1 | /* |
2 | * File: ert_main.c |
3 | * |
4 | * Code generated for Simulink model 'sensorsharp'. |
5 | * |
6 | * Model version : 1.47 |
7 | * Simulink Coder version : 8.12 (R2017a) 16-Feb-2017 |
8 | * C/C++ source code generated on : Tue Jun 18 18:54:30 2019 |
9 | * |
10 | * Target selection: ert.tlc |
11 | * Embedded hardware selection: Atmel->AVR |
12 | * Code generation objectives: Unspecified |
13 | * Validation result: Not run |
14 | */ |
15 | |
16 | #include "sensorsharp.h" |
17 | #include "rtwtypes.h" |
18 | #include <ext_work.h> |
19 | #include <ext_svr.h> |
20 | #include <ext_share.h> |
21 | #include <updown.h> |
22 | |
23 | volatile int IsrOverrun = 0; |
24 | boolean_T isRateRunning[2] = { 0, 0 }; |
25 | |
26 | boolean_T need2runFlags[2] = { 0, 0 }; |
27 | |
28 | void rt_OneStep(void) |
29 | { |
30 | boolean_T eventFlags[2]; |
31 | |
32 | /* Check base rate for overrun */ |
33 | if (isRateRunning[0]++) { |
34 | IsrOverrun = 1; |
35 | isRateRunning[0]--; /* allow future iterations to succeed*/ |
36 | return; |
37 | } |
38 | |
39 | /* |
40 | * For a bare-board target (i.e., no operating system), the rates |
41 | * that execute this base step are buffered locally to allow for |
42 | * overlapping preemption. The generated code includes function |
43 | * writeCodeInfoFcn() which sets the rates |
44 | * that need to run this time step. The return values are 1 and 0 |
45 | * for true and false, respectively. |
46 | */ |
47 | sensorsharp_SetEventsForThisBaseStep(eventFlags); |
48 | |
49 | #ifndef _MW_ARDUINO_LOOP_ |
50 | |
51 | sei(); |
52 | |
53 | #endif; |
54 | |
55 | sensorsharp_step0(); |
56 | |
57 | /* Get model outputs here */ |
58 | #ifndef _MW_ARDUINO_LOOP_ |
59 | |
60 | cli(); |
61 | |
62 | #endif; |
63 | |
64 | isRateRunning[0]--; |
65 | if (eventFlags[1]) { |
66 | if (need2runFlags[1]++) { |
67 | IsrOverrun = 1; |
68 | need2runFlags[1]--; /* allow future iterations to succeed*/ |
69 | return; |
70 | } |
71 | } |
72 | |
73 | if (need2runFlags[1]) { |
74 | if (isRateRunning[1]) { |
75 | /* Yield to higher priority*/ |
76 | return; |
77 | } |
78 | |
79 | isRateRunning[1]++; |
80 | |
81 | #ifndef _MW_ARDUINO_LOOP_ |
82 | |
83 | sei(); |
84 | |
85 | #endif; |
86 | |
87 | /* Step the model for subrate "1" */ |
88 | switch (1) |
89 | { |
90 | case 1 : |
91 | sensorsharp_step1(); |
92 | |
93 | /* Get model outputs here */ |
94 | break; |
95 | |
96 | default : |
97 | break; |
98 | } |
99 | |
100 | #ifndef _MW_ARDUINO_LOOP_ |
101 | |
102 | cli(); |
103 | |
104 | #endif; |
105 | |
106 | need2runFlags[1]--; |
107 | isRateRunning[1]--; |
108 | } |
109 | |
110 | rtExtModeCheckEndTrigger(); |
111 | } |
112 | |
113 | int main(void) |
114 | { |
115 | volatile boolean_T runModel = 1; |
116 | float modelBaseRate = 0.002; |
117 | float systemClock = 0; |
118 | init(); |
119 | MW_Arduino_Init(); |
120 | rtmSetErrorStatus(sensorsharp_M, 0); |
121 | |
122 | /* initialize external mode */ |
123 | rtParseArgsForExtMode(0, NULL); |
124 | sensorsharp_initialize(); |
125 | sei(); |
126 | |
127 | /* External mode */ |
128 | rtSetTFinalForExtMode(&rtmGetTFinal(sensorsharp_M)); |
129 | rtExtModeCheckInit(2); |
130 | |
131 | { |
132 | boolean_T rtmStopReq = false; |
133 | rtExtModeWaitForStartPkt(sensorsharp_M->extModeInfo, 2, &rtmStopReq); |
134 | if (rtmStopReq) { |
135 | rtmSetStopRequested(sensorsharp_M, true); |
136 | } |
137 | } |
138 | |
139 | rtERTExtModeStartMsg(); |
140 | cli(); |
141 | configureArduinoAVRTimer(); |
142 | runModel = |
143 | (rtmGetErrorStatus(sensorsharp_M) == (NULL)) && !rtmGetStopRequested |
144 | (sensorsharp_M); |
145 | |
146 | #ifndef _MW_ARDUINO_LOOP_ |
147 | |
148 | sei(); |
149 | |
150 | #endif; |
151 | |
152 | sei(); |
153 | while (runModel) { |
154 | /* External mode */ |
155 | { |
156 | boolean_T rtmStopReq = false; |
157 | rtExtModeOneStep(sensorsharp_M->extModeInfo, 2, &rtmStopReq); |
158 | if (rtmStopReq) { |
159 | rtmSetStopRequested(sensorsharp_M, true); |
160 | } |
161 | } |
162 | |
163 | runModel = |
164 | (rtmGetErrorStatus(sensorsharp_M) == (NULL)) && !rtmGetStopRequested |
165 | (sensorsharp_M); |
166 | runModel = runModel && MW_Arduino_Loop(); |
167 | } |
168 | |
169 | rtExtModeShutdown(2); |
170 | |
171 | /* Disable rt_OneStep() here */ |
172 | |
173 | /* Terminate model */ |
174 | sensorsharp_terminate(); |
175 | cli(); |
176 | return 0; |
177 | } |
178 | |
179 | /* |
180 | * File trailer for generated code. |
181 | * |
182 | * [EOF] |
183 | */ |
184 | |