File: C:\MATLAB6p5\work\atomicdemo_ert_rtw/ert_main.c

    1   /*
    2    * Auto generated example main program for model: atomicdemo
    3    *
    4    * Real-Time Workshop file version      : 5.0 $Date: 2002/05/30 19:21:33 $
    5    * Real-Time Workshop file generated on : Wed Mar 24 14:33:27 2004
    6    * C source code generated on           : Wed Mar 24 14:33:27 2004
    7    *
    8    * Description:
    9    *   Real-Time Workshop Embedded Coder example single rate main assuming
   10    *   no operating system.
   11    *
   12    * For more information:
   13    *   o Real-Time Workshop User's Guide
   14    *   o Real-Time Workshop Embedded Coder User's Guide
   15    *   o matlabroot/rtw/c/ert/ert_main.c
   16    *   o Type 'ecodertutorial' in MATLAB
   17    *
   18    * For a real-time operating system deployment example, reconfigure the
   19    * "Target operating system" option to "VxWorksExample".
   20    */
   21   
   22   #include <stdio.h>                      /* This ert_main.c example uses printf/fflush */
   23   #include "tmwtypes.h"                   /* MathWorks types */
   24   #include "simstruc_types.h"             /* Simulink types */
   25   #include "atomicdemo.h"                 /* Model's header file */
   26   
   27   static boolean_T OverrunFlag = 0;
   28   
   29   /* Associating rt_OneStep with a real-time clock or interrupt service routine
   30    * is what makes the generated code "real-time".  The function rt_OneStep is
   31    * always associated with the base rate of the model.  Subrates are managed
   32    * by the base rate from inside the generated code.  Enabling/disabling
   33    * interrupts and floating point context switches are target specific.  This
   34    * example code indicates where these should take place relative to executing
   35    * the generated code step function.  Overrun behavior should be tailored to
   36    * your application needs.  This example simply sets an error status in the
   37    * real-time model and returns from rt_OneStep.
   38    */
   39   void rt_OneStep(void)
   40   {
   41     /* Disable interrupts here */
   42   
   43     /* Check for overun */
   44     if (OverrunFlag++) {
   45       rtmSetErrorStatus(rtM, "Overrun");
   46       return;
   47     }
   48   
   49     /* Save FPU context here (if necessary) */
   50     /* Re-enable timer or interrupt here */
   51     /* Set model inputs here */
   52   
   53     atomicdemo_step();
   54   
   55     /* Get model outputs here */
   56   
   57     OverrunFlag--;
   58   
   59     /* Disable interrupts here */
   60     /* Restore FPU context here (if necessary) */
   61     /* Enable interrupts here */
   62   }
   63   
   64   /* The example "main" function illustrates what is required by your
   65    * application code to initialize, execute, and terminate the generated code.
   66    * Attaching rt_OneStep to a real-time clock is target specific.  This example
   67    * illustates how you do this relative to initializing the model.
   68    */
   69   int_T main(int_T argc, const char_T *argv[])
   70   {
   71   
   72     printf("Warning: The simulation will run forever. "
   73      "To change this behavior select the 'MAT-file logging' option.\n");
   74     fflush(NULL);
   75   
   76     /* Initialize model */
   77     atomicdemo_initialize(1);
   78   
   79     /* Attach rt_OneStep to a timer or interrupt service routine with
   80      * period 1.0 seconds (the model's base sample time) here.  The
   81      * call syntax for rt_OneStep is 
   82      *
   83      * rt_OneStep();
   84      */
   85   
   86     while (rtmGetErrorStatus(rtM) == NULL) {
   87       /* Perform other application tasks here */
   88     }
   89     return 0;
   90   }
   91