1#include <stdio.h>
2#include <stdlib.h>
3#include "VisionTest.h"
4#include "VisionTest_private.h"
5#include "rtwtypes.h"
6#include "limits.h"
7#include "linuxinitialize.h"
8#define UNUSED(x) x = x
9
10/* Function prototype declaration*/
11void exitFcn(int sig);
12void *terminateTask(void *arg);
13void *baseRateTask(void *arg);
14void *subrateTask(void *arg);
15volatile boolean_T runModel = true;
16sem_t stopSem;
17sem_t baserateTaskSem;
18pthread_t schedulerThread;
19pthread_t baseRateThread;
20unsigned long threadJoinStatus[8];
21int terminatingmodel = 0;
22void *baseRateTask(void *arg)
23{
24 runModel = (rtmGetErrorStatus(VisionTest_M) == (NULL)) && !rtmGetStopRequested
25 (VisionTest_M);
26 while (runModel) {
27 sem_wait(&baserateTaskSem);
28
29 /* External mode */
30 {
31 boolean_T rtmStopReq = false;
32 rtExtModePauseIfNeeded(VisionTest_M->extModeInfo, 1, &rtmStopReq);
33 if (rtmStopReq) {
34 rtmSetStopRequested(VisionTest_M, true);
35 }
36
37 if (rtmGetStopRequested(VisionTest_M) == true) {
38 rtmSetErrorStatus(VisionTest_M, "Simulation finished");
39 break;
40 }
41 }
42
43 /* External mode */
44 {
45 boolean_T rtmStopReq = false;
46 rtExtModeOneStep(VisionTest_M->extModeInfo, 1, &rtmStopReq);
47 if (rtmStopReq) {
48 rtmSetStopRequested(VisionTest_M, true);
49 }
50 }
51
52 VisionTest_step();
53
54 /* Get model outputs here */
55 rtExtModeCheckEndTrigger();
56 runModel = (rtmGetErrorStatus(VisionTest_M) == (NULL)) &&
57 !rtmGetStopRequested(VisionTest_M);
58 }
59
60 runModel = 0;
61 terminateTask(arg);
62 pthread_exit((void *)0);
63 return NULL;
64}
65
66void exitFcn(int sig)
67{
68 UNUSED(sig);
69 rtmSetErrorStatus(VisionTest_M, "stopping the model");
70}
71
72void *terminateTask(void *arg)
73{
74 UNUSED(arg);
75 terminatingmodel = 1;
76 printf("**terminating the model**\n");
77 fflush(stdout);
78
79 {
80 runModel = 0;
81 }
82
83 rtExtModeShutdown(1);
84
85 /* Disable rt_OneStep() here */
86
87 /* Terminate model */
88 VisionTest_terminate();
89 sem_post(&stopSem);
90 return NULL;
91}
92
93int main(int argc, char **argv)
94{
95 UNUSED(argc);
96 UNUSED(argv);
97 printf("**starting the model**\n");
98 fflush(stdout);
99 rtmSetErrorStatus(VisionTest_M, 0);
100 rtExtModeParseArgs(argc, (const char_T **)argv, NULL);
101
102 /* Initialize model */
103 VisionTest_initialize();
104
105 /* External mode */
106 rtSetTFinalForExtMode(&rtmGetTFinal(VisionTest_M));
107 rtExtModeCheckInit(1);
108
109 {
110 boolean_T rtmStopReq = false;
111 rtExtModeWaitForStartPkt(VisionTest_M->extModeInfo, 1, &rtmStopReq);
112 if (rtmStopReq) {
113 rtmSetStopRequested(VisionTest_M, true);
114 }
115 }
116
117 rtERTExtModeStartMsg();
118
119 /* Call RTOS Initialization function */
120 myRTOSInit(0.02, 0);
121
122 /* Wait for stop semaphore */
123 sem_wait(&stopSem);
124 return 0;
125}
126