All right strictly reserved. Reproduction or issue to third parties, in any form whatsoever, is not permitted without written authority from the proprietors.

VHDL Style Guide

Project Name/Projektname

Page/Seite


29 of/von 29

Prepared / Erstellt

Subject Responsible / Verantwortlich

Date/Datum

Rev.

File/Datei OpenOffice.org Writer

Mario Fohler

Peter Thorwartl

2008-07-31

1.0

so_vhdl_guide_20080728.odt







VHDL STYLE GUIDE













Table of Contents

1. VHDL Terms 4

1.1 Objects 4

1.2 Classes 4

1.2.1 Constants 4

1.2.2 Signals 4

1.2.3 Variable 5

1.2.4 Files 5

1.3 Types and Subtypes 6

1.4 Units 7

1.4.1 Libraries 7

1.4.2 Entity 7

1.4.3 Architecture 8

1.4.4 Package 8

1.4.5 Package Body 8

1.4.6 Configuration 9

2. Elements of Entity/Architecture 10

2.1 Generics 10

2.2 Ports 10

2.3 Process 10

2.4 If/Then/Else 11

2.5 Case 11

2.6 Loops 12

2.7 Function and Procedures 12

2.8 Components and Component Instantation 12

2.9 Simulation and test benches 13

2.10 Types 14

3. VHDL Style Guide 15

4. Header 17

5. General Coding Rules for Digital Designs 18

5.1 Reset 18

5.2 Clocks 18

5.3 Buses 20

5.4 Finite State Machine FSM 20

5.5 Memories 22

6. Project Structure 23

6.1 Library 23

6.2 Project Directory 23

6.3 One Project Tree 24

6.4 UPLD User Programmable Logic Devices 24

6.5 File Name 25

7. SVN 26

7.1 Rules 26

8. Scripting 27

8.1 Identifier ID 27


1. VHDL Terms

1.1 Objects

1.2 Classes

1.2.1 Constants

...

architecture rtl of sine is


constant sin_ampl_c : vector_t_arr := init_sin_f(depth_g, width_g); -- returns sine amplitude value


signal ampl_cnt_s : integer range 0 to 255 := 0; -- amplitude counter

signal sine_s : std_logic_vector(width_g-1 downto 0) := (others=>'0'); -- sine


begin

...

1.2.2 Signals


1.2.3 Variable

...

write_p : process -- write 64 following sin-amplitude values in sin.txt at the work directory (only simulate)

file out_sin_f : text open write_mode is "sin.txt"; -- create file in write mode in work directory

variable out_sin_line_v : line; -- line variable

begin

wait until rising_edge(clk_in_s);

if wr_end_s = '0' and freq_trig_s = '1' then

if wr_count_s = 64 then -- write 64 amplitude values

wr_end_s <= '1'; -- write end/end of file

else

write(out_sin_line_v, dac_amplvalue_s); -- write dac_amplvalue_s value in out_sin_line_v

writeline(out_sin_f, out_sin_line_v); -- write out_sin_line_v in one line of out_sin_f

wr_count_s <= wr_count_s+1; -- increment write counter

end if;

end if;

end process;

...


1.2.4 Files

1.3 Types and Subtypes

package modulator_pkg is

type vector_t_arr is array (natural range <>) of integer;

function init_sin_f

(

constant depth_c : in integer;

constant width_c : in integer

)

return vector_t_arr;

end;

package body modulator_pkg is


function init_sin_f

(

depth_c : in integer;

width_c : in integer

)

return vector_t_arr is


variable init_arr_v : vector_t_arr(0 to (2 ** depth_c));


begin


for i in 0 to ((2 ** depth_c) / 2) loop -- calculate positive amplitude values

init_arr_v(i) := integer(round(sin((math_2_pi / real(2 ** depth_c))*

real(i)) * real(2 ** (width_c - 1)))) + integer(2 ** (width_c - 1) - 1);

end loop;


for i in ((2 ** depth_c) / 2 + 1) to (2 ** depth_c) loop -- calculate negativ amplitude values

init_arr_v(i) := integer(round(sin((math_2_pi / real(2 ** depth_c))*

real(i)) * real(2 ** (width_c - 1)))) - integer(2 ** (width_c - 1));

end loop;


return init_arr_v;


end;


end;



1.4 Units

1.4.1 Libraries

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_textio.all;

use ieee.std_logic_unsigned.all;

library modelsim_lib;

use modelsim_lib.util.all;

library std;

use std.textio.all;

1.4.2 Entity

entity dac_ltc2624 is

generic(

depth_g : integer range 1 to 99 := 8; -- sine signal 8bit quantized

width_g : integer range 1 to 99 := 12 -- 12 bit sine amplitude value

);

port(

btn_reset : in std_logic; -- reset button

clk_in : in std_logic; -- 50MHz clock

clkdv_in : in std_logic; -- 25MHz clock

dac_clk : out std_logic; -- dac clock

dac_cs_n : out std_logic; -- dac enable

dac_data : out std_logic; -- dac data

dac_reset_n : out std_logic; -- dac reset

freq_trig : in std_logic -- frequency for dac data packages

sine : in std_logic_vector(width_g-1 downto 0) -- frequented sine amplitude

);

end;

1.4.3 Architecture

architecture rtl of modulator is

...

begin

...

end;

1.4.4 Package

1.4.5 Package Body

1.4.6 Configuration

2. Elements of Entity/Architecture


2.1 Generics

2.2 Ports

2.3 Process


2.4 If/Then/Else

2.5 Case


freq_ce_p : process -- create and select frequency


begin


wait until rising_edge(clk_in);

freq_cnt_s <= freq_cnt_s + 1; -- increment

freq_trig <= '0';

case sw0_freq_sel is -- select sine frequency


when '0' => -- frequency for sw0_freq_sel = '0'

if (sw0_freq_sel_jmp = '1') then

freq_cnt_s <= (others => '0'); -- reset

sw0_freq_sel_jmp <= '0';

end if;

if (freq_cnt_s = freqlow_g - 1) then

freq_trig <= '1';

freq_cnt_s <= (others => '0'); -- reset

end if;


when '1' => -- frequency for sw0_freq_sel = '1'

if (sw0_freq_sel_jmp = '0') then

freq_cnt_s <= (others => '0'); -- reset

sw0_freq_sel_jmp <= '1';

end if;

if (freq_cnt_s = freqhigh_g - 1 ) then

freq_trig <= '1';

freq_cnt_s <= (others => '0'); -- reset

end if;


when others => null;


end case;


end process;


2.6 Loops


2.7 Function and Procedures


2.8 Components and Component Instantation

dut_c: entity work.counter(rtl)

port map(

);


2.9 Simulation and test benches

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;


entity counter_tb is


generic(

clkcnt_value_g : std_logic_vector := b"100" -- threshold value for counter

);


end;


architecture tb of counter_tb is


constant per_c : time := 20 ns; -- clock period


signal clk_in_s : std_logic := '1'; -- clk (50MHz)

signal clk_out_s : std_logic := '0'; -- divided clk

signal clkcnt_out_s : std_logic_vector (clkcnt_value_g'length - 1 downto 0) := (others => '0'); -- clk counter

signal cnt_en_s : std_logic := '1'; -- clk counter enable


begin


counter : entity work.counter(rtl) -- fetch generic and ports of counter_rtl.vhd


generic map(

clkcnt_value_g => clkcnt_value_g

)


port map (

clk_in => clk_in_s,

clk_out => clk_out_s,

clkcnt_out => clkcnt_out_s,

cnt_en => cnt_en_s

);


clk_in_s <= not (clk_in_s) after per_c/2; -- generate 50MHz clock

cnt_en_s <= '0' after 300 ns; -- set clk counter enable to zero after 300us


end;

2.10 Types

3. VHDL Style Guide


Denotation:

Positioning:


Comments:

4. Header

--------------------------------------------------------------------------------

-- File : modulator_rtl.vhd

-- Project : modulator

-- Creation : 15.07.2008

-- Limitations : none

-- Errors : none known

-- Simulator : Modelsim SE 6.2a

-- Synthesizer : ISE 10.1

-- Platform : Windows XP

-- Targets : Simulation, Synthese, Implementation

---------------------------------------

-- Naming conv. : so_vhdl_guide.doc

---------------------------------------

-- Authors : Peter Thorwartl (thor)

-- Organization : so-logic

-- Email : thor@so-logic.co.at

-- Address : Lustkandlg. 52/22, A-1090 Vienna Austria/Europe/Earth

--------------------------------------------------------------------------------

-- Copyright Notice

-- Copying of this document and giving it to others and the

-- communication of the contents thereof is forbidden without authority.

-- Offenders are liable to payment of damages. All rights are reserved in

-- event of the grant or patent of the utility model or design.

--------------------------------------------------------------------------------

-- Function description

-- frequency modulator with output for dac

--------------------------------------------------------------------------------

-- $HeadURL:$

-- $Date:$

-- $Author:$

-- $Revision:$

--------------------------------------------------------------------------------

5. General Coding Rules for Digital Designs

5.1 Reset

5.2 Clocks





entity modulator is

generic(

...

);

port(

clk_in : in std_logic; -- clk 50 MHz

...

);

end;


architecture rtl of modulator is

...

begin


dcm2sim_activation: if (sim_g) generate -- dcm activation

...

end generate;


dcm2sim_deactivation: if not(sim_g) generate -- dcm deactivation

clkdv_p: process

begin

wait until rising_edge(clk_in);

clk_in_s <= not(clk_in_s); -- clk_in divided by 2

end process;

clkdv_s <= clk_in_s;

end generate;


counterled : entity work.counter(rtl) -- generate ~0,5Hz frequency for led

generic map(

clkcnt_value_g => x"2faf07f" -- clk counter threshold value

)

port map (

clk_in => clk_in,

...

);


freq_ce : entity work.freq_ce(rtl) -- generate frequency trigger

generic map(

...

)

port map(

clk_in => clk_in,

...

);


counterampl : entity work.counter(rtl) -- generate amplitude values

generic map(

clkcnt_value_g => x"00000ff" -- clk counter threshold value

)

port map (

clk_in => clk_in,

...

);


sine : entity work.sine(rtl) –- generates digital sine

generic map(

...

)

port map(

...

clk_in => clk_in,

...

);


dac_ltc2624: entity work.dac_ltc2624(rtl) -- fetch freq-trigger and ampl-values and generate dac output signals

generic map(

...

)

....port map(

...

clk_in => clk_in,

...

);


...


end;



entity counter is

generic(

...

);


port(

...

cnt_en : in std_logic -- clk counter enable

);

end;


architecture rtl of counter is


...


begin


counter_p: process

begin


wait until rising_edge(clk_in);

if (cnt_en = '1') then

...

else

...

end if;


end process;


...


end;


  1. Not assigning to a signal in every branch of an if-then-else statement or case statement. Remember that latches will be inferred for this condition in a combinatorial process

  2. Not defining all possible states or branches of an if-then-else or case statement.

5.3 Buses

5.4 Finite State Machine FSM


entity statemachine is

port(

clk_in : in std_logic; -- 50MHz clock

dac_clk_low : out std_logic; -- set dac clk to zero

shreg_en : out std_logic; -- shiftregister enable

statem_en : in std_logic -- statemachine enable

);

end;


architecture rtl of statemachine is


type state_type_t_enum is (shreg_end,shreg_start,clk_pause); -- three states of state machine


signal dac_clk_low_s : std_logic := '0'; -- set dac clk low

signal shreg_en_s : std_logic := '0'; -- set shiftreg enable low

signal statem_loop_s : integer range 0 to 49 := 0; -- state loop

signal statem_s : state_type_t_enum; -- enumerated state machine


begin


statem_statereg_p : process -- shift states


begin

wait until rising_edge(clk_in);

if ((statem_en = '1') or (dac_clk_low_s = '1')) then


case statem_s is


when shreg_end =>

statem_s <= shreg_start;


when shreg_start =>

if (statem_loop_s = 48) then

statem_s <= clk_pause;

statem_loop_s <= 0;

else

statem_loop_s <= statem_loop_s + 1;

end if;


when clk_pause =>

if (statem_loop_s = 1) then

statem_s <= shreg_end;

statem_loop_s <= 0;

else

statem_loop_s <= statem_loop_s + 1;

end if;


when others => null;


end case;


end if;


end process;


statem_stateoutput_p : process(statem_s) -- define output to state


begin


case statem_s is -- generate shiftregister enable and clk output low signal


when shreg_start =>

shreg_en_s <= '1'; -- start shift register

dac_clk_low_s <= '0';


when clk_pause =>

shreg_en_s <= '0'; -- end shift register

dac_clk_low_s <= '1'; -- set dac clk low


when shreg_end =>

shreg_en_s <= '0';

dac_clk_low_s <= '0';


when others => null;


end case;


end process;


shreg_en <= shreg_en_s;

dac_clk_low <= dac_clk_low_s;


end;



5.5 Memories


-- 8x32 lut-matrix

type lut8x32_t_arr is array (0 to 31) of std_logic_vector(7 downto 0);


-- 8bit amplitude values of 32bit quantized sin

constant wave_c : lut8x32_t_arr := (

0 => X"8C", 1 => X"A5", 2 => X"BC", 3 => X"D0",

4 => X"E2", 5 => X"F0", 6 => X"FA", 7 => X"FE",

8 => X"FE", 9 => X"FA", 10 => X"F0", 11 => X"E2",

12 => X"D0", 13 => X"BC", 14 => X"A5", 15 => X"8C",

16 => X"73", 17 => X"5A", 18 => X"43", 19 => X"2F",

20 => X"1D", 21 => X"0F", 22 => X"05", 23 => X"01",

24 => X"01", 25 => X"05", 26 => X"0F", 27 => X"1D",

28 => X"2F", 29 => X"43", 30 => X"5A", 31 => X"73"

);

6. Project Structure

6.1 Library

Directory Structure Example

/lib

/vhdl

/msim61f_ise91sp3

/msim62a_ise10sp1

/verilog

/msim62a_ise91sp3

/msim62a_ise10sp1

/pads

/templates

/oo

6.2 Project Directory

Project Directory Example

project/

/<company_name1>

/<project_name1>

/<project_name2>

/<company_name2>

/<project_name3>

/<project_name4>

6.3 One Project Tree

<project-name>/

info/

/xilinx

/marvell

pcb/

soft/

tools/

upld/


6.4 UPLD User Programmable Logic Devices

/upld

/src

/result

/release


src\.

doc\.

figure\.

*.png

*.vsd

html\.

pdf\.

c\.

*.c

*.cpp

*.h

java\*.java

vhdl\*.vhd

verilog\*.v

<toolcompany>\*<toolversion_confname>.*

cmd\

*.make

*.bat

*.sh

6.5 File Name


7. SVN

7.1 Rules

8. Scripting


8.1 Identifier ID

Examples for using of the 32 bit identification number:


# VERSION string digit 12345678


# 1. digit year

# 2. and 3. digit week

# 4. day of week 1 Monday 7 .. Sunday


# 5. digit PROJECT

# 0 .. so_hs

ifeq ($(PROJECT), so_hs)

P=0

endif


ifeq ($(PROJECT), infineon_hs)

P=1

endif


# 6. digit DESIGN


# 0 .. iotest check pinout, GTP and DCM use for all use cases

ifeq ($(DESIGN), iotest)

S= 0

endif


# 1 .. pcbtest with CPU

ifeq ($(DESIGN), pcbtest)

S = 1

endif


# 2 .. ibert serial io toolkit

ifeq ($(DESIGN), ibert)

S= 2

endif


# 3 .. HSPG

ifeq ($(DESIGN), hspg)

S = 3

endif


# 4 .. HSLA

ifeq ($(DESIGN), hsla)

S = 4

endif


# 6 .. HSPL_L

ifeq ($(DESIGN), hspl_l)

S = 6

endif


# 7 .. HSPL_TV

ifeq ($(DESIGN), hspl_tv)

S = 7

endif


# 8 .. HSPL_TJ

ifeq ($(DESIGN), hspl_tj)

S = 8

endif



# 7. digit BOARD

# 0 .. ML505 Demoboard Xilinx

ifeq ($(BOARD), ml505)

B=0

endif


# 1 .. first version of print FPGA board

ifeq ($(BOARD), hsfb1)

B=1

endif



# 8. digit PART

ifeq ($(PART), lx50t)

DEVICE=xc5vlx50t-ff1136-1

T=0

endif

ifeq ($(PART), lx110t)

DEVICE=xc5lvx110t-ff1136-1

T=1

endif

ifeq ($(PART), fx70t)

DEVICE=xc5vfx70t-ff1136-1

T=2

endif

ifeq ($(PART), fx100t)

DEVICE=xc5vfx100t-ff1136-1

T=3

endif