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_and_Gyro'.
9 *
10 * Model version : 1.7
11 * Simulink Coder version : 8.12 (R2017a) 16-Feb-2017
12 * C/C++ source code generated on : Tue Dec 05 15:47:02 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_and_Gyro.h"
21#include "integ_Accel_and_Gyro_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
29extern const char *TgtConnInit(int_T argc, char_T *argv[]);
30extern void TgtConnTerm();
31extern void TgtConnPreStep(int_T tid);
32extern void TgtConnPostStep(int_T tid);
33const char * csErrorStatus;
34
35/* Function prototype declaration*/
36void exitFcn(int sig);
37void *terminateTask(void *arg);
38void *baseRateTask(void *arg);
39void *subrateTask(void *arg);
40volatile boolean_T runModel = true;
41mw_signal_event_t stopSem;
42mw_signal_event_t baserateTaskSem;
43mw_thread_t schedulerThread;
44mw_thread_t baseRateThread;
45mw_thread_t backgroundThread;
46unsigned long threadJoinStatus[8];
47int terminatingmodel = 0;
48void *baseRateTask(void *arg)
49{
50 runModel = (rtmGetErrorStatus(integ_Accel_and_Gyro_M) == (NULL)) &&
51 !rtmGetStopRequested(integ_Accel_and_Gyro_M);
52 while (runModel) {
53 mw_osSignalEventWaitEver(&baserateTaskSem);
54
55 /* External mode */
56 {
57 boolean_T rtmStopReq = false;
58 rtExtModePauseIfNeeded(integ_Accel_and_Gyro_M->extModeInfo, 3, &rtmStopReq);
59 if (rtmStopReq) {
60 rtmSetStopRequested(integ_Accel_and_Gyro_M, true);
61 }
62
63 if (rtmGetStopRequested(integ_Accel_and_Gyro_M) == true) {
64 rtmSetErrorStatus(integ_Accel_and_Gyro_M, "Simulation finished");
65 break;
66 }
67 }
68
69 integ_Accel_and_Gyro_step();
70
71 /* Get model outputs here */
72 rtExtModeCheckEndTrigger();
73 runModel = (rtmGetErrorStatus(integ_Accel_and_Gyro_M) == (NULL)) &&
74 !rtmGetStopRequested(integ_Accel_and_Gyro_M);
75 }
76
77 runModel = 0;
78 terminateTask(arg);
79 mw_osThreadExit((void *)0);
80 return NULL;
81}
82
83void exitFcn(int sig)
84{
85 UNUSED(sig);
86 rtmSetErrorStatus(integ_Accel_and_Gyro_M, "stopping the model");
87}
88
89void *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_and_Gyro_terminate();
109 mw_osSignalEventRelease(&stopSem);
110 return NULL;
111}
112
113void backgroundTask(void *arg)
114{
115 while (runModel) {
116 /* External mode */
117 {
118 boolean_T rtmStopReq = false;
119 rtExtModeOneStep(integ_Accel_and_Gyro_M->extModeInfo, 3, &rtmStopReq);
120 if (rtmStopReq) {
121 rtmSetStopRequested(integ_Accel_and_Gyro_M, true);
122 }
123 }
124
125 runCommService();
126 }
127}
128
129int main(int argc, char **argv)
130{
131 SystemCoreClockUpdate();
132 hardware_init();
133 rtmSetErrorStatus(integ_Accel_and_Gyro_M, 0);
134 rtExtModeParseArgs(argc, (const char_T **)argv, NULL);
135
136 /* Initialize model */
137 integ_Accel_and_Gyro_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_and_Gyro_M));
145 rtExtModeCheckInit(3);
146
147 {
148 boolean_T rtmStopReq = false;
149 rtExtModeWaitForStartPkt(integ_Accel_and_Gyro_M->extModeInfo, 3, &rtmStopReq);
150 if (rtmStopReq) {
151 rtmSetStopRequested(integ_Accel_and_Gyro_M, true);
152 }
153 }
154
155 rtERTExtModeStartMsg();
156
157 /* Call RTOS Initialization function */
158 mw_RTOSInit(0.05, 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