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