Professional Documents
Culture Documents
But, sometimes the models have compatibility or library problems and doesnt work...
We can make a simple model of RAM or ROMs functionality and use that in our simulations.
Modeling RAM-Memories
Memory: process(Address,En,Data,rw) variable mem:array(Addressrange) of std_logic_vector(Datarange); begin if (En=1) then if (rw=1) then Data<=mem(Address); else Address mem(Address):=Data; end if; else Data Data<=(others=>Z); end if; end process;
process(clk) begin if (clk=1) and clkevent then FIFO(7 downto 0)<=FIFO(6 downto 0) & DataIn; end if; end process;
FIFOs are easy to model if they are made from Registers, but if they are implemented using a memory, a memory model is needed.
En r/w
Modeling ROM-Memories
Memory: process(Address,En,Data) variable mem:array(Addressrange) of std_logic_vector(Datarange); variable init: boolean:=false; begin if (not(init)) then initiate mem by reading data from file system init:=true; end if; if (En=1) then Address Data<=mem(Address); else Data<=(others=>Z); end if; Data end process;
En
std_logic_vector
WRITE puts data into a LINE buffer WRITELINE writes the data in the LINE buffer to file
Default Files
Example : ppm_file_handler
TYPE PPM_FILE_TYPE is FILE of CHARACTER; ...
PROCEDURE WriteData( VARIABLE data_out : IN INTEGER RANGE 0 to 255; FILE FileOut : PPM_FILE_TYPE ) IS VARIABLE char : CHARACTER; -- A temporary character BEGIN char := character'val(data_out); -- Write the character char to the output file WRITE(FileOut, char); END WriteData;
Example : ppm_file_handler
PROCEDURE ReadData( VARIABLE data_in : OUT INTEGER RANGE 0 to 255; FILE FileIn : Std.TextIO.Text; VARIABLE HashTable : HashTable_Type ) IS VARIABLE buf : STRING(1 DOWNTO 1); -- The read character i.e. one char of the string. VARIABLE len : INTEGER; -- A dummy var. for getting the READ syntax right VARIABLE char : CHARACTER; -- A temporary character VARIABLE int : INTEGER RANGE 0 TO 255; -- The integer value of a the read ASCII character BEGIN READ(FileIn, buf, len); char := buf(1); int := HashTable(char); data_in:=int; END ReadData; -- Read 1 character from the input file -- Extraction of curr. read character -- Make the char integer val. survive
Name Regions
The VHDL hierarchy is composed of Name Regions
Each component instantiation is expanded internally Access to signals higher up in hierarchy is allowed by using the full name of the signals Useful for doing power calculations & debugging
(Verilog allows probing signals downwards in hierarchy also, which is very useful when debugging since it is allows probing the lower level hierarchies from the test bench)
Generated Entity
LIBRARY ieee; USE ieee.std_logic_1164.all; LIBRARY lpm; USE lpm.lpm_components.all; ENTITY single_port_memory IS PORT ( address : IN STD_LOGIC_VECTOR (11 DOWNTO 0); we : IN STD_LOGIC := '1'; data : IN STD_LOGIC_VECTOR (7 DOWNTO 0); q : OUT STD_LOGIC_VECTOR (7 DOWNTO 0) ); END single_port_memory;
Testbench requirements
Testbench should model real case
Reactive testbenches
Complicated FSM behaviour
Traffic generators
Traffic distributions: Normal, Gaussian, etc. Traffic patterns: Local traffic, Global traffic, Bursty traffic, etc. Easiest way to read data from Matlab genererated file
Analysis
Analyse and determine if faults occur, preferably automatic Log results in file Use Matlab for analysis of results from traffic patterns
Reactive Testbenches
Use behavioural style for testbench modelling
May result in delta delay problems when testing FSMs Use after statement to introduce or force a small delay
Use ASSERT statements to specify and log abnormal behaviour and/or to abort simulation
(SystemVerilog allows also TIME dependent assertions, which is very useful when specifying FSM dependent operating conditions - used in Formal Verification)
Unconditional loops
i:=0; a:loop -- unconditional loop => loop forever exit a when i=97; i:=i+1; q<=sample(i) wait on clk until clk=1; end loop a;
Example : ppm_file_handler
LOOP READ(FileIn, buf, len);
...
Assert Statement
The ASSERT statement is used for displaying text when certain conditions are NOT met ASSERT statement classifies the text message in four categories
Note -- relays information about conditions to the user Warning -- alerts the user to conditions that are not expected, but not fatal Error -- relays conditions that will cause the model to work incorrectly Failure -- alerts the user to conditions that are catastrophic
CASE state IS WHEN 0 => IF int = 50 THEN state := 1; ELSE state := 0; END IF; WHEN 1 =>
...
WHEN 3 => IF int = 10 THEN EXIT; ELSIF int = 2 THEN state := 1; ELSE state := 0; END IF; WHEN OTHERS => null; END CASE; END LOOP;
Assert Syntax
Syntax of the ASSERT statement
ASSERT condition REPORT violation statement SEVERITY level; G
Assert Example
Assume type state is (good, reset); We specify the Normal operating conditions assert triggers on abnormal operating conditions
PROCEDURE display_state (current_state : IN state) IS BEGIN ASSERT (current_state = reset) REPORT Status of State: good SEVERITY NOTE; ASSERT (current_state /= reset) REPORT Status of State: reset SEVERITY WARNING; END display_state; G
The ASSERT statement will trigger when the condition is false The violation statement must be enclosed in quotes
ASSERT (NOT((j=1) AND (k=1))) REPORT Set and Reset are both 1 SEVERITY ERROR;
ASSERT statements may have some implementation defined action associated with the various SEVERITY levels
ASSERT false REPORT A has the value & print_number(a) SEVERITY NOTE;
Example
ENTITY multiplexor IS PORT (a, b: IN BIT; select: IN BIT; output: OUT BIT); BEGIN check: PROCESS(a, b) BEGIN ASSERT a/=b REPORT a equals b SEVERITY NOTE; END PROCESS; END multiplexor;
Multi-language simulations
Use the VHDL Foreign Language Interface and/or Use the Modelsim simulation engine to run mixmode/multi-language simulations
VHDL Verilog SystemC
The use of foreign code is mainly implementation dependent Foreign variables, signals, or entities are not possible Good for modeling memories, processors and parsing complicated file formats!!!
ATTRIBUTE FOREIGN OF name: construct IS "information/parameters";
FLI Example
ENTITY and2 IS PORT(a, b: IN BIT; c: OUT BIT); END and2; ARCHITECTURE c_model OF and2 IS ATTRIBUTE FOREIGN OF c_model: ARCHITECTURE IS "xxand2(A, B, C)"; BEGIN END c_model;
integer; int_array(3 downto 0); int_array(3 downto 0)) is subprogram my_proc not called";
Single-kernal simulation allows the top-level design unit to be either VHDL or Verilog.
As you traverse the design hierarchy, instantiations may freely switch back and forth between VHDL and Verilog.
-b -s -v <module_name>
module top(i1, o1, o2, io1); parameter width = 8; parameter delay = 4.5; parameter filename = "file.in"; input i1; output [7:0] o1; output [4:7] o2; inout [width-1:0] io1; endmodule After compiling (with vlog) , vgencomp is invoked on the compiled module: vgencomp top
Component/Technology Libraries
Used to verify post-synthesis behaviour May require usage of
Configuration files Global signals
Configuration files
A configuration allows you to replace a component inside the testbench without rewriting the code
Example
CONFIGURATION new_components OF test IS for test_exor for U1:exor use entity work.exor(structural) for structural for all:inverter use lsi10k.not_gate(behave) end for; end for; end for; end for; END new_components;
Appendix
a b
c d e f g
q and
C
i
q <= a and b;
C
o
2) Use a script to modify the VHDL code a) Add a power calculation for each input and output in the description of the gate b) repeat step 2a) for every gate in the library 3) Recompile and store the VHDL code in a new library
and
Ci
q
Co
process(a) begin work.power_pack.switched_cap<=transport Ci_and; work.power_pack.switched_cap<=transport 0.0 after 1 ns; end process;