Gene-Auto User's Guide

Author: Fady NASSIF Serge STEER Version: 0.3 14/05/2009 User's Guide

1. Introduction: The objectives GeneAuto tools is the generation of certifiable C code from or Scicos models. To ease the certification process, the model's usable class have been strongly restricted : the models must only represent sampled systems with a unique sample time, the usable blocks set is also limited, ...

The standard Scicos tool includes its own C code generator, which is able to generate C code for a larger class of models but without certification objectives.

This guide is addressed to the users of the Gene-Auto tools to help them implementing the code generator into Scicos. In this document, we will explain how to: ● Building and loading GeneAuto plug-in ● Using a diagram with GeneAuto blocks ● Generate the code using the GeneAuto's generator ● Add new blocks for the GeneAuto library. The user can also find the blocks supported by Gene-Auto implemented in the palette “Gene-Auto”.

2. Building and loading GeneAuto plug in: The distributed package for the GeneAuto Scicos plug in is a source version. It must be built before use

Prerequisites To be able to build and run this version of the GeneAuto plugin for the following packages must be available on your computer ( or Windows) – The Scilab version named Scicoslab-gtk-4.3-3 which is available at http://www.scicoslab.org/. In the following, the term “Scilab” will refer to this version. As soon as possible the GeneAuto plug in will be adapted to the official Scilab-5.x version. – The ocaml-3.10.2 compiler which is available at http://caml.inria.fr/pub/distrib/ocaml-3.10/ – A C compiler

Build the source version The current distribution of the GeneAuto plug in includes (ans had been tested with) a pre-compiled version of the GeneAuto tool chain (release 2.4.2), but the GeneAuto specific Scicos block simulation functions must be built as well as the Scilab functions used by the plug in. To do so, the user must execute the files “builder.sce” and “loader.sce” from the main folder of the package. • He can execute the following Scilab instructions: exec ('/builder.sce'); exec ('/loader.sce'); Where stands for the GeneAuto plugin installation path.

• Or, he can click on “File” from the menu of Scilab , choose the “File Operations”, go to the GeneAuto directory, choose the “builder.sce” file and click on the Exec button. Same procedure is done for the loader. The figure below shows how to exec the builder file using the second method.

Scicos Team: Fady NASSIF INRIA 2/7 Serge STEER User's Guide

Load the plug in into Scilab The load step have to be done every time the user launches a new Scilab prompt. To avoid this operation the user can use the Scilab start-up facility to make the plug in loaded when Scilab starts.

This may be done adding the instruction exec ('/loader.sce'); into the scilab.ini file located in the SCIHOME directory (enter SCIHOME at the Scilab prompt to get its actual value).

A simple way is to use the Scilab text editor using the following instruction: -->scipad(SCIHOME+'/scilab.ini'); add the loader instruction and to not forget to save the file...

The load step have to be done everytime the user launches a new Scilab prompt. To avoid this operation everytime, the user can enter, only for one time, the following Scilab instruction after executing the builder: -->scipad(SCIHOME+'/scilab.ini'); to edit the scilab startup file. Then, add the instruction: exec (/loader.sce'); in the opened file and save it.

3. Using a diagram with GeneAuto blocks: In the Demo, a new field is created for the demos that uses the GeneAuto blocks. The user can access to these demos by clicking on the Demo in the Scilab prompt, and choose the GeneAuto. The user can also creates his own Gene-Auto diagram. He can launch Scicos from the Scilab prompt: --> scicos(); Then, click on the “Palette” from the Scicos menu bar, choose “Palettes”, and then select the “GeneAuto” palette. The blocks inside this palette are all the Scicos blocks compatibles with the

Scicos Team: Fady NASSIF INRIA 3/7 Serge STEER User's Guide specifications. Some of them are standards Scicos blocks some other a specific to GeneAuto. A Scicos diagram with the block PULSE from the GeneAuto palette is shown in the figure below.

4. Generating and simulating using the GeneAuto code generator: After creating the diagram, and before launching the Gene-Auto code generator the user must put the desired region to generate in a SuperBlock. If we consider the example above, and if we consider that we want to generate the code of the part inside the red rectangle, we must: ● Select the region ● Click on the right button of the mouse, and choose the “Region To Super Block” menu. It is time to generate the code of the Super block created. The user must first click on the Super block one time to have it selected, then choose the option “Tools” from the menu, and then select the “Gene-Auto” item (The “GASM export” item can also be used to generate only the GASM model (in an xml file).

If everything is going well,The Scicos model contained in the super block will be first translated into the GeneAuto System Model (GASM) which will be saved as an xml file in a user given location. After that the GeneAuto tool chain is automatically called to generate the associated C code, a new Scicos blockbased on the generated C code is then created in the Scicos diagram. The user can now connect this block as a basic Scicos block, for example to be able to compare the Scicos model with the GeneAuto generated one in a simulation context.

Some blocks like the UnitDelay block uses the sample time, the Sample time in Scicos is presented by the SampleCLK block (shown by the green circle in the figure above). If the Region-to-Generate contains more than one SampleCLK, the sample times must be equal to be supported by Gene-Auto. The “t5.cos” diagram, found in the “GeneAutoScicos/tests/t5/” directory, is an example using the SampleCLK block.

NB: in the directory the user selected, the program generates:

Scicos Team: Fady NASSIF INRIA 4/7 Serge STEER User's Guide

● three folders : – macros/ contains the Scilab interfacing function of the generated block – src/ contains the C source files generated by the Gene-Auto code generator as well as the Scicos block simulation function (_blk.c ). This folder also contains the Scilab scripts builder.sce and loader.sce used for building the dynamic library of the C functions. – xml/ contains the files .xml.mdl created by the Scicos to Gene-Auto translator and a sub directory named tmp which contains, the GeneAuto tool chain log file, the intermediate versions of the GeneAuto System Model. ● two Scilab script files : – builder.sce, used by Scilab to build all the generated stuff – loader.sce, used by Scilab to load it.

5. Adding new blocks to the Gene-Auto library: To add a new block to the Gene-Auto library, the user must first write the interface and the silulation function of the block (see the Scicos Help for more details). Once these Scicos specific functions are written the user have to write the Scicos-Gene-Auto interface function of the block. This function take the Scicos block data structure as input and generates the block parameters description in the four left hand side argument: – name : a character string, the name of the block – labels: a vector of character strings, the parameter identifiers or an empty matrix if the block has no parameter at all. – values: a list, the current values for each parameter. A parameter value is used if there is no expression available for the associated parameter or if the given expression cannot be evaluated. – exprs: a vector of character string, the expressions that cab be used to compute the values. If no expression is available for a given parameter, the corresponding entry in exprs must be an empty string ('' or emptystr) The name of the function should always be _tran.

Example: The Scilab function associated with the GAIN Scicos block is:

function [name,labels,values,exprs]=GAINBLK_tran(o) values=list(); name='Gain' labels=['Gain';'Multiplication'] //two parameters if o.model.rpar==[] then values(1)=o.model.opar(1);else values(1)=o.model.rpar;end if size(values(1),'*')==1 then values(2)='Element-wise(K.*u)' else values(2)='Matrix(K*u)' end // o.graphics.exprs contains the expression the user has given in the GAIN block dialog // for the gain value parameter. //It may be things like “2.45', “1/3”, “A” (where A is a variable defined in the Scicos context), ... exprs=[o.graphics.exprs, emptystr()] // the second value has no associated expression so emptystr() is used. endfunction

Scicos Team: Fady NASSIF INRIA 5/7 Serge STEER User's Guide

A new GeneAuto.jar must be created including the “Backend” and the “Typer” of the new block (see the GeneAuto tool manual. 6. Gene-Auto palette: In the Gene-Auto palette, we can find all the predefined blocks supported by the Gene-Auto generator and that are implemented in Scicos.

Scicos Team: Fady NASSIF INRIA 6/7 Serge STEER