VARIABLES
Variable Declarations
Variables can be declared as singular or as arrays. Arrays of variables provide a means of producing look up tables and, more importantly, support for buses.
Declarations of variables have the form:
TYPE name[[[lower..upper]]] [[=expression]] [[,etc]]
TYPE name[[[width]]] [[=expression]] [[,etc]]
A declaration takes the form of the name of the variable type you wish to declare variables of, followed by a comma separated list of variable names. If the variable represents an array, then the name must be followed by either the lower and upper inclusive bounds of the array separated by two periods or the width of the array, enclosed in square brackets. The width or lower and upper bounds of the array must be integer constants, since expressions are not allowed. If you specify an array by its width, then a lower bound of zero and an upper bound of width-1 is assumed. Both bounds must lie in the range 0 to 255, so an array can hold at most 256 elements. Variable initialisation is achieved by following the variable name or closing square bracket of an array declaration by an equals sign and then the initialisation expression.
For example,
PIN data[2..5]=13, output
INT i
INT j=0,k[2]
TIME t1,t2=10n
declares two variables of type PIN (data and output), three variables of type INT (i, j, and k) and two variables of type TIME (t1 and t2). The data and k variables have both been declared as arrays; data has four elements: data[2], data[3], data[4] and data[5], whilst k has two elements: k[0] and k[1]. Of the variables declared, data, j, and t2 have been initialised with the values 13, 0 and 1E-8 respectively.
Prefixing the name of a PIN with an exclamation mark declares the pin as inverted, so that the state the script assigns is applied to the net the other way up:
PIN !NRESET
Variables declared with an initialisation expression are only assigned the result of the expression once, during the boot invocation of the script. After the boot invocation, variables maintain their values from the previous invocations of the EasyHDL script and are not assigned the results of their initialisation expressions prior to each invocation.
All declarations must appear before the first executable statement of the script. Within that block the order in which the declarations are written does not matter, but a declaration cannot be made part way through the code.
BOOL and PIN Types for more information on declaring arrays of PIN variables.
Assigning To Variables for an explanation of assigning expressions to variables.
Declaration Order for the rule on where declarations may appear.
Numeric Types
There are three numeric types in EasyHDL:
| Type | Description |
INT |
Signed integers in the range -2,147,483,648 to 2,147,483,647. |
FLOAT |
Signed or unsigned floating point values in the range 2.225074 x 10-308 to 1.797693 x 10308. DOUBLE is accepted as a synonym for FLOAT and declares exactly the same type. |
TIME |
Signed or unsigned integers capable of holding an event time which has a resolution of 1ps. The current time in an analogue simulation may be obtained from the system variable REALTIME which returns a floating point quantity. |
String Types
EasyHDL supports a simple string type
STRING Simple ASCII character string.
Various operations can be performed on a string variable:
STRING S1 = "Hello", S2 = "World", S3
INT C
S3 = S1+" "+S2 // S3 <= "Hello World"
S3 = S1[1,4] // S3 <= "Hell"
C=ASC(S1) // C <= 48h ('H')
C=ASC(S1[2]) // C <= 65h ('e')
S3 = CHR(C+1) // S3 <= "f"
A subscripted string can be read but not written, so S3 = S1[1,4] is legal whereas S1[1,4] = "Good" is a compile error. To replace part of a string, build a new one by concatenation.
A string constant is written between double quotes and may contain the following escape sequences:
| Sequence | Description |
\n |
Line feed. |
\r |
Carriage return. |
\t |
Tab. |
\xNN |
The character whose code is the hexadecimal value NN. |
\" |
A double quote character. |
\' |
A single quote character. |
"" |
A double quote character, written as a doubled quote inside the string. |
A string may hold up to 255 characters.
BOOL and PIN Types
The EasyHDL PIN is provided for accessing the pins on the digital generator(s) that the script is linked to. Variables declared of this type are 'linked' to the same-named generator(s) to which the script is assigned.
Declaring the Output(s) for more information on how to declare PIN variables.
Declarations of this type must appear with the rest of the declarations, before the first executable statement, although the order within that block does not matter. As for other EasyHDL types, initialisation of the variables declared is allowed.
When a variable of type PIN is read or tested, it returns both the current and previous activity of the pin, where the pin's activity is dependant on the state of the net to which the pin is connected, the electrical type of the pin, the translation-table for the logic family, and any properties assigned to the pin by the owner device or generator. Variables of type PIN should only be tested by equivalence to one of the following system constants:
| Type | Description |
TRUE,ACTIVE |
The pin is currently active; its previous activity is ignored. |
FALSE,INACTIVE |
The pin is currently inactive, its previous activity is ignored. |
FF |
The pin was inactive and remains inactive. |
FT,POSEDGE |
The pin was inactive and has become active. |
TF,NEGEDGE |
The pin was active and has become inactive. |
TT |
The pin was active and remains active. |
It is possible to directly drive the net to which an output pin connects, regardless of the electrical type of the pin or any properties assigned to it, by assigning the PIN variable one of the following system constants:
| Type | Description |
FLT |
Drive the net with the floating state. |
SLO |
Drive the net with a strong low. |
SHI |
Drive the net with a strong high. |
WLO |
Drive the net with a weak low. |
WHI |
Drive the net with a weak high. |
As the storage of a pin's activity state is complex, the special type BOOL is provided for holding the state of a PIN variable. The BOOL type is identical to the PIN type except that variables declared to be of type BOOL are not linked to an external pin.
NODE Type
The EasyHDL type NODE is provided for accessing the pins on the analogue generator(s) that the script is linked to. Variables declared of this type are 'linked' to the same-named generator(s) to which the script is assigned.
Declaring the Output(s) for more information on how to declare NODE variables.
Declarations of this type must appear with the rest of the declarations, before the first executable statement, although the order within that block does not matter. As for other EasyHDL types, initialisation of the variables declared is allowed.
When a variable of type NODE is read or tested, it returns the voltage or current value that it is driving. In the case of a timed transition, this will be the interpolated value at the current simulation time.
Assigning To Variables
Assignments to single variables have the general syntax:
[[LET]] variable = expr'n[[,variable=expr'n]][[,etc]]
For example:
INT VAR1, VAR2, VAR3
...
VAR1=10, VAR2=20, VAR3=30
In general, the result of any expression is always cast to the type of the variable it is being assigned to prior to assignment. The exception to this is assigning a net state to a variable of type PIN that links to an external generator or output device pin, where the state is applied directly to the net the pin or generator connects to.
Arrays can also be assigned. If the expression yields an array result and the number of elements in the expression array is at least the same as the number of elements in the array variable being assigned, then the assignment operation assigns each element from the expression to the variable array in turn starting at the lower bound of each array. If there are insufficient elements in the expression result for the array variable being assigned, a run-time error results.
For example:
INT A[10..19]
A[10..12]=A[15..19] // A[10]=A[15], A[11]=A[16], A[12]=A[17]
A[10..15]=A[16..17] // Error, insufficient elements in // A[16..17].
If the expression result is a single value, and the array variable being assigned is not of type PIN, then this value is first cast to the type of the array variable and is then assigned to each element in turn. For variable arrays of type PIN, the value is first cast to a INT and then each element of the PIN array is set active or inactive according to whether the bit in the INT result is set or reset respectively. The lowest element in the array is always set according to the value of bit zero of expression result, the next element according to bit one, and so on. Assignment is not made according to the value of the bit corresponding to element number. For example:
INT A[3]
PIN D[2..3]
A=4 // A[0]=4, A[1]=4, A[2]=4
D=10 // D[2]=Bit 0 of 10, D[3]=Bit 1 of 10.
An assignment to a variable of type PIN (either a single variable or an array) can use an extended syntax to provide timing information, as follows:
pin_var = expression AFTER time_expression
pin_var = expression AFTER tlh_expression,thl_expression
pin_var = expression AT|@ time_expression
The first syntax uses the keyword AFTER and a single time_expression to force the pin's output to change only after the specified time. The second syntax again uses the keyword AFTER, but has two time expressions, tlh_expression and thl_expression to force the pin's output to change either after tlh_expression if the pin's output change involves a low-to-high transition, or after thl_expression if the pin's output change involves a high-to-low transition. Note that the terms low-to-high and high-to-low are general - an output switching from a floating state to a weak-low is deemed to be performing a high-to-low transition. The final syntax uses the AT or @ symbol to specify an absolute time at which the pin's output is to change.
It should be noted that an assignment to a pin does not occur until the time specified, and not until after the script ends or is suspended, even if the assignment time is the same as the script invocation time. Thus assigning to a pin and subsequently testing pin within the same script invocation will not yield the assigned value.
For example:
PIN p
p=TRUE // Assume pin was inactive, we assign it active.
IF p=TRUE THEN // Pin is still inactive, therefore test fails.
...
See Also:
BOOL and PIN Types for more information on assigning to PIN variables.