%%\r
-%% linux_ert_target_multitasking_main.tlc\r
%%\r
%% description:\r
-%% This TLC script generates ert_main for multi-rate / multi-tasking\r
+%% This TLC script generates ert_main.c\r
%% case.\r
%%\r
-%% date: 3nd Feb 2009\r
+%% authors: Michal Sojka <sojkam1@fel.cvut.cz>\r
+%% Lukas Hamacek <hamacl1@fel.cvut.cz>\r
%%\r
-%% author: Lukas Hamacek, Michal Sojka\r
-%% e-mail: hamacl1@fel.cvut.cz\r
%% Department of Control Engineering\r
%% Faculty of Electrical Engineering\r
%% Czech Technical University in Prague\r
%%\r
-%% modifications:\r
-%% 2009/2/3 - Lukas Hamacek\r
-%% creation of the file\r
-%%\r
\r
%% GENERATEDECLARATIONS\r
%% This function generates main function declarations.\r
%function generateDeclarations() Output\r
\r
/* Multirate - Multitasking case main file */\r
- #define _POSIX_C_SOURCE 199309L /* For clock_gettime() */\r
+ #define _BSD_SOURCE /* For usleep() */\r
+ #define _POSIX_C_SOURCE 200112L /* For clock_gettime() & clock_nanosleep() */\r
#include <stdio.h> /* This ert_main.c example uses printf/fflush */\r
#include <pthread.h> /* Thread library header file */\r
#include <sched.h> /* OS scheduler header file */\r
%endforeach\r
\r
/* Execute base rate step */\r
- %<modelName>_step0();\r
+ %if solverMode == "SingleTasking"\r
+ %<modelName>_step();\r
+ %else\r
+ %<modelName>_step0();\r
+ %endif\r
\r
%if extMode == 1\r
rtExtModeCheckEndTrigger();\r
%endif\r
\r
- next.tv_sec += period.tv_sec;\r
- next.tv_nsec += period.tv_nsec;\r
- if (next.tv_nsec >= 1000000000) {\r
- next.tv_sec++;\r
- next.tv_nsec -= 1000000000;\r
- }\r
- clock_gettime(CLOCK_MONOTONIC, &now);\r
- if (now.tv_sec > next.tv_sec ||\r
- (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) {\r
- uint64_T nsec = (now.tv_sec - next.tv_sec) * 1000000000 + now.tv_nsec - next.tv_nsec;\r
- fprintf(stderr, "Base rate (%<fundamentalStepSize>s) overrun by %d us\n", (int)(nsec/1000));\r
- }\r
+ do {\r
+ next.tv_sec += period.tv_sec;\r
+ next.tv_nsec += period.tv_nsec;\r
+ if (next.tv_nsec >= 1000000000) {\r
+ next.tv_sec++;\r
+ next.tv_nsec -= 1000000000;\r
+ }\r
+ clock_gettime(CLOCK_MONOTONIC, &now);\r
+ if (now.tv_sec > next.tv_sec ||\r
+ (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) {\r
+ uint32_T usec = (now.tv_sec - next.tv_sec) * 1000000 + (now.tv_nsec - next.tv_nsec)/1000;\r
+ fprintf(stderr, "Base rate (%<fundamentalStepSize>s) overrun by %d us\n", usec);\r
+ next = now;\r
+ continue;\r
+ }\r
+ } while (0);\r
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL);\r
\r
}\r