Designing Your Model: Model-Code Correspondence : Activity Charts : Task Activities : Extended Task - Generated Code

Extended Task - Generated Code

The code for an extended Task that contains activities A21 and A22 will resemble the following:

TASK (TASK2)
{

cgSingleBuffer_TASK2.eventMask = 0xff;

start_activity_A21;

start_activity_A22;

while(1) {

cgActivity_A21();

cgActivity_A22();

WaitEvent(cgSingleBuffer_TASK2.eventMask);

ClearEvent(cgSingleBuffer_TASK2.eventMask);

}

/* TerminateTask(); */

}

If a statechart is added beneath the Task, but not as a direct descendant, the code will resemble the following:

TASK (TASK2)
{

cgSingleBuffer_TASK2.eventMask = 0xff;

start_activity_A21;

start_activity_A22;

while(1) {

do {

cgGlobalFlags &= ~BITSUPERSTEP_TASK2;

cgActivity_A21();

cgActivity_A22();

if(cgDoubleBufferNew_TASK2.cg_Events)

cgGlobalFlags |= BITSUPERSTEP_TASK2;

cgDoubleBufferOld_TASK2 = cgDoubleBufferNew_TASK2;

cgDoubleBufferNew_TASK2.cg_Events = 0;

} while ( (cgGlobalFlags & BITSUPERSTEP_TASK2) != 0);

WaitEvent(cgSingleBuffer_TASK2.eventMask);

GetEvent(TASK2, &cgSingleBuffer_TASK2.eventsBuff);

ClearEvent(cgSingleBuffer_TASK2.eventMask);

}

/* TerminateTask(); */

}

If the Task is periodic, with a period of 10 ticks, the code will resemble the following:

TASK (TASK2)
{

SetRelAlarm(TASK2_ALARM, 1, 10);

cgSingleBuffer_TASK2.eventMask = 0xff;

start_activity_A21;

start_activity_A22;

while(1) {

do {

cgGlobalFlags &= ~BITSUPERSTEP_TASK2;

cgActivity_A21();

cgActivity_A22();

if(cgDoubleBufferNew_TASK2.cg_Events)

cgGlobalFlags |= BITSUPERSTEP_TASK2;

cgDoubleBufferOld_TASK2 = cgDoubleBufferNew_TASK2;

cgDoubleBufferNew_TASK2.cg_Events = 0;

} while ( (cgGlobalFlags & BITSUPERSTEP_TASK2) != 0);

WaitEvent(cgSingleBuffer_TASK2.eventMask);

GetEvent(TASK2, &cgSingleBuffer_TASK2.eventsBuff);

ClearEvent(cgSingleBuffer_TASK2.eventMask);

if(cgSingleBuffer_TASK2.eventsBuff & 0x01)

GEN_IN_CURRENT(TASK2_EV);

}

/* TerminateTask(); */

}