|
| 1 | +<h1>VHDL</h1> |
| 2 | +<p>To use this language, use the class "language-vhdl".</p> |
| 3 | + |
| 4 | +<h2>Comments</h2> |
| 5 | +<pre><code>-- I am a comment |
| 6 | +I am not</code></pre> |
| 7 | + |
| 8 | +<h2>Literals</h2> |
| 9 | +<pre><code>constant FREEZE : integer := 32; |
| 10 | +constant TEMP : real := 32.0; |
| 11 | +A_INT <= 16#FF#; |
| 12 | +B_INT <= 2#1010_1010#; |
| 13 | +MONEY := 1_000_000.0; |
| 14 | +FACTOR := 2.2E-6; |
| 15 | +constant DEL1 :time := 10 ns; |
| 16 | +constant DEL2 :time := 2.27 us; |
| 17 | +type MY_LOGIC is ('X','0','1','Z'); |
| 18 | +type T_STATE is (IDLE, READ, END_CYC); |
| 19 | +signal CLK : MY_LOGIC := '0'; |
| 20 | +signal STATE : T_STATE := IDLE; |
| 21 | +constant FLAG :bit_vector(0 to 7) := "11111111"; |
| 22 | +constant MSG : string := "Hello"; |
| 23 | +BIT_8_BUS <= B"1111_1111"; |
| 24 | +BIT_9_BUS <= O"353"; |
| 25 | +BIT_16_BUS <= X"AA55"; |
| 26 | +constant TWO_LINE_MSG : string := "Hello" & CR & "World";</code></pre> |
| 27 | + |
| 28 | +<h2>Full example</h2> |
| 29 | +<pre><code>-- example code from: http://www.csee.umbc.edu/portal/help/VHDL/samples/samples.html |
| 30 | +library IEEE; |
| 31 | +use IEEE.std_logic_1164.all; |
| 32 | + |
| 33 | +entity fadd is -- full adder stage, interface |
| 34 | + port(a : in std_logic; |
| 35 | + b : in std_logic; |
| 36 | + cin : in std_logic; |
| 37 | + s : out std_logic; |
| 38 | + cout : out std_logic); |
| 39 | +end entity fadd; |
| 40 | + |
| 41 | +architecture circuits of fadd is -- full adder stage, body |
| 42 | +begin -- circuits of fadd |
| 43 | + s <= a xor b xor cin after 1 ns; |
| 44 | + cout <= (a and b) or (a and cin) or (b and cin) after 1 ns; |
| 45 | +end architecture circuits; -- of fadd |
| 46 | + |
| 47 | +library IEEE; |
| 48 | +use IEEE.std_logic_1164.all; |
| 49 | +entity add32 is -- simple 32 bit ripple carry adder |
| 50 | + port(a : in std_logic_vector(31 downto 0); |
| 51 | + b : in std_logic_vector(31 downto 0); |
| 52 | + cin : in std_logic; |
| 53 | + sum : out std_logic_vector(31 downto 0); |
| 54 | + cout : out std_logic); |
| 55 | +end entity add32; |
| 56 | + |
| 57 | +architecture circuits of add32 is |
| 58 | + signal c : std_logic_vector(0 to 30); -- internal carry signals |
| 59 | +begin -- circuits of add32 |
| 60 | + a0: entity WORK.fadd port map(a(0), b(0), cin, sum(0), c(0)); |
| 61 | + stage: for I in 1 to 30 generate |
| 62 | + as: entity WORK.fadd port map(a(I), b(I), c(I-1) , sum(I), c(I)); |
| 63 | + end generate stage; |
| 64 | + a31: entity WORK.fadd port map(a(31), b(31), c(30) , sum(31), cout); |
| 65 | +end architecture circuits; -- of add32 |
| 66 | + |
| 67 | +use STD.textio.all; |
| 68 | +library IEEE; |
| 69 | +use IEEE.std_logic_1164.all; |
| 70 | +use IEEE.std_logic_textio.all; |
| 71 | + |
| 72 | +entity signal_trace is |
| 73 | +end signal_trace; |
| 74 | + |
| 75 | +architecture circuits of signal_trace is |
| 76 | + signal a: std_logic_vector(31 downto 0) := x"00000000"; |
| 77 | + signal b: std_logic_vector(31 downto 0) := x"FFFFFFFF"; |
| 78 | + signal cin: std_logic := '1'; |
| 79 | + signal cout: std_logic; |
| 80 | + signal sum: std_logic_vector(31 downto 0); |
| 81 | +begin -- circuits of signal_trace |
| 82 | + adder: entity WORK.add32 port map(a, b, cin, sum, cout); -- parallel circuit |
| 83 | + |
| 84 | + prtsum: process (sum) |
| 85 | + variable my_line : LINE; |
| 86 | + alias swrite is write [line, string, side, width] ; |
| 87 | + begin |
| 88 | + swrite(my_line, "sum="); |
| 89 | + write(my_line, sum); |
| 90 | + swrite(my_line, ", at="); |
| 91 | + write(my_line, now); |
| 92 | + writeline(output, my_line); |
| 93 | + end process prtsum; |
| 94 | + |
| 95 | +end architecture circuits; -- of signal_trace</code></pre> |
0 commit comments