⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vdpmult_msf.c

📁 《MATLAB7.0_Simulink6.0建模仿真开发与高级工程应用》书中程序
💻 C
字号:
#if !defined(S_FUNCTION_NAME)
#define S_FUNCTION_NAME                 vdpmult_msf
#endif
#define S_FUNCTION_LEVEL                2

#if !defined(RTW_GENERATED_S_FUNCTION)
#define RTW_GENERATED_S_FUNCTION
#endif

#include <stdio.h>
#include <math.h>
#include "simstruc.h"
#include "fixedpoint.h"
#include "rt_nonfinite.h"

#define rt_logging_h
#include "vdpmult_types.h"

#include "vdpmult.h"

#include "vdpmult_private.h"

static void mdlInitializeSizes(SimStruct *S)
{

  ssSetNumSFcnParams(S, 0);

  ssSetRTWGeneratedSFcn(S, 2);

  ssSetNumContStates(S, 0);
  ssSetNumDiscStates(S, 0);

  if (!ssSetNumInputPorts(S, 2)) return;

  if(!ssSetInputPortVectorDimension(S, 0, 1)) return;
  ssSetInputPortFrameData(S, 0, FRAME_NO);
  if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
    ssSetInputPortDataType(S, 0, SS_DOUBLE);
  }

  ssSetInputPortDirectFeedThrough(S, 0, 1);
  ssSetInputPortRequiredContiguous(S, 0, 1);
  ssSetInputPortOptimOpts(S, 0, SS_NOT_REUSABLE_AND_GLOBAL);
  ssSetInputPortOverWritable(S, 0, false);

  ssSetInputPortSampleTime(S, 0, 0.0);
  ssSetInputPortOffsetTime(S, 0, 0.0);

  if(!ssSetInputPortVectorDimension(S, 1, 1)) return;
  ssSetInputPortFrameData(S, 1, FRAME_NO);
  if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
    ssSetInputPortDataType(S, 1, SS_DOUBLE);
  }

  ssSetInputPortDirectFeedThrough(S, 1, 1);
  ssSetInputPortRequiredContiguous(S, 1, 1);
  ssSetInputPortOptimOpts(S, 1, SS_NOT_REUSABLE_AND_GLOBAL);
  ssSetInputPortOverWritable(S, 1, false);

  ssSetInputPortSampleTime(S, 1, 0.0);
  ssSetInputPortOffsetTime(S, 1, 0.0);

  if (!ssSetNumOutputPorts(S, 1)) return;

  if(!ssSetOutputPortVectorDimension(S, 0, 1)) return;

  ssSetOutputPortFrameData(S, 0, FRAME_NO);

  if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) {
    ssSetOutputPortDataType(S, 0, SS_DOUBLE);
  }

  ssSetOutputPortSampleTime(S, 0, 0.0);
  ssSetOutputPortOffsetTime(S, 0, 0.0);

  ssSetOutputPortOkToMerge(S, 0, SS_OK_TO_MERGE);

  ssSetOutputPortOptimOpts(S, 0, SS_NOT_REUSABLE_AND_GLOBAL);

  if ( !ssSetNumDWork(S, 1)) {
    return;
  }
#if SS_SFCN_FOR_SIM
  {
    int id = ssRegisterDataType(S, "vdpmult_sfcnDWork");
    if (id == INVALID_DTYPE_ID ) return;

    if(!ssSetDataTypeSize(S, id, sizeof(vdpmult_sfcnDWork))) return;
    ssSetDWorkDataType(S, 0, id);
    ssSetDWorkWidth(S, 0, 1);
  }
#endif

  {
    
    static ssRTWStorageType storageClass[3] = {SS_RTW_STORAGE_AUTO,
      SS_RTW_STORAGE_AUTO, SS_RTW_STORAGE_AUTO};
    ssSetModelRefPortRTWStorageClasses(S, storageClass);
  }

  ssSetNumSampleTimes(S, PORT_BASED_SAMPLE_TIMES);
  ssSetNumRWork(S, 0);
  ssSetNumIWork(S, 0);
  ssSetNumPWork(S, 0);
  ssSetNumModes(S, 0);
  ssSetNumNonsampledZCs(S, 0);

  {
    static const char* toFileNames[] = {""};
    static const char* fromFileNames[] = {""};
    ssSetModelRefFromFiles(S, 0,fromFileNames);
    ssSetModelRefToFiles(S, 0,toFileNames);
  }

  ssSetNeedLocalAbsoluteTime(S, 0,"");

  ssSetModelReferenceSampleTimeInheritanceRule(S,
   DISALLOW_SAMPLE_TIME_INHERITANCE);
  ssSetOptimizeModelRefInitCode(S, 0);

  ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE |
   SS_OPTION_DISALLOW_CONSTANT_SAMPLE_TIME |
   SS_OPTION_SUPPORTS_ALIAS_DATA_TYPES |
   SS_OPTION_WORKS_WITH_CODE_REUSE );
  if(!ssSetModelRefFileName(S, "vdpmult")) return;
}

static void mdlInitializeSampleTimes(SimStruct *S)
{

}

#define MDL_SET_INPUT_PORT_SAMPLE_TIME
#if defined(MATLAB_MEX_FILE)

static void mdlSetInputPortSampleTime(SimStruct *S,int_T portIdx,real_T
 sampleTime,real_T offsetTime)
{

  int i;

  for(i = 0; i < 2; ++i) {
    ssSetInputPortSampleTime(S,i,sampleTime);
    ssSetInputPortOffsetTime(S,i,offsetTime);
  }

  for(i = 0; i < 1; ++i) {
    if(ssGetOutputPortSampleTime(S,i) == mxGetInf() &&
     ssGetOutputPortOffsetTime(S,i) == 0.0) {
      
      continue;
    }
    ssSetOutputPortSampleTime(S,i,sampleTime);
    ssSetOutputPortOffsetTime(S,i,offsetTime);
  }
}
#endif

#define MDL_SET_OUTPUT_PORT_SAMPLE_TIME
#if defined(MATLAB_MEX_FILE)

static void mdlSetOutputPortSampleTime(SimStruct *S,int_T portIdx,real_T
 sampleTime,real_T offsetTime)
{

  int i;

  for(i = 0; i < 2; ++i) {
    ssSetInputPortSampleTime(S,i,sampleTime);
    ssSetInputPortOffsetTime(S,i,offsetTime);
  }

  for(i = 0; i < 1; ++i) {
    if(ssGetOutputPortSampleTime(S,i) == mxGetInf() &&
     ssGetOutputPortOffsetTime(S,i) == 0.0) {
      
      continue;
    }
    ssSetOutputPortSampleTime(S,i,sampleTime);
    ssSetOutputPortOffsetTime(S,i,offsetTime);
  }
}
#endif

#define MDL_SET_WORK_WIDTHS

static void mdlSetWorkWidths(SimStruct *S)
{

  if (S->mdlInfo->genericFcn != NULL) {
    ssRegModelRefMdlInfo(S, "vdpmult", rtMdlInfo_vdpmult, rtNumMdlInfo_vdpmult);

    {
      ModelRefChildModelInfo childModels[1] = {
        "vdpmult","vdpmult",0};
      ssRegModelRefChildModel(S,1,childModels);
    }
  }
}

#define MDL_START

static void mdlStart(SimStruct *S)
{
  vdpmult_sfcnDWork *dw = (vdpmult_sfcnDWork *) ssGetDWork(S, 0);

  mr_vdpmult_initialize(S, ssGetSampleTimeTaskID(S, 0), &(dw->rtm));
  
  ssSetModelMappingInfoPtr(S, &(dw->rtm.DataMapInfo.mmi));

  if (S->mdlInfo->genericFcn != NULL) {
    real_T fixedStep = 0.4;
    real_T startTime = 0.0;
    real_T stopTime = 20.0;
    int_T hwSettings[8];
    real_T lifeSpan = -1;
    _GenericFcn fcn = S->mdlInfo->genericFcn;

    boolean_T hasDiscTs = 0;
    (fcn)(S, GEN_FCN_CHK_MODELREF_SOLVER_TYPE, 2, &hasDiscTs);
    (fcn)(S, GEN_FCN_CHK_MODELREF_SOLVER_NAME, -1, "FixedStepDiscrete");
    (fcn)(S, GEN_FCN_CHK_MODELREF_SOLVER_MODE, SOLVER_MODE_SINGLETASKING, NULL);
    (fcn)(S, GEN_FCN_CHK_MODELREF_FIXED_STEP, -1, &fixedStep);
    (fcn)(S, GEN_FCN_CHK_MODELREF_START_TIME, -1, &startTime);
    (fcn)(S, GEN_FCN_CHK_MODELREF_STOP_TIME, -1, &stopTime);
    hwSettings[0] = 8;
    hwSettings[1] = 16;
    hwSettings[2] = 32;
    hwSettings[3] = 32;

    hwSettings[4] = 2;
    hwSettings[5] = 0;
    hwSettings[6] = 32;
    hwSettings[7] = 1;
    (fcn)(S, GEN_FCN_CHK_MODELREF_HARDWARE_SETTINGS, 8, hwSettings);
    (fcn)(S, GEN_FCN_CHK_MODELREF_LIFE_SPAN, -1, &lifeSpan);
  }
}

static void mdlOutputs(SimStruct *S, int_T tid)
{
  const real_T *InPort_0 = (real_T *) ssGetInputPortSignal(S, 0);
  const real_T *InPort_1 = (real_T *) ssGetInputPortSignal(S, 1);
  real_T *OutPort_0 = (real_T *) ssGetOutputPortSignal(S, 0);
  vdpmult_sfcnDWork *dw = (vdpmult_sfcnDWork *) ssGetDWork(S, 0);

  if (tid != CONSTANT_TID) {

    mr_vdpmult(InPort_0, InPort_1, OutPort_0, &(dw->rtm));
  }
}

static void mdlTerminate(SimStruct *S)
{
  vdpmult_sfcnDWork *dw = (vdpmult_sfcnDWork *) ssGetDWork(S, 0);
}

#ifdef MATLAB_MEX_FILE
#include "simulink.c"
#include "fixedpoint.c"
#else
#include "cg_sfun.h"
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -