/*
 *  dsp_sim.c - Simulation only functions for DSP Blockset
 *
 *  Copyright 2000 The MathWorks, Inc.
 *  $Revision: 1.4 $ $Date: 2000/08/16 21:24:35 $
 */

#include "dsp_sim.h"

#if !defined(MATLAB_MEX_FILE)
#   error "dsp_sim.c should not be used for S-Functions without a corresponding TLC file."
#endif

/*
 * Intended only for use via REGISTER_SFCN_PARAMS macro - see below.
 * Returns true if no errors occurred.
 */
boolean_T registerSFunctionParams(SimStruct *S, int_T numParams)
{
    boolean_T argCountOK = (boolean_T)(numParams == ssGetSFcnParamsCount(S));

    ssSetNumSFcnParams(S, numParams);
        
    if(numParams > 0) {
        if (!argCountOK) return(false);
        
        if (ssGetmdlCheckParameters(S) != NULL) {
            /* Call mdlCheckParameters() in the S-Function */
            sfcnCheckParameters(S);
        } else {
            ssSetErrorStatus(S,"Parameters passed to S-Function, but "
                               "mdlCheckParameters not present.");
        }
        return( (boolean_T)(!ANY_ERRORS(S)) );

    } else {
        return(argCountOK);
    }
}


/*
 *  Version of calloc for Simulink S-Functions
 */
void *slCalloc(
    SimStruct *S,
    const int_T count,
    const int_T size)
    {
    void *buf = mxCalloc(count, size);
    if (buf == NULL) {
        ssSetErrorStatus(S, "Failed to allocate memory in slCalloc.");
    } else {
        mexMakeMemoryPersistent(buf);
    }
    return(buf);
}


void slFree(void *ptr)
{
    if (ptr != NULL) {
        mxFree(ptr);
    }
}

/* [EOF] dsp_sim.c */
