File: ert_main.c

    1   /*
    2    * File: ert_main.c
    3    *
    4    * Code generated for Simulink model 'CONTROL_SYS'.
    5    *
    6    * Model version                  : 1.379
    7    * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
    8    * C/C++ source code generated on : Thu Dec 22 12:00:05 2016
    9    *
   10    * Target selection: ert.tlc
   11    * Embedded hardware selection: Intel->x86-64 (Windows64)
   12    * Code generation objectives:
   13    *    1. Traceability
   14    *    2. Execution efficiency
   15    *    3. ROM efficiency
   16    *    4. RAM efficiency
   17    * Validation result: Not run
   18    */
   19   
   20   #include <stddef.h>
   21   #include <stdio.h>                     /* This ert_main.c example uses printf/fflush */
   22   #include "CONTROL_SYS.h"               /* Model's header file */
   23   #include "rtwtypes.h"
   24   
   25   static RT_MODEL_CONTROL_SYS_T CONTROL_SYS_M_;
   26   static RT_MODEL_CONTROL_SYS_T *const CONTROL_SYS_M = &CONTROL_SYS_M_;/* Real-time model */
   27   static B_CONTROL_SYS_T CONTROL_SYS_B;  /* Observable signals */
   28   static DW_CONTROL_SYS_T CONTROL_SYS_DW;/* Observable states */
   29   
   30   /* '<Root>/MEAS_BUS' */
   31   static THE_MEAS_BUS CONTROL_SYS_U_MEAS_BUS;
   32   
   33   /* '<Root>/Ze_cmd' */
   34   static real_T CONTROL_SYS_U_Ze_cmd;
   35   
   36   /* '<Root>/XY_cmd' */
   37   static real_T CONTROL_SYS_U_XY_cmd[2];
   38   
   39   /* '<Root>/YAW_cmd' */
   40   static real_T CONTROL_SYS_U_YAW_cmd;
   41   
   42   /* '<Root>/w_mot_UN' */
   43   static real_T CONTROL_SYS_U_w_mot_UN[4];
   44   
   45   /* '<Root>/VOLTS' */
   46   static real_T CONTROL_SYS_Y_VOLTS[4];
   47   
   48   /* '<Root>/FM_CMD_VEC' */
   49   static real_T CONTROL_SYS_Y_FM_CMD_VEC[4];
   50   
   51   /*
   52    * Associating rt_OneStep with a real-time clock or interrupt service routine
   53    * is what makes the generated code "real-time".  The function rt_OneStep is
   54    * always associated with the base rate of the model.  Subrates are managed
   55    * by the base rate from inside the generated code.  Enabling/disabling
   56    * interrupts and floating point context switches are target specific.  This
   57    * example code indicates where these should take place relative to executing
   58    * the generated code step function.  Overrun behavior should be tailored to
   59    * your application needs.  This example simply sets an error status in the
   60    * real-time model and returns from rt_OneStep.
   61    */
   62   void rt_OneStep(RT_MODEL_CONTROL_SYS_T *const CONTROL_SYS_M);
   63   void rt_OneStep(RT_MODEL_CONTROL_SYS_T *const CONTROL_SYS_M)
   64   {
   65     static boolean_T OverrunFlag = false;
   66   
   67     /* Disable interrupts here */
   68   
   69     /* Check for overrun */
   70     if (OverrunFlag) {
   71       rtmSetErrorStatus(CONTROL_SYS_M, "Overrun");
   72       return;
   73     }
   74   
   75     OverrunFlag = true;
   76   
   77     /* Save FPU context here (if necessary) */
   78     /* Re-enable timer or interrupt here */
   79     /* Set model inputs here */
   80   
   81     /* Step the model */
   82     CONTROL_SYS_step(CONTROL_SYS_M, &CONTROL_SYS_U_MEAS_BUS, CONTROL_SYS_U_Ze_cmd,
   83                      CONTROL_SYS_U_XY_cmd, CONTROL_SYS_U_YAW_cmd,
   84                      CONTROL_SYS_U_w_mot_UN, CONTROL_SYS_Y_VOLTS,
   85                      CONTROL_SYS_Y_FM_CMD_VEC);
   86   
   87     /* Get model outputs here */
   88   
   89     /* Indicate task complete */
   90     OverrunFlag = false;
   91   
   92     /* Disable interrupts here */
   93     /* Restore FPU context here (if necessary) */
   94     /* Enable interrupts here */
   95   }
   96   
   97   /*
   98    * The example "main" function illustrates what is required by your
   99    * application code to initialize, execute, and terminate the generated code.
  100    * Attaching rt_OneStep to a real-time clock is target specific.  This example
  101    * illustrates how you do this relative to initializing the model.
  102    */
  103   int_T main(int_T argc, const char *argv[])
  104   {
  105     /* Unused arguments */
  106     (void)(argc);
  107     (void)(argv);
  108   
  109     /* Pack model data into RTM */
  110     CONTROL_SYS_M->blockIO = &CONTROL_SYS_B;
  111     CONTROL_SYS_M->dwork = &CONTROL_SYS_DW;
  112   
  113     /* Initialize model */
  114     CONTROL_SYS_initialize(CONTROL_SYS_M, &CONTROL_SYS_U_MEAS_BUS,
  115       &CONTROL_SYS_U_Ze_cmd, CONTROL_SYS_U_XY_cmd, &CONTROL_SYS_U_YAW_cmd,
  116       CONTROL_SYS_U_w_mot_UN, CONTROL_SYS_Y_VOLTS, CONTROL_SYS_Y_FM_CMD_VEC);
  117   
  118     /* Attach rt_OneStep to a timer or interrupt service routine with
  119      * period 0.02 seconds (the model's base sample time) here.  The
  120      * call syntax for rt_OneStep is
  121      *
  122      *  rt_OneStep(CONTROL_SYS_M);
  123      */
  124     printf("Warning: The simulation will run forever. "
  125            "Generated ERT main won't simulate model step behavior. "
  126            "To change this behavior select the 'MAT-file logging' option.\n");
  127     fflush((NULL));
  128     while (rtmGetErrorStatus(CONTROL_SYS_M) == (NULL)) {
  129       /*  Perform other application tasks here */
  130     }
  131   
  132     /* Disable rt_OneStep() here */
  133   
  134     /* Terminate model */
  135     CONTROL_SYS_terminate(CONTROL_SYS_M);
  136     return 0;
  137   }
  138   
  139   /*
  140    * File trailer for generated code.
  141    *
  142    * [EOF]
  143    */
  144