forked from xtdrone/XTDrone
119 lines
2.6 KiB
C++
119 lines
2.6 KiB
C++
//
|
|
// 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]
|
|
//
|