Structure is a syntax that manages multiple wirings and registers.
The structure makes it possible to declare multiple wirings and registers at a time.
“struct” that abbreviates “structure” is used when a structure is declared.
Declaration of structure
A structure is declared using “struct syntax” independent of “declare syntax” and
“module syntax” of NSL.
Wiring and register to be declared in a struct syntax declare only the name and
the bit width of a “terminal”, and it determines whether it is a wiring or a register
when it is instantiated.
The declaration of a structure is described as follows.
struct structure_name {
Member_Name1 [Bit_Width] ;
Member_Name2 [Bit_Width] ;
………
} ;
※A semicolon is always required after a declaration of the structure.
Next, an example of NSL that uses a structure is shown.
struct st_RGB { R[8] ; //8bit terminal "R" of the structure "st_RGB" G[8] ; //8bit terminal "G" of the structure "st_RGB" B[8] ; //8bit terminal "B" of the structure "st_RGB" } ; |
It is instantiated in a module syntax when a structure is used,
and the structure is set to either of the register or the wiring at that time.
An instantiation of the structure is described as follows.
Declaration of wiring)
Structure_name wire Instance_name[Multiply]
Declaration of register)
Structure_name reg Instance_name[Multiply] = Initial_value
The multiplicity and the initial value may be omitted.
An initial value can be set only when the instance was declared in a register.
And, only one instance can be used when the multiplicity was omitted.
In addition, it is described as follows when an instance of the structure is used in a module syntax.
Example) In case of instance being used
Instance_name
Example) In case of instance member being used
Instance_name.Member_name
Since an instance specifies either of a wiring or a register,
it also uses a transfer that meets the wiring and the register.
When a structure was instantiated with a wiring,
the transfer of the value to the instance is described as follows.
Example) In case of being transferred to instance
Instance_name = Value
Example) In case of being transferred to instance member
Instance_name.Member_name = Value
When a structure is instantiated in a register, it is described as follows.
Example) In case of being transferred to whole instance
Instance_name := Value
Example) In case of being transferred to instance member
Instance_name.Member_name := Value
An example of the instantiation in the structure is shown as follows.
Example 12-2 is a circuit that converts RGB signal into CMYK signal.
// ※When the bit depth of CMYK and RGB is 8bits respectively. struct st_RGB { R[8] ; //Red data G[8] ; //Green data B[8] ; //Blue data }; struct st_CMYK { C[8] ; //Cyan data M[8] ; //Magenta data Y[8] ; //Yellow data K[8] ; //Black data }; declare RGB_CMYK_conv { input inRGB[24] ; output outCMYK[32] ; func_in exec(inRGB) ; func_out ack(outCMYK) ; } module RGB_CMYK_conv { st_RGB reg RGB = 0 ; //The structure "st_RGB" is instantiated as "RGB" of the register. //"0" is set as an initial value. st_CMYK reg CMYK = 0 ; //The structure "st_CMYK" is instantiated as "CMYK" of the register. //"0" is set as an initial value. reg opr1[8] = 0 ; //An operation register is declared. reg opr2[8] = 0 ; //An operation register is declared. reg opr3[8] = 0 ; //An operation register is declared. func exec seq { //A function is described in the sequence syntax. RGB := inRGB ; //"inRGB" is written into the instance "RGB". //RGB signal is converted into CMYK signal. { opr1 := 8'hFF - RGB.R ; //"R" of the instance "RGB" is taken out and is operated. opr2 := 8'hFF - RGB.G ; //"G" of the instance "RGB" is taken out and is operated. opr3 := 8'hFF - RGB.B ; //"B" of the instance "RGB" is taken out and is operated. } //"K" is calculated. if(opr1>opr2) opr1 := opr2 ; if(opr1>opr3) opr1 := opr3 ; //The minimum value of "Opr1", "Opr2", and "Opr3" is substituted for "opr1". CMYK.K := opr1 ; //It is written in only "K" of the instance "CMYK". //"C", "M", and "Y" are calculated. { CMYK.C := 8'hFF - RGB.R - CMYK.K ; //"R" of "RGB", and "K" of "CMYK" are taken out and calculated. CMYK.M := 8'hFF - RGB.G - CMYK.K ; //"G" of "RGB", and "K" of "CMYK" are taken out and calculated. CMYK.Y := 8'hFF - RGB.B - CMYK.K ; //"B" of "RGB", and "K" of "CMYK" are taken out and calculated. } ack(CMYK) ; //"CMYK" is assumed to be an argument, and "ack" is output. } } |