-
Notifications
You must be signed in to change notification settings - Fork 0
/
ert_main.cpp
118 lines (101 loc) · 2.56 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// Academic License - for use in teaching, academic research, and meeting
// course requirements at degree granting institutions only. Not for
// government, commercial, or other organizational use.
//
// File: ert_main.cpp
//
// Code generated for Simulink model 'obstacleStopper'.
//
// Model version : 1.86
// Simulink Coder version : 9.0 (R2018b) 24-May-2018
// C/C++ source code generated on : Fri May 24 15:32:42 2019
//
// Target selection: ert.tlc
// Embedded hardware selection: Generic->Unspecified (assume 32-bit Generic)
// Code generation objectives: Unspecified
// Validation result: Not run
//
#include <stdio.h>
#include <stdlib.h>
#include "obstacleStopper.h"
#include "obstacleStopper_private.h"
#include "rtwtypes.h"
#include "limits.h"
#include "rt_nonfinite.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(obstacleStopper_M) == (NULL));
while (runModel) {
sem_wait(&baserateTaskSem);
obstacleStopper_step();
// Get model outputs here
stopRequested = !((rtmGetErrorStatus(obstacleStopper_M) == (NULL)));
runModel = !stopRequested;
}
runModel = 0;
terminateTask(arg);
pthread_exit((void *)0);
return NULL;
}
void exitFcn(int sig)
{
UNUSED(sig);
rtmSetErrorStatus(obstacleStopper_M, "stopping the model");
}
void *terminateTask(void *arg)
{
UNUSED(arg);
terminatingmodel = 1;
{
runModel = 0;
}
// Disable rt_OneStep() here
// Terminate model
obstacleStopper_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(obstacleStopper_M, 0);
// Initialize model
obstacleStopper_initialize();
// Call RTOS Initialization function
myRTOSInit(0.02, 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;
}
//
// File trailer for generated code.
//
// [EOF]
//