image thumbnail
from Code Coverage Tool by Mark Walker
Code Coverage Tool measures C statement coverage in generated code.

controller_model_sf_c.html
RTW Report - controller_model_sf.c

File: c:\projects\cov\tst9a\controller_model_ert_rtw\controller_model_sf.c

    1   /*
    2    * controller_model_sf.c
    3    *
    4    * This file contains a "wrapper style S-Function" for testing the generated
    5    * code from Simulink.  Simulink invokes the generated code through its
    6    * S-Function API.  Note that this file is not required for deployment
    7    * of the generated code outside of Simulink.
    8    *
    9    * Real-Time Workshop code generation for Simulink model "controller_model.mdl".
   10    *
   11    * Model Version              : 1.79
   12    * Real-Time Workshop version : 7.2  (R2008b)  04-Aug-2008
   13    * C source code generated on : Thu May 14 12:41:14 2009
   14    *
   15    */
   16   
   17   #if !defined(S_FUNCTION_NAME)
   18   #define S_FUNCTION_NAME                controller_model_sf
   19   #endif
   20   
   21   #define S_FUNCTION_LEVEL               2
   22   
   23   /* So mdlEnable and mdlDisable will be defined in the simstruc.h */
   24   #if !defined(RTW_GENERATED_S_FUNCTION)
   25   #define RTW_GENERATED_S_FUNCTION
   26   #endif
   27   
   28   #include <stdio.h>
   29   #include <math.h>
   30   #include "simstruc.h"
   31   #include "fixedpoint.h"
   32   #define rt_logging_h
   33   #define RTWSfcnInfo                    void *
   34   #include "controller_model.h"
   35   
   36   static int8_T controller_model_sf_counter = 0;
   37   
   38   /* Function: mdlInitializeSizes ===============================================
   39    * Abstract:
   40    *   This function registers the input and output signal properties of the
   41    *   generated ERT code.
   42    */
   43   static void mdlInitializeSizes(SimStruct *S)
   44   {
   45     /* Tunable Parameters */
   46     ssSetNumSFcnParams(S, 0);
   47     ssFxpSetU32BitRegionCompliant(S, 1);
   48   
   49     /* Number of expected parameters */
   50     if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
   51   
   52   #if defined(MDL_CHECK_PARAMETERS)
   53   
   54       mdlCheckParameters(S);
   55   
   56   #endif                                 /* MDL_CHECK_PARAMETERS */
   57   
   58       if (ssGetErrorStatus(S) != (NULL)) {
   59         return;
   60       }
   61     } else {
   62       return;                            /* Parameter mismatch will be reported by Simulink */
   63     }
   64   
   65     ssSetNumContStates(S, 0);
   66     ssSetNumDiscStates(S, 0);
   67     ssSetRTWGeneratedSFcn(S, 3);
   68   
   69     /* Number of input ports */
   70     if (!ssSetNumInputPorts(S, 1))
   71       return;
   72     if (!ssSetInputPortVectorDimension(S, 0, 1))
   73       return;
   74     ssSetInputPortBusMode(S, 0, SL_NON_BUS_MODE);
   75     if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
   76       ssSetInputPortDataType(S, 0, SS_UINT8);
   77     }
   78   
   79     ssSetBusInputAsStruct(S, 0, 1);
   80     ssSetInputPortDirectFeedThrough(S, 0, 1);
   81     ssSetInputPortSampleTime(S, 0, 1.0);
   82     ssSetInputPortOffsetTime(S, 0, 0.0);
   83   
   84     /* Number of output ports */
   85     if (!ssSetNumOutputPorts(S, 1))
   86       return;
   87     if (!ssSetOutputPortVectorDimension(S, 0, 1))
   88       return;
   89     ssSetOutputPortBusMode(S, 0, SL_NON_BUS_MODE);
   90     if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
   91       ssSetOutputPortDataType(S, 0, SS_UINT8);
   92     }
   93   
   94     ssSetOutputPortSampleTime(S, 0, 1.0);
   95     ssSetOutputPortOffsetTime(S, 0, 0.0);
   96   
   97     /* Number of sample-times */
   98     ssSetNumSampleTimes(S, 1);
   99     ssSetNumRWork(S, 0);
  100     ssSetNumIWork(S, 0);
  101     ssSetNumPWork(S, 0);
  102     ssSetNumModes(S, 0);
  103     ssSetNumNonsampledZCs(S, 0);
  104   
  105     /* ERT S-Function works with model reference normal mode */
  106     ssSetModelReferenceNormalModeSupport(S, MDL_START_AND_MDL_PROCESS_PARAMS_OK);
  107   
  108     /* exception free code */
  109     ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE
  110                  );
  111   
  112     /* input and output ports are already assigned */
  113     /* ssSetOptions(S, SS_OPTION_PORT_SAMPLE_TIMES_ASSIGNED); */
  114   }
  115   
  116   /* Function: mdlInitializeSampleTimes =========================================
  117    * Abstract:
  118    *    This function registers the sample times of the generated ERT code.
  119    */
  120   static void mdlInitializeSampleTimes(SimStruct *S)
  121   {
  122     ssSetSampleTime(S, 0, 1.0);
  123     ssSetOffsetTime(S, 0, 0.0);
  124   }
  125   
  126   #define MDL_INITIALIZE_CONDITIONS
  127   
  128   /* Function: mdlInitializeConditions ==========================================
  129    * Abstract:
  130    *   This function calls the initialization function of the generated ERT
  131    *   code.
  132    */
  133   static void mdlInitializeConditions(SimStruct *S)
  134   {
  135   
  136   #ifdef PIL_S_FUNCTION
  137   
  138     pilMarshallInitSFcnSimStruct(S);
  139     pilMarshallInitRootSimStruct(ssGetRootSS(S));
  140   
  141   #endif
  142   
  143     controller_model_initialize(1);
  144   }
  145   
  146   #define MDL_START                                                /* Change to #undef to remove function */
  147   #if defined(MDL_START)
  148   
  149   /* Function: mdlStart =========================================================
  150    * Abstract:
  151    *
  152    */
  153   static void mdlStart(SimStruct *S)
  154   {
  155     /* check if more than one instance of this S-Function has been used */
  156     if (++controller_model_sf_counter > 1) {
  157       ssSetErrorStatus(S,"This S-Function is limited to one copy per model.");
  158       controller_model_sf_counter = 0;
  159       return;
  160     }
  161   
  162     /* check if parent model's start time is the same as that used to generate code */
  163     if (ssGetTStart(S) != 0.0) {
  164       ssSetErrorStatus(S,
  165                        "The parent model of this S-Function must set the value of the 'Start time' on the Solver page of its Configuration Parameters Dialog to 0.0 since that was the value used when generating code for the S-Function's original model.");
  166       return;
  167     }
  168   }
  169   
  170   #endif                                 /*  MDL_START */
  171   
  172   /* Function: mdlOutputs =======================================================
  173    * Abstract:
  174    *   This function calls the step function of the generated ERT code
  175    *   and provides an interface with the simulation data.
  176    */
  177   static void mdlOutputs(SimStruct *S, int_T tid)
  178   {
  179     InputUInt8PtrsType InPort_0 = (InputUInt8PtrsType) ssGetInputPortSignalPtrs(S,
  180       0);
  181     uint8_T *OutPort_0 = (uint8_T *)ssGetOutputPortSignal(S, 0);
  182     controller_model_U.In1 = InPort_0[0][0];
  183     controller_model_step();
  184     OutPort_0[0] = result;
  185   }
  186   
  187   /* Function: mdlTerminate =====================================================
  188    * Abstract:
  189    *   This function calls the termination function of the generated ERT code.
  190    */
  191   static void mdlTerminate(SimStruct *S)
  192   {
  193     controller_model_terminate();
  194     controller_model_sf_counter = 0;
  195   }
  196   
  197   #define MDL_ENABLE
  198   
  199   /* Function: mdlEnable =================================================
  200    *
  201    */
  202   static void mdlEnable(SimStruct *S)
  203   {
  204     (void) S;
  205   }
  206   
  207   #define MDL_DISABLE
  208   
  209   /* Function: mdlDisable =================================================
  210    *
  211    */
  212   static void mdlDisable(SimStruct *S)
  213   {
  214     (void) S;
  215   }
  216   
  217   #ifdef MATLAB_MEX_FILE                 /* Is this file being compiled as a MEX-file? */
  218   #include "simulink.c"                  /* MEX-file interface mechanism */
  219   #include "fixedpoint.c"
  220   #else
  221   #include "cg_sfun.h"                   /* Code generation registration function */
  222   #endif

Contact us at files@mathworks.com