VHDL Coding Rules
VHDL Coding Rules
Rule: A VHDL file and the entity it contains have the same name.
VHDL Coding Rules, page 3
File header
--------------------------------------------------------------------
-- Project : project or course name
-- Author : Teemu Teekkari
-- Date : 01/09/03 14:05:01
-- File : example.vhd
-- Design : Course exercise 1
--------------------------------------------------------------------
-- Description : Example header
--------------------------------------------------------------------
-- $Log$
--------------------------------------------------------------------
• There is a space on both sides of “=>”, “<=“, “:=”, “>”, “<“, “=“,
“/=“, “+”, “-”, “&”, “AND”, “OR”, “XOR” etc:
• You may omit the space from the sides of “*” and “/”:
ENTITY pokerhand IS
PORT (
rst_n : IN STD_LOGIC;
clk : IN STD_LOGIC;
card_0_in : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
card_1_in : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
card_2_in : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
card_3_in : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
card_4_in : IN STD_LOGIC_VECTOR(5 DOWNTO 0);
hand_out : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
END pokerhand;
-- control signals
SIGNAL select_0 : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL select_1 : STD_LOGIC_VECTOR(31 DOWNTO 0);
SIGNAL state : STD_LOGIC_VECTOR(31 DOWNTO 0);
i_pokerhand : pokerhand
PORT MAP (
rst_n => rst_n,
clk => clk,
card_0_in => card_0_i,
card_1_in => card_1_i,
card_2_in => card_2_i,
card_3_in => card_3_i,
card_4_in => card_4_i,
hand_out => hand_i
);
----------------------------------------------------------
-- Parity bit is calculated for the DATA_INPUT signal.
----------------------------------------------------------
parity_calculation : PROCESS (rst_n, clk)
BEGIN
IF (rst_n = '0') THEN
parity <= '0';
ELSIF (clk‘EVENT and clk = '1') THEN
parity <= data_input(3) XOR data_input(2)
XOR data_input(1) XOR data_input(0);
END IF;
END PROCESS parity_calculation;
BEHAVIORAL Implies physical logic, does not compile with RTL tools
RTL Implies physical logic, compiles with RTL tools
STRUCTURAL Implies physical connections, but not any logic
GATE Gate level netlist
SIMULATION Simulation model
TESTBENCH Test bench
* Note: Internal signal is a signal which is later assigned to another signal, for example:
data_out <= data_out_i;
• Sometimes it is useful to indicate bits that have been left off with
the number of the LSB
– For example an address bus with the two LSBs left off:
SIGNAL address : STD_LOGIC_VECTOR(datawidth_g-1 DOWNTO 2);
result <= a + b
WHEN (addsub = '0')
ELSE a - b;
– Example:
state1
output=“01”
sel=‘1’ sel=‘1’
state3 state2
sel=‘0’ sel=‘0’
output=“11” output=“10”
sel=‘1’
probe_v := '0';
FOR i IN 0 TO 31 LOOP
probe_v := probe_v XOR data_in(i);
END LOOP;
probe_out <= probe_v;
Rule: Use variable only when there is real benefit from it.
VHDL Coding Rules, page 38
Safe coding: Miscellaneous
• Avoid subtypes.
• Use only STD_LOGIC signal states '0', '1' and 'Z'
– Never refer to state 'X' in VHDL code.
• Avoid instantiating library primitives
– If you do, keep them in a separate block.
– Consider Synopsys GTECH library components.
• Do not embed synthesis script in the VHDL code
– Difficult to maintain both the script and the code.
• All logic should be contained within the leaf blocks of the design
(RTL architecture).
• Every block above a leaf cell up to the top level should contain
only component instantiations and wiring (STRUCTURAL
architecture).
• All timing exceptions should be contained within a block.
• Constant values should not be routed through hierarchy.
• Three state signals are not allowed inside the chip.
* Note: Snake path is a combinational path going through many blocks of the design. Time
budgeting of snake paths is difficult.