/*
 * ECPDSPResetmdl.c
 *
 * Real-Time Workshop code generation for Simulink model "ECPDSPResetmdl.mdl".
 *
 * Model Version              : 1.18
 * Real-Time Workshop version : 7.1  (R2008a)  23-Jan-2008
 * C source code generated on : Fri Sep 04 09:18:31 2009
 */

#include "ECPDSPResetmdl.h"
#include "ECPDSPResetmdl_private.h"
#include <stdio.h>
#include "ECPDSPResetmdl_dt.h"

/* Block signals (auto storage) */
BlockIO_ECPDSPResetmdl ECPDSPResetmdl_B;

/* Real-time model */
RT_MODEL_ECPDSPResetmdl ECPDSPResetmdl_M_;
RT_MODEL_ECPDSPResetmdl *ECPDSPResetmdl_M = &ECPDSPResetmdl_M_;

/* Model output function */
void ECPDSPResetmdl_output(int_T tid)
{
  /* Level2 S-Function Block: '<S1>/S-Function' (ECPDSPReset) */
  {
    SimStruct *rts = ECPDSPResetmdl_M->childSfunctions[0];
    sfcnOutputs(rts, 0);
  }

  UNUSED_PARAMETER(tid);
}

/* Model update function */
void ECPDSPResetmdl_update(int_T tid)
{
  /* Update absolute time for base rate */
  if (!(++ECPDSPResetmdl_M->Timing.clockTick0))
    ++ECPDSPResetmdl_M->Timing.clockTickH0;
  ECPDSPResetmdl_M->Timing.t[0] = ECPDSPResetmdl_M->Timing.clockTick0 *
    ECPDSPResetmdl_M->Timing.stepSize0 + ECPDSPResetmdl_M->Timing.clockTickH0 *
    ECPDSPResetmdl_M->Timing.stepSize0 * 4294967296.0;
  UNUSED_PARAMETER(tid);
}

/* Model initialize function */
void ECPDSPResetmdl_initialize(boolean_T firstTime)
{
  (void)firstTime;

  /* Registration code */

  /* initialize non-finites */
  rt_InitInfAndNaN(sizeof(real_T));

  /* initialize real-time model */
  (void) memset((char_T *)ECPDSPResetmdl_M,0,
                sizeof(RT_MODEL_ECPDSPResetmdl));
  rtsiSetSolverName(&ECPDSPResetmdl_M->solverInfo,"FixedStepDiscrete");
  ECPDSPResetmdl_M->solverInfoPtr = (&ECPDSPResetmdl_M->solverInfo);

  /* Initialize timing info */
  {
    int_T *mdlTsMap = ECPDSPResetmdl_M->Timing.sampleTimeTaskIDArray;
    mdlTsMap[0] = 0;
    ECPDSPResetmdl_M->Timing.sampleTimeTaskIDPtr = (&mdlTsMap[0]);
    ECPDSPResetmdl_M->Timing.sampleTimes =
      (&ECPDSPResetmdl_M->Timing.sampleTimesArray[0]);
    ECPDSPResetmdl_M->Timing.offsetTimes =
      (&ECPDSPResetmdl_M->Timing.offsetTimesArray[0]);

    /* task periods */
    ECPDSPResetmdl_M->Timing.sampleTimes[0] = (0.001);

    /* task offsets */
    ECPDSPResetmdl_M->Timing.offsetTimes[0] = (0.0);
  }

  rtmSetTPtr(ECPDSPResetmdl_M, &ECPDSPResetmdl_M->Timing.tArray[0]);

  {
    int_T *mdlSampleHits = ECPDSPResetmdl_M->Timing.sampleHitArray;
    mdlSampleHits[0] = 1;
    ECPDSPResetmdl_M->Timing.sampleHits = (&mdlSampleHits[0]);
  }

  rtmSetTFinal(ECPDSPResetmdl_M, 1.0);
  ECPDSPResetmdl_M->Timing.stepSize0 = 0.001;

  /* external mode info */
  ECPDSPResetmdl_M->Sizes.checksums[0] = (276956918U);
  ECPDSPResetmdl_M->Sizes.checksums[1] = (419181661U);
  ECPDSPResetmdl_M->Sizes.checksums[2] = (3017051442U);
  ECPDSPResetmdl_M->Sizes.checksums[3] = (2375396542U);

  {
    static const sysRanDType rtAlwaysEnabled = SUBSYS_RAN_BC_ENABLE;
    static RTWExtModeInfo rt_ExtModeInfo;
    static const sysRanDType *systemRan[1];
    ECPDSPResetmdl_M->extModeInfo = (&rt_ExtModeInfo);
    rteiSetSubSystemActiveVectorAddresses(&rt_ExtModeInfo, systemRan);
    systemRan[0] = &rtAlwaysEnabled;
    rteiSetModelMappingInfoPtr(&rt_ExtModeInfo,
      &ECPDSPResetmdl_M->SpecialInfo.mappingInfo);
    rteiSetChecksumsPtr(&rt_ExtModeInfo, ECPDSPResetmdl_M->Sizes.checksums);
    rteiSetTPtr(&rt_ExtModeInfo, rtmGetTPtr(ECPDSPResetmdl_M));
  }

  ECPDSPResetmdl_M->solverInfoPtr = (&ECPDSPResetmdl_M->solverInfo);
  ECPDSPResetmdl_M->Timing.stepSize = (0.001);
  rtsiSetFixedStepSize(&ECPDSPResetmdl_M->solverInfo, 0.001);
  rtsiSetSolverMode(&ECPDSPResetmdl_M->solverInfo, SOLVER_MODE_SINGLETASKING);

  /* block I/O */
  ECPDSPResetmdl_M->ModelData.blockIO = ((void *) &ECPDSPResetmdl_B);

  {
    ((real_T*)&ECPDSPResetmdl_B.SFunction)[0] = 0.0;
  }

  /* parameters */
  ECPDSPResetmdl_M->ModelData.defaultParam = ((real_T *) &ECPDSPResetmdl_P);

  /* data type transition information */
  {
    static DataTypeTransInfo dtInfo;
    (void) memset((char_T *) &dtInfo,0,
                  sizeof(dtInfo));
    ECPDSPResetmdl_M->SpecialInfo.mappingInfo = (&dtInfo);
    dtInfo.numDataTypes = 14;
    dtInfo.dataTypeSizes = &rtDataTypeSizes[0];
    dtInfo.dataTypeNames = &rtDataTypeNames[0];

    /* Block I/O transition table */
    dtInfo.B = &rtBTransTable;

    /* Parameters transition table */
    dtInfo.P = &rtPTransTable;
  }

  /* child S-Function registration */
  {
    RTWSfcnInfo *sfcnInfo = &ECPDSPResetmdl_M->NonInlinedSFcns.sfcnInfo;
    ECPDSPResetmdl_M->sfcnInfo = (sfcnInfo);
    rtssSetErrorStatusPtr(sfcnInfo, (&rtmGetErrorStatus(ECPDSPResetmdl_M)));
    rtssSetNumRootSampTimesPtr(sfcnInfo, &ECPDSPResetmdl_M->Sizes.numSampTimes);
    rtssSetTPtrPtr(sfcnInfo, &rtmGetTPtr(ECPDSPResetmdl_M));
    rtssSetTStartPtr(sfcnInfo, &rtmGetTStart(ECPDSPResetmdl_M));
    rtssSetTFinalPtr(sfcnInfo, &rtmGetTFinal(ECPDSPResetmdl_M));
    rtssSetTimeOfLastOutputPtr(sfcnInfo, &rtmGetTimeOfLastOutput
      (ECPDSPResetmdl_M));
    rtssSetStepSizePtr(sfcnInfo, &ECPDSPResetmdl_M->Timing.stepSize);
    rtssSetStopRequestedPtr(sfcnInfo, &rtmGetStopRequested(ECPDSPResetmdl_M));
    rtssSetDerivCacheNeedsResetPtr(sfcnInfo,
      &ECPDSPResetmdl_M->ModelData.derivCacheNeedsReset);
    rtssSetZCCacheNeedsResetPtr(sfcnInfo,
      &ECPDSPResetmdl_M->ModelData.zCCacheNeedsReset);
    rtssSetBlkStateChangePtr(sfcnInfo,
      &ECPDSPResetmdl_M->ModelData.blkStateChange);
    rtssSetSampleHitsPtr(sfcnInfo, &ECPDSPResetmdl_M->Timing.sampleHits);
    rtssSetPerTaskSampleHitsPtr(sfcnInfo,
      &ECPDSPResetmdl_M->Timing.perTaskSampleHits);
    rtssSetSimModePtr(sfcnInfo, &ECPDSPResetmdl_M->simMode);
    rtssSetSolverInfoPtr(sfcnInfo, &ECPDSPResetmdl_M->solverInfoPtr);
  }

  ECPDSPResetmdl_M->Sizes.numSFcns = (1);

  /* register each child */
  {
    (void) memset((void *)&ECPDSPResetmdl_M->NonInlinedSFcns.childSFunctions[0],
                  0,
                  1*sizeof(SimStruct));
    ECPDSPResetmdl_M->childSfunctions =
      (&ECPDSPResetmdl_M->NonInlinedSFcns.childSFunctionPtrs[0]);
    ECPDSPResetmdl_M->childSfunctions[0] =
      (&ECPDSPResetmdl_M->NonInlinedSFcns.childSFunctions[0]);

    /* Level2 S-Function Block: ECPDSPResetmdl/<S1>/S-Function (ECPDSPReset) */
    {
      SimStruct *rts = ECPDSPResetmdl_M->childSfunctions[0];

      /* timing info */
      time_T *sfcnPeriod = ECPDSPResetmdl_M->NonInlinedSFcns.Sfcn0.sfcnPeriod;
      time_T *sfcnOffset = ECPDSPResetmdl_M->NonInlinedSFcns.Sfcn0.sfcnOffset;
      int_T *sfcnTsMap = ECPDSPResetmdl_M->NonInlinedSFcns.Sfcn0.sfcnTsMap;
      (void) memset((void*)sfcnPeriod,0,
                    sizeof(time_T)*1);
      (void) memset((void*)sfcnOffset,0,
                    sizeof(time_T)*1);
      ssSetSampleTimePtr(rts, &sfcnPeriod[0]);
      ssSetOffsetTimePtr(rts, &sfcnOffset[0]);
      ssSetSampleTimeTaskIDPtr(rts, sfcnTsMap);

      /* Set up the mdlInfo pointer */
      {
        ssSetBlkInfo2Ptr(rts, &ECPDSPResetmdl_M->NonInlinedSFcns.blkInfo2[0]);
        ssSetRTWSfcnInfo(rts, ECPDSPResetmdl_M->sfcnInfo);
      }

      /* Allocate memory of model methods 2 */
      {
        ssSetModelMethods2(rts, &ECPDSPResetmdl_M->NonInlinedSFcns.methods2[0]);
      }

      /* inputs */
      {
        _ssSetNumInputPorts(rts, 1);
        ssSetPortInfoForInputs(rts,
          &ECPDSPResetmdl_M->NonInlinedSFcns.Sfcn0.inputPortInfo[0]);

        /* port 0 */
        {
          real_T const **sfcnUPtrs = (real_T const **)
            &ECPDSPResetmdl_M->NonInlinedSFcns.Sfcn0.UPtrs0;
          sfcnUPtrs[0] = &ECPDSPResetmdl_P.Add1_Value;
          ssSetInputPortSignalPtrs(rts, 0, (InputPtrsType)&sfcnUPtrs[0]);
          _ssSetInputPortNumDimensions(rts, 0, 1);
          ssSetInputPortWidth(rts, 0, 1);
        }
      }

      /* outputs */
      {
        ssSetPortInfoForOutputs(rts,
          &ECPDSPResetmdl_M->NonInlinedSFcns.Sfcn0.outputPortInfo[0]);
        _ssSetNumOutputPorts(rts, 1);

        /* port 0 */
        {
          _ssSetOutputPortNumDimensions(rts, 0, 1);
          ssSetOutputPortWidth(rts, 0, 1);
          ssSetOutputPortSignal(rts, 0, ((real_T *) &ECPDSPResetmdl_B.SFunction));
        }
      }

      /* path info */
      ssSetModelName(rts, "S-Function");
      ssSetPath(rts, "ECPDSPResetmdl/ECPDSP Reset/S-Function");
      ssSetRTModel(rts,ECPDSPResetmdl_M);
      ssSetParentSS(rts, NULL);
      ssSetRootSS(rts, rts);
      ssSetVersion(rts, SIMSTRUCT_VERSION_LEVEL2);

      /* parameters */
      {
        mxArray **sfcnParams = (mxArray **)
          &ECPDSPResetmdl_M->NonInlinedSFcns.Sfcn0.params;
        ssSetSFcnParamsCount(rts, 4);
        ssSetSFcnParamsPtr(rts, &sfcnParams[0]);
        ssSetSFcnParam(rts, 0, (mxArray*)&ECPDSPResetmdl_P.SFunction_P1_Size[0]);
        ssSetSFcnParam(rts, 1, (mxArray*)&ECPDSPResetmdl_P.SFunction_P2_Size[0]);
        ssSetSFcnParam(rts, 2, (mxArray*)&ECPDSPResetmdl_P.SFunction_P3_Size[0]);
        ssSetSFcnParam(rts, 3, (mxArray*)&ECPDSPResetmdl_P.SFunction_P4_Size[0]);
      }

      /* registration */
      ECPDSPReset(rts);
      sfcnInitializeSizes(rts);
      sfcnInitializeSampleTimes(rts);

      /* adjust sample time */
      ssSetSampleTime(rts, 0, 0.001);
      ssSetOffsetTime(rts, 0, 0.0);
      sfcnTsMap[0] = 0;

      /* set compiled values of dynamic vector attributes */
      ssSetNumNonsampledZCs(rts, 0);

      /* Update connectivity flags for each port */
      _ssSetInputPortConnected(rts, 0, 1);
      _ssSetOutputPortConnected(rts, 0, 1);
      _ssSetOutputPortBeingMerged(rts, 0, 0);

      /* Update the BufferDstPort flags for each input port */
      ssSetInputPortBufferDstPort(rts, 0, -1);
    }
  }
}

/* Model terminate function */
void ECPDSPResetmdl_terminate(void)
{
  /* Level2 S-Function Block: '<S1>/S-Function' (ECPDSPReset) */
  {
    SimStruct *rts = ECPDSPResetmdl_M->childSfunctions[0];
    sfcnTerminate(rts);
  }

  /* External mode */
  rtExtModeShutdown(1);
}

/*========================================================================*
 * Start of GRT compatible call interface                                 *
 *========================================================================*/
void MdlOutputs(int_T tid)
{
  ECPDSPResetmdl_output(tid);
}

void MdlUpdate(int_T tid)
{
  ECPDSPResetmdl_update(tid);
}

void MdlInitializeSizes(void)
{
  ECPDSPResetmdl_M->Sizes.numContStates = (0);/* Number of continuous states */
  ECPDSPResetmdl_M->Sizes.numY = (0);  /* Number of model outputs */
  ECPDSPResetmdl_M->Sizes.numU = (0);  /* Number of model inputs */
  ECPDSPResetmdl_M->Sizes.sysDirFeedThru = (0);/* The model is not direct feedthrough */
  ECPDSPResetmdl_M->Sizes.numSampTimes = (1);/* Number of sample times */
  ECPDSPResetmdl_M->Sizes.numBlocks = (3);/* Number of blocks */
  ECPDSPResetmdl_M->Sizes.numBlockIO = (1);/* Number of block outputs */
  ECPDSPResetmdl_M->Sizes.numBlockPrms = (18);/* Sum of parameter "widths" */
}

void MdlInitializeSampleTimes(void)
{
}

void MdlInitialize(void)
{
}

void MdlStart(void)
{
  /* Level2 S-Function Block: '<S1>/S-Function' (ECPDSPReset) */
  {
    SimStruct *rts = ECPDSPResetmdl_M->childSfunctions[0];
    sfcnStart(rts);
    if (ssGetErrorStatus(rts) != NULL)
      return;
  }

  MdlInitialize();
}

RT_MODEL_ECPDSPResetmdl *ECPDSPResetmdl(void)
{
  ECPDSPResetmdl_initialize(1);
  return ECPDSPResetmdl_M;
}

void MdlTerminate(void)
{
  ECPDSPResetmdl_terminate();
}

/*========================================================================*
 * End of GRT compatible call interface                                   *
 *========================================================================*/
