Naming conventions, prefixes, and best practices for readable and maintainable VHDL code.
Why Coding Rules?
In a real VHDL project, a file may be read by dozens of people over years. Coding rules ensure:
Readability: understand a signal's role at first glance
Maintainability: quickly locate a bug
Consistency: same style throughout the team
Code review: facilitates error detection
Naming Prefixes
Ports (external interface)
Prefix
VHDL Mode
Meaning
Example
i_
in
Input port
i_clk, i_data, i_rst
o_
out
Output port
o_valid, o_data
io_
inout
Bidirectional port
io_bus, io_sda
Internal Signals
Prefix
Meaning
Example
w_
Unregistered signal — wire, combinational
w_sum, w_mux_out
r_
Registered signal — flip-flop, D latch
r_counter, r_data
Other Identifiers
Prefix
Meaning
Example
c_
Constant
c_CLK_FREQ, c_MAX_COUNT
g_
Generic (entity parameter)
g_WIDTH, g_DEPTH
t_
User-defined type
t_state, t_data_array
v_
Variable (inside a process)
v_temp, v_index
P_
Process (label)
P_WRITE_FSM, P_READ_DATA
f_
Function
f_log2, f_parity
Complete Examples
entity uart_tx is generic ( g_CLK_FREQ : integer := 100_000_000; -- g_ for generic g_BAUD_RATE : integer := 115_200 ); port ( i_clk : in std_logic; -- i_ input i_rst : in std_logic; -- i_ input i_data : in std_logic_vector(7 downto 0); i_valid : in std_logic; o_tx : out std_logic; -- o_ output o_ready : out std_logic );end entity uart_tx;architecture rtl of uart_tx is constant c_BIT_PERIOD : integer := g_CLK_FREQ / g_BAUD_RATE; -- c_ constant type t_state is (IDLE, START, DATA, STOP); -- t_ type signal r_state : t_state; -- r_ registered signal r_counter : integer range 0 to c_BIT_PERIOD; -- r_ registered signal r_shift : std_logic_vector(7 downto 0); -- r_ registered signal w_tx_bit : std_logic; -- w_ combinational -- f_ for a function function f_parity(v_data : std_logic_vector) return std_logic is variable v_p : std_logic := '0'; begin for i in v_data'range loop v_p := v_p xor v_data(i); end loop; return v_p; end function f_parity;begin P_TX_FSM : process (i_clk) -- P_ for processes begin -- ... end process P_TX_FSM;end architecture rtl;