/*
 * dsp_ts_sim.c 
 *
 * DSP Blockset helper function.
 *
 * Check input/output port sample time information. 
 *
 * NOTE: This is a query on the port sample time information. Therefore, 
 * the information must already be set for the port.
 *
 *
 * Copyright (c) 1995-1999 The MathWorks, Inc. All Rights Reserved.
 * $Revision: 1.7 $ $Date: 2000/03/16 03:17:16 $
 */

#include "dsp_ts_sim.h"

/*--------------------------------------------------------------*/
/* BLOCK: SAMPLE TIME INHERITED
 */
boolean_T isBlockTsInherited(SimStruct *S, int_T sti) {
  return((boolean_T)(ssGetSampleTime(S,sti) == INHERITED_SAMPLE_TIME));
}


/*--------------------------------------------------------------*/
/* BLOCK: CONTINUOUS SAMPLE TIME
 * Includes continuous (0) and variable sample times (-2). 
 */
boolean_T isBlockContinuous(SimStruct *S, int_T sti) {
  return((boolean_T)(!isBlockTsInherited(S, sti) && (ssGetSampleTime(S,sti) <= CONTINUOUS_SAMPLE_TIME)));
}

/*--------------------------------------------------------------*/
/* BLOCK: DISCRETE SAMPLE TIME
 */
boolean_T isBlockDiscrete(SimStruct *S, int_T sti) {
  return((boolean_T)(!isBlockTsInherited(S, sti) && (ssGetSampleTime(S,sti) > CONTINUOUS_SAMPLE_TIME)));
}

/*--------------------------------------------------------------*/
/* PORT-BASED:
 */
boolean_T areAllInputPortsDiscreteSampleTime(SimStruct *S) {
    boolean_T      retVal     = true;
    const int_T    numInPorts = ssGetNumInputPorts(S);
    register int_T i;

    for (i=0; i<numInPorts; i++) {
        /* Only set return value false if input samp time IS NOT discrete */
        if (ssGetInputPortSampleTime(S, i) <= CONTINUOUS_SAMPLE_TIME) {
            retVal = false;
            break; /* EARLY BREAK OUT OF LOOP */
        }
    }
    return(retVal);
}

boolean_T areAllInputPortsContOrConstSampleTime(SimStruct *S) {
    boolean_T      retVal     = true;
    const int_T    numInPorts = ssGetNumInputPorts(S);
    register int_T i;

    for (i=0; i<numInPorts; i++) {
        /* Only set return value false if input samp time IS discrete */
        if (ssGetInputPortSampleTime(S, i) > CONTINUOUS_SAMPLE_TIME) {
            retVal = false;
            break; /* EARLY BREAK OUT OF LOOP */
        }
    }
    return(retVal);
}

boolean_T areAllInputPortsSameBehaviorSampleTime(SimStruct *S) {
    if ( areAllInputPortsDiscreteSampleTime(S) )
        return(true);
    else if ( areAllInputPortsContOrConstSampleTime(S) )
        return(true);
    else
        return(false);
}

/*--------------------------------------------------------------*/
/* OFFSET
 */


/* [EOF] dsp_ts_sim.c */
