-
Notifications
You must be signed in to change notification settings - Fork 0
/
ert_main.cpp
93 lines (77 loc) · 1.8 KB
/
ert_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <stdlib.h>
#include "stepvel.h"
#include "stepvel_private.h"
#include "rtwtypes.h"
#include "limits.h"
#include "linuxinitialize.h"
#define UNUSED(x) x = x
/* Function prototype declaration*/
void exitFcn(int sig);
void *terminateTask(void *arg);
void *baseRateTask(void *arg);
void *subrateTask(void *arg);
volatile boolean_T stopRequested = false;
volatile boolean_T runModel = true;
sem_t stopSem;
sem_t baserateTaskSem;
pthread_t schedulerThread;
pthread_t baseRateThread;
unsigned long threadJoinStatus[8];
int terminatingmodel = 0;
void *baseRateTask(void *arg)
{
runModel = (rtmGetErrorStatus(stepvel_M) == (NULL));
while (runModel) {
sem_wait(&baserateTaskSem);
stepvel_step();
/* Get model outputs here */
stopRequested = !((rtmGetErrorStatus(stepvel_M) == (NULL)));
runModel = !stopRequested;
}
runModel = 0;
terminateTask(arg);
pthread_exit((void *)0);
return NULL;
}
void exitFcn(int sig)
{
UNUSED(sig);
rtmSetErrorStatus(stepvel_M, "stopping the model");
}
void *terminateTask(void *arg)
{
UNUSED(arg);
terminatingmodel = 1;
{
runModel = 0;
}
/* Disable rt_OneStep() here */
/* Terminate model */
stepvel_terminate();
sem_post(&stopSem);
return NULL;
}
int main(int argc, char **argv)
{
UNUSED(argc);
UNUSED(argv);
void slros_node_init(int argc, char** argv);
slros_node_init(argc, argv);
rtmSetErrorStatus(stepvel_M, 0);
/* Initialize model */
stepvel_initialize();
/* Call RTOS Initialization function */
myRTOSInit(0.05, 0);
/* Wait for stop semaphore */
sem_wait(&stopSem);
#if (MW_NUMBER_TIMER_DRIVEN_TASKS > 0)
{
int i;
for (i=0; i < MW_NUMBER_TIMER_DRIVEN_TASKS; i++) {
CHECK_STATUS(sem_destroy(&timerTaskSem[i]), 0, "sem_destroy");
}
}
#endif
return 0;
}