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