30.07.2013 Views

The Esterel v5 21 System Manual - Courses

The Esterel v5 21 System Manual - Courses

The Esterel v5 21 System Manual - Courses

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.3. C CODE FOR DATA HANDLING 33<br />

During its execution, the reaction function can call the user-supplied C<br />

data-handling functions that implement the functions, procedures, and tasks<br />

declared in the <strong>Esterel</strong> program. It can also read a sensor S1 by calling the<br />

user-supplied sensor C function PROG S S1 that should return the sensor’s<br />

value.<br />

If the <strong>Esterel</strong> program emits the output signal O1, the generated C code<br />

calls the user-supplied output C function PROG O O1 with the appropriate<br />

output value as argument if the signal O1 is valued.<br />

To summarize, the user must write functions to read sensors, named<br />

PROG S xx, and output functions, named PROG O xx. <strong>The</strong> reaction function<br />

PROG and the input functions PROG I xx are defined in the generated code.<br />

Notice that all functions related to program input, output, or execution<br />

are prefixed with the program name. On the contrary, the data-handling<br />

function names and the module names are not prefixed. <strong>The</strong>refore, it is<br />

unwise to use a name of the predefined C functions as esterel function name<br />

(itoa for example) and a C keyword as module name (main for example).<br />

3.3 C Code for Data Handling<br />

3.3.1 Where to Define the Data-handling Objects<br />

Assume as before that the basename used by <strong>Esterel</strong> is prog. <strong>The</strong>n a directive<br />

of the form<br />

#include "prog.h"<br />

is generated in the prog.c file if the <strong>Esterel</strong> input file declares a type, a<br />

constant, a function, a procedure, or a task.<br />

<strong>The</strong> prog.h include file must contain the code needed to separately compile<br />

the generated prog.c C file. <strong>The</strong>refore, prog.h must at least contain<br />

the C definition of the user-defined types used in the source program. It can<br />

also contain inline constant, function, and procedure definitions by #define<br />

directives.<br />

<strong>The</strong> constants, functions, and procedures used in the <strong>Esterel</strong> source program<br />

and not #defined in prog.h are automatically declared to be extern<br />

in the generated file prog.c. <strong>The</strong>y can be defined in any other C file. As<br />

said before, it is often convenient to write them in a file prog data.c.<br />

In all cases, the types, constants, functions, and procedures must be<br />

defined in C with the same name as in the <strong>Esterel</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!