Specman GUTS
Specman GUTS
(Get Up To Speed)
1
Table of Contents
Topic Page
• Basic e code definition 4
• Struct example 12
• Generation / constraints 14
• Constraints example 20
• Simulation interface 22
• Methods 24
• signal assignments 27
• Operations 29
• Control Statements 32
• Method example 47
• Gen on-the-fly 49
• Packing 52
2
Intro to Specman Code
struct my_struct_s {
field; -- describe field to be passed in to simulation
keep …; -- if any constraints on legal value of field
event clk is rise('path/clk')@sim;
method() @clk is {
for or while loop {
gen field; -- only if generation-on-the-fly
'path/input' = field; -- or = variable
wait [1]; -- wait of at least one period needed
};
stop_run();
};
run() is also {start method() };
};
extend sys { inst_name : my_struct_s };
5
Fields Syntax
• Syntax
– field_name : type;
• type will determine width of field and how certain functions (print,
for example) work with the value
6
Types
• Types
– integer
• int - 32-bit signed integer
• uint - 32-bit unsigned integer
• int (bits: n) - n-bit signed integer
• uint (bits: n) - n-bit unsigned integer
– integer subtypes
• byte - 8-bit unsigned integer, same as uint (bits:8)
• bit - 1-bit unsigned value, same as uint(bits:1)
– Boolean
• bool - 1 bit Boolean value (TRUE or FALSE)
7
Types
• Enumerated types
– defined with type statement
type color_t : [RED, GREEN, BLUE];
8
Types
• structs
– any user defined struct is also a valid type for a field
struct a_s {
x : int;
};
struct b_s {
y : a_s; -- the type is struct "a_s"
};
9
Lists
10
Field Examples
11
Example Struct - Packet
12
Packet Struct Solution
<‘
type packet_kind_t : [GOOD, BAD];
struct packet_s {
kind : packet_kind_t;
addr : uint (bits : 2);
len : uint (bits : 6);
data [len] : list of byte;
};
struct my_stimulus_s {
packets [10] : list of packet_s;
};
‘>
13
Generation with basic structs
14
Constraints (keep) Overview
15
Keep Boolean expression
• in range
– keep x in [5..10]; -- x is an int
keep y in [1,3,5..8]; -- y is a uint
keep z in [SMALL..MEDIUM]; -- z is enum
– keep k not in [100..199]; -- k will not be 1xx
16
Keep implication
17
Keep for each in list
18
Keep - Weighted Distribution
19
Constraints Example
20
Constraints solution
<‘
extend packet_s {
keep len < 20;
keep soft kind == select {
90: GOOD;
10: BAD;
};
keep soft addr == select {
20: 0;
60: 1;
20: 2;
};
};
‘>
21
Simulator interface
22
Event “clock” definition
23
Methods Overview
24
Specman Variables
25
Simulator Signals
26
Assignment
NOTE: if item is a list or a struct, assignment will not create a copy of the list or
struct; instead another pointer to the list or struct is created, meaning that a
change to the underlying list or struct based on either pointer will be seen
when the list or struct is viewed by either pointer. If you want a copy, see
copy method described later.
27
Assignment (cont.)
• RHS
• another item
• any number of operators applied to fields or variables
• a value returned by a user-defined or pre-defined method
28
Operations
29
Operations - example
• x = 2, y = 1, k = TRUE
• ((x + y) * 2) - 5
x << 3
x|y
(x == 3) or ((y ==1) and k)
30
List Elements and Bit Slicing
• List elements
– Individual elements from a list can be specified by [index]
• my_list[5] -- 6th element in my_list (0 is 1st)
– Sublist can be specified by [low..high]
• my_list[2..5] -- 3rd through 6th element
• Bit Slicing
– A bit from an integer can be specified by [bit_pos:bit_pos]
• my_int[7:7] -- MSB of an 8-bit integer my_int
– A range of bits from an integer can be specified as [high:low]
• my_int[7:4] -- upper 4 bits of my_int
31
Control Statements - Loops, Conditional
32
For loops
33
While loops
34
if..else conditional
35
Apply “packets” to simulator
36
Simulator Interface Solution
• struct stimulus_s {
packets [10] : list of packet_s;
event clk is fall('~/top/accept')@sim;
drive() @clk is {
for each (p) in packets do {
'~/top/address' = p.addr;
'~/top/length' = p.len;
wait [1];
for each (d) in p.data do {
'~/top/databyte' = d;
wait [1];
};
};
stop_run();
};
run() is also {start drive()};
};
extend sys { my_stimulus : stimulus_s };
37
Alternative: Using Verilog Tasks
38
Solution Using Verilog Task
39
Varying the Template
40
The Wait Action
• wait
• valid only in time-consuming method (method definition defines
default event)
• wait for some number of cycles of the default event
wait [5]; -- waits 5 cycles of default event
• wait for another event
wait until rise('~/top/rst'); -- wait for inactive
wait until @interrupt;
• wait for a condition to become true
wait until true('~/top/flag' == 1);
41
Starting Methods
• NOTE: there is always an implied wait for the default event before
the body of a TCM executes
42
Starting Methods in the First Place
43
Extending Methods
44
Extending Structs
45
Make Your Own Methods
46
Method example - packet
47
Parity solution
extend sys {
parity_calc (data : list of byte) : byte is {
for each (item) in data do {
result = result ^ item;
};
};
};
extend packet_s {
parity : byte;
keep kind == good => parity == parity_calc(data);
};
48
Generation On-The-Fly
49
Generation On-The-Fly Example
50
Interface Solution Using Gen On-The-Fly
• struct stimulus3_s {
event clk is fall('~/top/accept')@sim;
drive() @clk is {
var next_pkt : packet_s;
for i from 1 to 15 do {
gen next_pkt keeping {.addr == '~/top/two_bits'};
'~/top/address' = next_pkt.addr;
'~/top/length' = next_pkt.len;
wait [1];
for each (d) in next_pkt.data do {
'~/top/databyte' = d;
wait [1] * cycle;
};
};
stop_run();
};
run() is also {start apply()};
};
extend sys { my_stimulus : stimulus3_s };
51
Concatenating with pack
52
Packing Styles
• packing.high
• the first field goes in the most significant location of the result, the
second field goes in the next most significant location, and so on until
the last field goes in the least significant location
• use for concatenating items to an integer
• packing.low
• the first field goes in the least significant location of the result, the
second field goes in the next least significant location, and so on until
the last field goes in the most significant location
• make your own
• your CE can help you create a new style in a setup file
53
Pack Examples
54
Interface Solution Using Pack
• struct stimulus4_s {
packets [10] : list of packet_s;
event clk is fall('~/top/accept')@sim;
drive() @clk is {
var bytes : list of byte;
for each (p) in packets do {
bytes = pack(packing.low, p.len, p.addr, p.data);
for each (b) in bytes do {
'~/top/databyte' = b;
wait [1];
};
};
stop_run();
};
run() is also {start apply()};
};
extend sys { my_stimulus : stimulus4_s };
55
Pre-defined List Methods
56
More List Methods
57
Printing actions
58
Printing examples
• print
– print index using dec;
print data using hex;
• out
– out("Index is" , index, "and data is ", data[index]);
• outf
– outf("Index is %d and data is %x\n", index,data[index]);
59
Checking action
60