55,7 → 55,11 |
/*==================================* |
* Global data local to this module * |
*==================================*/ |
|
|
RT_MODEL *S; |
const char *status; |
real_T finaltime = -2.0; |
volatile int simulation_run; |
static struct { |
int_T stopExecutionFlag; |
int_T isrOverrun; |
231,20 → 235,18 |
|
} /* end rtOneStep */ |
|
int main() { |
void Init_RealTime_Workshop() { |
|
RT_MODEL *S; |
const char *status; |
real_T finaltime = -2.0; |
|
/**************************** |
/**************************** |
* Initialize global memory * |
****************************/ |
|
(void)memset(&GBLbuf, 0, sizeof(GBLbuf)); |
|
/************************ |
/************************ |
* Initialize the model * |
************************/ |
|
rt_InitInfAndNaN(sizeof(real_T)); |
|
S = MODEL(); |
253,6 → 255,7 |
rtmGetErrorStatus(S)); |
sys_end(); |
} |
|
if (finaltime >= 0.0 || finaltime == RUN_FOREVER) rtmSetTFinal(S,finaltime); |
|
MdlInitializeSizes(); |
272,6 → 275,7 |
cprintf("Failed to initialize sample time engine: %s\n", status); |
sys_end(); |
} |
|
rt_CreateIntegrationData(S); |
|
rtExtModeCheckInit(); |
278,7 → 282,7 |
rtExtModeWaitForStartMsg(rtmGetRTWExtModeInfo(S), |
(boolean_T *)&rtmGetStopRequested(S)); |
|
cprintf("\n** starting the model **\n"); |
cprintf("\n** Starting the model **\n"); |
|
MdlStart(); |
if (rtmGetErrorStatus(S) != NULL) { |
294,25 → 298,11 |
if (rtmGetTFinal(S) == RUN_FOREVER) { |
cprintf("\n**May run forever. Model stop time set to infinity.**\n"); |
} |
|
while (!GBLbuf.stopExecutionFlag && |
(rtmGetTFinal(S) == RUN_FOREVER || |
rtmGetTFinal(S)-rtmGetT(S) > rtmGetT(S)*DBL_EPSILON)) { |
|
rtExtModePauseIfNeeded(rtmGetRTWExtModeInfo(S), |
(boolean_T *)&rtmGetStopRequested(S)); |
} |
|
cprintf("."); |
void Close_RealTime_Workshop() { |
|
if (rtmGetStopRequested(S)) break; |
rt_OneStep(S); |
} |
|
if (!GBLbuf.stopExecutionFlag && !rtmGetStopRequested(S)) { |
/* Execute model last time step */ |
rt_OneStep(S); |
} |
|
/******************** |
* Cleanup and exit * |
********************/ |
334,8 → 324,68 |
sys_end(); |
} |
|
MdlTerminate(); |
MdlTerminate(); |
|
} |
|
TASK RTW_body(void *arg) { |
|
simulation_run = 1; |
|
while (!GBLbuf.stopExecutionFlag && |
(rtmGetTFinal(S) == RUN_FOREVER || |
rtmGetTFinal(S)-rtmGetT(S) > rtmGetT(S)*DBL_EPSILON)) { |
|
rtExtModePauseIfNeeded(rtmGetRTWExtModeInfo(S), |
(boolean_T *)&rtmGetStopRequested(S)); |
|
cprintf(".(%dus)",(int)(rtmGetT(S)*1000000)); |
|
if (rtmGetStopRequested(S)) break; |
rt_OneStep(S); |
|
task_endcycle(); |
|
} |
|
if (!GBLbuf.stopExecutionFlag && !rtmGetStopRequested(S)) { |
/* Execute model last time step */ |
rt_OneStep(S); |
} |
|
simulation_run = 0; |
|
return NULL; |
|
} |
|
int main() { |
|
HARD_TASK_MODEL RTW_task; |
PID RTW_pid; |
|
Init_RealTime_Workshop(); |
|
hard_task_default_model(RTW_task); |
hard_task_def_mit(RTW_task,rtmGetStepSize(S) * 1000000); |
hard_task_def_wcet(RTW_task,10000); |
hard_task_def_usemath(RTW_task); |
hard_task_def_ctrl_jet(RTW_task); |
|
RTW_pid = task_create("RTW",RTW_body,&RTW_task,NULL); |
if (RTW_pid == NIL) { |
cprintf("Error creating RealTime Workshop Task\n"); |
sys_end(); |
} |
|
task_activate(RTW_pid); |
|
while(simulation_run); |
|
Close_RealTime_Workshop(); |
|
sys_end(); |
|
return 0; |
|
} /* end main */ |
} |