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 39<br />

Remark: It is convenient to write the string conversion functions<br />

together with the other data-handling functions. <strong>The</strong>ir definitions<br />

can be enclosed in a “#ifdef SIMUL” directive, making<br />

them defined only in simulation mode.<br />

3.3.5 Constants<br />

Each constant used in the <strong>Esterel</strong> program must be defined in C with the<br />

same name, unless it is initialized in the <strong>Esterel</strong> code. A constant can<br />

be defined either by a #define directive in prog.h or by a standard C<br />

variable definition. If not #defined, a constant is automatically declared to<br />

be extern in prog.c. It can therefore be defined in any other file. Consider<br />

the example:<br />

constant NUMBER_OF_PERSONS: integer,<br />

LUNCH_TIME: TIME;<br />

<strong>The</strong>n prog.h can contain<br />

#define NUMBER_OF_PERSONS 45<br />

and prog data.c can contain:<br />

TIME LUNCH_TIME = {12, 0, 0};<br />

3.3.6 Functions<br />

Each function used in the <strong>Esterel</strong> program must have a C definition. <strong>The</strong><br />

definition can be given either by a #define directive in prog.h or by a classical<br />

C function definition. If not #defined, the C function is automatically<br />

declared to be extern in the generated file prog.c.<br />

A C function definition must match the source function type declaration.<br />

For example, let us define the function declared in the PROG module by the<br />

following <strong>Esterel</strong> declaration:<br />

function FETCH (ARRAY_10_OF_TIME, integer) : TIME;<br />

A possible definition is:<br />

TIME FETCH (a, i)<br />

ARRAY_10_OF_TIME a;<br />

int i;<br />

{<br />

return(a.array[i]);<br />

}

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

Saved successfully!

Ooh no, something went wrong!