File: ert_main.c

    1   /*
    2    * File: ert_main.c
    3    *
    4    * Code generated for Simulink model 'bh_f14'.
    5    *
    6    * Model version                  : 1.18
    7    * Simulink Coder version         : 8.10 (R2016a) 10-Feb-2016
    8    * C/C++ source code generated on : Wed Jun 22 07:56:08 2016
    9    *
   10    * Target selection: ert.tlc
   11    * Embedded hardware selection: 32-bit Generic
   12    * Code generation objectives: Unspecified
   13    * Validation result: Not run
   14    */
   15   
   16   #include <stddef.h>
   17   #include <stdio.h>                     /* This ert_main.c example uses printf/fflush */
   18   #include "bh_f14.h"                    /* Model's header file */
   19   #include "rtwtypes.h"
   20   
   21   static RT_MODEL_bh_f14_T bh_f14_M_;
   22   static RT_MODEL_bh_f14_T *const bh_f14_M = &bh_f14_M_;/* Real-time model */
   23   static B_bh_f14_T bh_f14_B;            /* Observable signals */
   24   static DW_bh_f14_T bh_f14_DW;          /* Observable states */
   25   static X_bh_f14_T bh_f14_X;            /* Observable continuous states */
   26   
   27   /* '<Root>/u' */
   28   static real_T bh_f14_U_u;
   29   
   30   /* '<Root>/alpha (rad)' */
   31   static real_T bh_f14_Y_alpharad;
   32   
   33   /* '<Root>/Nz Pilot (g)' */
   34   static real_T bh_f14_Y_NzPilotg;
   35   
   36   /*
   37    * Associating rt_OneStep with a real-time clock or interrupt service routine
   38    * is what makes the generated code "real-time".  The function rt_OneStep is
   39    * always associated with the base rate of the model.  Subrates are managed
   40    * by the base rate from inside the generated code.  Enabling/disabling
   41    * interrupts and floating point context switches are target specific.  This
   42    * example code indicates where these should take place relative to executing
   43    * the generated code step function.  Overrun behavior should be tailored to
   44    * your application needs.  This example simply sets an error status in the
   45    * real-time model and returns from rt_OneStep.
   46    */
   47   void rt_OneStep(RT_MODEL_bh_f14_T *const bh_f14_M);
   48   void rt_OneStep(RT_MODEL_bh_f14_T *const bh_f14_M)
   49   {
   50     static boolean_T OverrunFlag = false;
   51   
   52     /* Disable interrupts here */
   53   
   54     /* Check for overrun */
   55     if (OverrunFlag) {
   56       rtmSetErrorStatus(bh_f14_M, "Overrun");
   57       return;
   58     }
   59   
   60     OverrunFlag = true;
   61   
   62     /* Save FPU context here (if necessary) */
   63     /* Re-enable timer or interrupt here */
   64     /* Set model inputs here */
   65   
   66     /* Step the model for base rate */
   67     bh_f14_step(bh_f14_M, bh_f14_U_u, &bh_f14_Y_alpharad, &bh_f14_Y_NzPilotg);
   68   
   69     /* Get model outputs here */
   70   
   71     /* Indicate task complete */
   72     OverrunFlag = false;
   73   
   74     /* Disable interrupts here */
   75     /* Restore FPU context here (if necessary) */
   76     /* Enable interrupts here */
   77   }
   78   
   79   /*
   80    * The example "main" function illustrates what is required by your
   81    * application code to initialize, execute, and terminate the generated code.
   82    * Attaching rt_OneStep to a real-time clock is target specific.  This example
   83    * illustrates how you do this relative to initializing the model.
   84    */
   85   int_T main(int_T argc, const char *argv[])
   86   {
   87     /* Unused arguments */
   88     (void)(argc);
   89     (void)(argv);
   90   
   91     /* Pack model data into RTM */
   92     bh_f14_M->ModelData.blockIO = &bh_f14_B;
   93     bh_f14_M->ModelData.dwork = &bh_f14_DW;
   94     bh_f14_M->ModelData.contStates = &bh_f14_X;
   95   
   96     /* Initialize model */
   97     bh_f14_initialize(bh_f14_M, &bh_f14_U_u, &bh_f14_Y_alpharad,
   98                       &bh_f14_Y_NzPilotg);
   99   
  100     /* Simulating the model step behavior (in non real-time) to
  101      *  simulate model behavior at stop time.
  102      */
  103     while ((rtmGetErrorStatus(bh_f14_M) == (NULL)) && !rtmGetStopRequested
  104            (bh_f14_M)) {
  105       rt_OneStep(bh_f14_M);
  106     }
  107   
  108     /* Disable rt_OneStep() here */
  109   
  110     /* Terminate model */
  111     bh_f14_terminate(bh_f14_M);
  112     return 0;
  113   }
  114   
  115   /*
  116    * File trailer for generated code.
  117    *
  118    * [EOF]
  119    */
  120