+1 855-VERIFYY
+

Newsletter:Apache Velocity Template

Apache Velocity Template

Introduction-

IDesignSpec (IDS) introduces its new feature which enable users to customize and create their own outputs using Velocity template- main benefit of using Apache Velocity Template. It enables user to create fast and personalized outputs.

Our Velocity template is based on a very simple architecture with two components – a data model and the template. This data model is basically the input IDesignSpec file which describes the design specification. Input file can be of any format which is supported by IDesignSpec example: SystemRDL, IP-XACT, Word, Excel, RALF, etc. The other component is the Template, which is defined and designed by the user. The template is a plain text file that describes the static output and dynamic elements from the data model.

To design this template, we provide several handy commands, like, $ids.get_system, $ids.get_board, $ids.get_chip, $ids.get_object_by_name, $ids.get_top, $ids.get_prop, etc. Also, it is totally Java based, so mostly all the functions of Java langauge works in here. The Template Processor processes both Data model as well as Template to provide the user with required output.

Here, “Templates” in IDS documents translates into “Objects” in Velocity template. The Velocity Application Programming Interface introduces seven object types, each corresponding to a document template. The following types of objects have been introduced in the Velocity API of IDS:

    • System
    • Board
    • Chip
    • Block
    • RegGroup
    • Reg
    • Fields

For example, property / value pairs on the templates translate into ‘properties’ within objects. So for a “block”, the value specified for offset can be accessed by getting the ‘offset’ property of the block object in velocity Template.

Example-

Here is a sample that illustrates the usage of Velocity Templates. It shows the design specification, the velocity template and the generated output.

  1. Design Specification

ra2

  1. Velocity Template

#set($put=”include”)
#set($top=$ids.get_top())
#$set “global_types.h”
#$set “global_registers.h”
#foreach($child in $ids.get_objects($top))
/****************************************************************************
* VARIABLE Data structure of register $ids.get_prop($child,”name”) in
* component instance $ids.get_prop($top,”name”)
****************************************************************************/
BW_register_info_t $ids.get_prop($top,”name”)__$ids.get_prop($child,”name”) = {
“$ids.get_prop($child,”name”)”,
$ids.get_prop($child,”offset”),
$ids.get_prop($child,”default”),
$ids.get_prop($child,”size”)
};
#end
/****************************************************************************
* VARIABLE reg_info
****************************************************************************/
const BW_register_info_t *BW_reg_info[] = {
#foreach($child in $ids.get_objects($top))
#if($comma==1),#end&$ids.get_prop($top,”name”)__$ids.get_prop($child,”name”) #set($comma = 1)
#end
};

  1. Command-

idsbatch <input_file> -velocity <velocity_file>

  1. Output-

#$set “global_types.h”
#$set “global_registers.h”
/****************************************************************************
*
* VARIABLE Data structure of register Reg1 in
* component instance block_name

****************************************************************************/

BW_register_info_t block_name__Reg1 = {
“Reg1″,
0,
0×00000000,
4
};
/****************************************************************************
*
* VARIABLE Data structure of register Reg2 in
* component instance block_name

****************************************************************************/

BW_register_info_t block_name__Reg2 = {
“Reg2″,
4,
0×00000000,
4
};
/****************************************************************************
* VARIABLE reg_info
****************************************************************************/

const BW_register_info_t *BW_reg_info[] = {
&block_name__Reg1 , &block_name__Reg2
};

Conclusion-

Apache Velocity Template is a vital feature for personalizing the outputs in the user desired format. Along with this, it is faster. It opens up the possibility for the user to generate any desired output.

By: Himanshu