X-Git-Url: http://rtime.felk.cvut.cz/gitweb/ert_linux.git/blobdiff_plain/60e06334b0bae3c8811a14985a3269e58fb05fce..cc5c048815a3558f4de7f701ff683178604c4188:/ert_linux/ert_linux_multitasking_main.tlc diff --git a/ert_linux/ert_linux_multitasking_main.tlc b/ert_linux/ert_linux_multitasking_main.tlc index 96ca6ea..dfae42a 100644 --- a/ert_linux/ert_linux_multitasking_main.tlc +++ b/ert_linux/ert_linux_multitasking_main.tlc @@ -1,22 +1,16 @@ %% -%% linux_ert_target_multitasking_main.tlc %% %% description: -%% This TLC script generates ert_main for multi-rate / multi-tasking +%% This TLC script generates ert_main.c %% case. %% -%% date: 3nd Feb 2009 +%% authors: Michal Sojka +%% Lukas Hamacek %% -%% author: Lukas Hamacek, Michal Sojka -%% e-mail: hamacl1@fel.cvut.cz %% Department of Control Engineering %% Faculty of Electrical Engineering %% Czech Technical University in Prague %% -%% modifications: -%% 2009/2/3 - Lukas Hamacek -%% creation of the file -%% %% GENERATEDECLARATIONS %% This function generates main function declarations. @@ -27,7 +21,8 @@ %function generateDeclarations() Output /* Multirate - Multitasking case main file */ - #define _POSIX_C_SOURCE 199309L /* For clock_gettime() */ + #define _BSD_SOURCE /* For usleep() */ + #define _POSIX_C_SOURCE 200112L /* For clock_gettime() & clock_nanosleep() */ #include /* This ert_main.c example uses printf/fflush */ #include /* Thread library header file */ #include /* OS scheduler header file */ @@ -175,24 +170,32 @@ %endforeach /* Execute base rate step */ - %_step0(); + %if solverMode == "SingleTasking" + %_step(); + %else + %_step0(); + %endif %if extMode == 1 rtExtModeCheckEndTrigger(); %endif - next.tv_sec += period.tv_sec; - next.tv_nsec += period.tv_nsec; - if (next.tv_nsec >= 1000000000) { - next.tv_sec++; - next.tv_nsec -= 1000000000; - } - clock_gettime(CLOCK_MONOTONIC, &now); - if (now.tv_sec > next.tv_sec || - (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) { - uint64_T nsec = (now.tv_sec - next.tv_sec) * 1000000000 + now.tv_nsec - next.tv_nsec; - fprintf(stderr, "Base rate (%s) overrun by %d us\n", (int)(nsec/1000)); - } + do { + next.tv_sec += period.tv_sec; + next.tv_nsec += period.tv_nsec; + if (next.tv_nsec >= 1000000000) { + next.tv_sec++; + next.tv_nsec -= 1000000000; + } + clock_gettime(CLOCK_MONOTONIC, &now); + if (now.tv_sec > next.tv_sec || + (now.tv_sec == next.tv_sec && now.tv_nsec > next.tv_nsec)) { + uint32_T usec = (now.tv_sec - next.tv_sec) * 1000000 + (now.tv_nsec - next.tv_nsec)/1000; + fprintf(stderr, "Base rate (%s) overrun by %d us\n", usec); + next = now; + continue; + } + } while (0); clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next, NULL); }