103 lines
2.9 KiB
C++
103 lines
2.9 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 'Arduino_skal'.
|
||
|
//
|
||
|
// Model version : 1.1
|
||
|
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
||
|
// C/C++ source code generated on : Thu Apr 15 22:06:00 2021
|
||
|
//
|
||
|
// Target selection: ert.tlc
|
||
|
// Embedded hardware selection: AMD->x86-64 (Windows64)
|
||
|
// Code generation objectives:
|
||
|
// 1. Execution efficiency
|
||
|
// 2. RAM efficiency
|
||
|
// Validation result: Not run
|
||
|
//
|
||
|
#include <stddef.h>
|
||
|
#include <stdio.h> // This ert_main.c example uses printf/fflush
|
||
|
#include "Arduino_skal.h" // Model's header file
|
||
|
#include "rtwtypes.h"
|
||
|
|
||
|
static Arduino_skalModelClass rtObj; // Instance of model class
|
||
|
|
||
|
//
|
||
|
// Associating rt_OneStep with a real-time clock or interrupt service routine
|
||
|
// is what makes the generated code "real-time". The function rt_OneStep is
|
||
|
// always associated with the base rate of the model. Subrates are managed
|
||
|
// by the base rate from inside the generated code. Enabling/disabling
|
||
|
// interrupts and floating point context switches are target specific. This
|
||
|
// example code indicates where these should take place relative to executing
|
||
|
// the generated code step function. Overrun behavior should be tailored to
|
||
|
// your application needs. This example simply sets an error status in the
|
||
|
// real-time model and returns from rt_OneStep.
|
||
|
//
|
||
|
void rt_OneStep(void);
|
||
|
void rt_OneStep(void)
|
||
|
{
|
||
|
static boolean_T OverrunFlag = false;
|
||
|
|
||
|
// Disable interrupts here
|
||
|
|
||
|
// Check for overrun
|
||
|
if (OverrunFlag) {
|
||
|
rtmSetErrorStatus(rtObj.getRTM(), "Overrun");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
OverrunFlag = true;
|
||
|
|
||
|
// Save FPU context here (if necessary)
|
||
|
// Re-enable timer or interrupt here
|
||
|
// Set model inputs here
|
||
|
|
||
|
// Step the model for base rate
|
||
|
rtObj.step();
|
||
|
|
||
|
// Get model outputs here
|
||
|
|
||
|
// Indicate task complete
|
||
|
OverrunFlag = false;
|
||
|
|
||
|
// Disable interrupts here
|
||
|
// Restore FPU context here (if necessary)
|
||
|
// Enable interrupts here
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// The example "main" function illustrates what is required by your
|
||
|
// application code to initialize, execute, and terminate the generated code.
|
||
|
// Attaching rt_OneStep to a real-time clock is target specific. This example
|
||
|
// illustrates how you do this relative to initializing the model.
|
||
|
//
|
||
|
int_T main(int_T argc, const char *argv[])
|
||
|
{
|
||
|
// Unused arguments
|
||
|
(void)(argc);
|
||
|
(void)(argv);
|
||
|
|
||
|
// Initialize model
|
||
|
rtObj.initialize();
|
||
|
|
||
|
// Simulating the model step behavior (in non real-time) to
|
||
|
// simulate model behavior at stop time.
|
||
|
|
||
|
while ((rtmGetErrorStatus(rtObj.getRTM()) == (NULL)) && !rtmGetStopRequested
|
||
|
(rtObj.getRTM())) {
|
||
|
rt_OneStep();
|
||
|
}
|
||
|
|
||
|
// Disable rt_OneStep() here
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// File trailer for generated code.
|
||
|
//
|
||
|
// [EOF]
|
||
|
//
|