1 | /* |
2 | * Academic License - for use in teaching, academic research, and meeting |
3 | * course requirements at degree granting institutions only. Not for |
4 | * government, commercial, or other organizational use. |
5 | * |
6 | * File: ert_main.c |
7 | * |
8 | * Code generated for Simulink model 'integ_accel'. |
9 | * |
10 | * Model version : 1.6 |
11 | * Simulink Coder version : 8.12 (R2017a) 16-Feb-2017 |
12 | * C/C++ source code generated on : Tue Dec 05 15:11:10 2017 |
13 | * |
14 | * Target selection: ert.tlc |
15 | * Embedded hardware selection: ARM Compatible->ARM Cortex |
16 | * Code generation objectives: Unspecified |
17 | * Validation result: Not run |
18 | */ |
19 | |
20 | #include "integ_accel.h" |
21 | #include "integ_accel_private.h" |
22 | #include "rtwtypes.h" |
23 | #include "limits.h" |
24 | #include "board.h" |
25 | #include "mw_cmsis_rtos.h" |
26 | #define UNUSED(x) x = x |
27 | #define EXIT_ON_ERROR(msg, cond) if (cond) { return(0); } |
28 | |
29 | extern const char *TgtConnInit(int_T argc, char_T *argv[]); |
30 | extern void TgtConnTerm(); |
31 | extern void TgtConnPreStep(int_T tid); |
32 | extern void TgtConnPostStep(int_T tid); |
33 | const char * csErrorStatus; |
34 | |
35 | /* Function prototype declaration*/ |
36 | void exitFcn(int sig); |
37 | void *terminateTask(void *arg); |
38 | void *baseRateTask(void *arg); |
39 | void *subrateTask(void *arg); |
40 | volatile boolean_T runModel = true; |
41 | mw_signal_event_t stopSem; |
42 | mw_signal_event_t baserateTaskSem; |
43 | mw_thread_t schedulerThread; |
44 | mw_thread_t baseRateThread; |
45 | mw_thread_t backgroundThread; |
46 | unsigned long threadJoinStatus[8]; |
47 | int terminatingmodel = 0; |
48 | void *baseRateTask(void *arg) |
49 | { |
50 | runModel = (rtmGetErrorStatus(integ_accel_M) == (NULL)) && |
51 | !rtmGetStopRequested(integ_accel_M); |
52 | while (runModel) { |
53 | mw_osSignalEventWaitEver(&baserateTaskSem); |
54 | |
55 | /* External mode */ |
56 | { |
57 | boolean_T rtmStopReq = false; |
58 | rtExtModePauseIfNeeded(integ_accel_M->extModeInfo, 3, &rtmStopReq); |
59 | if (rtmStopReq) { |
60 | rtmSetStopRequested(integ_accel_M, true); |
61 | } |
62 | |
63 | if (rtmGetStopRequested(integ_accel_M) == true) { |
64 | rtmSetErrorStatus(integ_accel_M, "Simulation finished"); |
65 | break; |
66 | } |
67 | } |
68 | |
69 | integ_accel_step(); |
70 | |
71 | /* Get model outputs here */ |
72 | rtExtModeCheckEndTrigger(); |
73 | runModel = (rtmGetErrorStatus(integ_accel_M) == (NULL)) && |
74 | !rtmGetStopRequested(integ_accel_M); |
75 | } |
76 | |
77 | runModel = 0; |
78 | terminateTask(arg); |
79 | mw_osThreadExit((void *)0); |
80 | return NULL; |
81 | } |
82 | |
83 | void exitFcn(int sig) |
84 | { |
85 | UNUSED(sig); |
86 | rtmSetErrorStatus(integ_accel_M, "stopping the model"); |
87 | } |
88 | |
89 | void *terminateTask(void *arg) |
90 | { |
91 | UNUSED(arg); |
92 | terminatingmodel = 1; |
93 | |
94 | { |
95 | runModel = 0; |
96 | |
97 | /* Wait for background task to complete */ |
98 | CHECK_STATUS(mw_osThreadJoin(backgroundThread,(void *)&threadJoinStatus), 0, |
99 | "mw_osThreadJoin"); |
100 | } |
101 | |
102 | rtExtModeShutdown(3); |
103 | TgtConnTerm(); |
104 | |
105 | /* Disable rt_OneStep() here */ |
106 | |
107 | /* Terminate model */ |
108 | integ_accel_terminate(); |
109 | mw_osSignalEventRelease(&stopSem); |
110 | return NULL; |
111 | } |
112 | |
113 | void backgroundTask(void *arg) |
114 | { |
115 | while (runModel) { |
116 | /* External mode */ |
117 | { |
118 | boolean_T rtmStopReq = false; |
119 | rtExtModeOneStep(integ_accel_M->extModeInfo, 3, &rtmStopReq); |
120 | if (rtmStopReq) { |
121 | rtmSetStopRequested(integ_accel_M, true); |
122 | } |
123 | } |
124 | |
125 | runCommService(); |
126 | } |
127 | } |
128 | |
129 | int main(int argc, char **argv) |
130 | { |
131 | SystemCoreClockUpdate(); |
132 | hardware_init(); |
133 | rtmSetErrorStatus(integ_accel_M, 0); |
134 | rtExtModeParseArgs(argc, (const char_T **)argv, NULL); |
135 | |
136 | /* Initialize model */ |
137 | integ_accel_initialize(); |
138 | |
139 | /* Target connectivity initialization */ |
140 | csErrorStatus = TgtConnInit(argc, argv); |
141 | EXIT_ON_ERROR("Error initializing target connectivity: %s\n", csErrorStatus); |
142 | |
143 | /* External mode */ |
144 | rtSetTFinalForExtMode(&rtmGetTFinal(integ_accel_M)); |
145 | rtExtModeCheckInit(3); |
146 | |
147 | { |
148 | boolean_T rtmStopReq = false; |
149 | rtExtModeWaitForStartPkt(integ_accel_M->extModeInfo, 3, &rtmStopReq); |
150 | if (rtmStopReq) { |
151 | rtmSetStopRequested(integ_accel_M, true); |
152 | } |
153 | } |
154 | |
155 | rtERTExtModeStartMsg(); |
156 | |
157 | /* Call RTOS Initialization function */ |
158 | mw_RTOSInit(0.001, 0); |
159 | |
160 | /* Wait for stop semaphore */ |
161 | mw_osSignalEventWaitEver(&stopSem); |
162 | return 0; |
163 | } |
164 | |
165 | /* |
166 | * File trailer for generated code. |
167 | * |
168 | * [EOF] |
169 | */ |
170 | |