%%\r
%function generateMain() Output\r
/**\r
- * This is the thread function of the main loop.\r
+ * This is the thread function of the base rate loop.\r
* Fundamental sample time = %<fundamentalStepSize>s\r
*/\r
void * base_rate()\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
%<modelName>_initialize();\r
simulationFinished = 0;\r
\r
+ /* Prepare task attributes */\r
CHECK0(pthread_attr_init(&attr));\r
CHECK0(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED));\r
CHECK0(pthread_attr_setschedpolicy(&attr, SCHED_FIFO));\r
\r
%endforeach\r
\r
- /* Starting the main loop */\r
+ /* Starting the base rate thread */\r
sched_param.sched_priority = MAX_PRIO;\r
CHECK0(pthread_attr_setschedparam(&attr, &sched_param));\r
CHECK0(pthread_create(&base_rate_thread, &attr, base_rate, NULL));\r