/* Copyright 1994-2004 The MathWorks, Inc. * $Revision: 1.18.2.4 $ * $Date: 2004/07/24 23:37:27 $ * * File : sfix_udelay.c * * Abstract: * S-function for Fixed Point Data Type * UNIT DELAY */ /*=====================================* * Required setup for C MEX S-Function * *=====================================*/ #define S_FUNCTION_NAME sfix_target_specific #define S_FUNCTION_LEVEL 2 /* * Need to include simstruc.h for the definition of the SimStruct and * its associated macro definitions. */ #include "package.h" #include "fixpoint.h" #include "fix_sfun_defines.h" extern void hostcpuinfo(double yp[]); /*========================* * General Defines/macros * *========================*/ /* Function: mdlInitializeSizes =============================================== * Abstract: * Initialize the sizes array */ static void mdlInitializeSizes(SimStruct *S) { /* * Set and Check parameter count */ ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) return; /* * set sizes */ if ( !ssSetNumOutputPorts( S, 4) ) return; if ( !ssSetNumInputPorts( S, 0) ) return; /* if ( ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY ) */ { /* * outputs */ ssSetOutputPortWidth( S, 0, 1 ); ssSetOutputPortReusable(S, 0, TRUE); ssSetOutputPortWidth( S, 1, 1 ); ssSetOutputPortReusable(S, 1, TRUE); ssSetOutputPortWidth( S, 2, 1 ); ssSetOutputPortReusable(S, 1, TRUE); ssSetOutputPortWidth( S, 3, 4 ); ssSetOutputPortReusable(S, 2, TRUE); /* * sample times */ ssSetNumSampleTimes( S, 1 ); /* * options */ ssSetOptions( S, ( SS_OPTION_COMMON_TO_ALL_FIXPT ) ); } } /* end mdlInitializeSizes */ /* Function: mdlInitializeSampleTimes ========================================= * Abstract: * Initialize the sample times array. */ static void mdlInitializeSampleTimes(SimStruct *S) { /* * set sample time */ ssSetSampleTime(S, 0, 0.0 ); ssSetOffsetTime(S, 0, FIXED_IN_MINOR_STEP_OFFSET ); ssSetModelReferenceSampleTimeDefaultInheritance(S); } /* end mdlInitializeSampleTimes */ /* Function: ======================================================= * */ static int double2int(double r) { return ((int)r); } /* Function: mdlOutputs ======================================================= * Abstract: * Compute the outputs of the S-function. */ static void mdlOutputs(SimStruct *S, int_T tid) { real_T *y; double cpu_info[7]; /* hostcpuinfo returns an array of doubles containing information about the * host cpu. This information is dynamically calculated, so should be * host independant. The array contains the following information: * * element # Value/descrtiption * 0 Shift right behavior * 0 == logical * 1 == arithmetic * 1 Signed Integer division rounding * 1 == round toward floor * 2 == round toward 0 * 3 == undefined rounding behavior * 2 Byte ordering * 0 == Little Endian * 1 == Big Endian * 3 Number of bits per char * 4 Number of bits per short * 5 Number of bits per int * 6 Number of bits per long */ hostcpuinfo(cpu_info); /* shifts right on signed integers */ y = (real_T *)ssGetOutputPortSignal(S,0); y[0] = cpu_info[0]; /* negative operand integer division rounding */ y = (real_T *)ssGetOutputPortSignal(S,1); y[0] = cpu_info[1]; /* Byte ordering */ y = (real_T *)ssGetOutputPortSignal(S,2); y[0] = cpu_info[2]; /* bits per char, short, int, long */ y = (real_T *)ssGetOutputPortSignal(S,3); y[0] = cpu_info[3]; y[1] = cpu_info[4]; y[2] = cpu_info[5]; y[3] = cpu_info[6]; } /* end mdlOutputs */ /* Function: mdlTerminate ===================================================== * Abstract: * Called when the simulation is terminated. */ PRIVATE void mdlTerminate(SimStruct *S) { } /* end mdlTerminate */ /* Function: mdlRTW =========================================================== * Abstract: * RTW function. Write parameters and parameter settings: */ #define MDL_RTW PRIVATE void mdlRTW(SimStruct *S) { } /* end mdlRTW */ /*=======================================* * Required closing for C MEX S-Function * *=======================================*/ #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */ # include "simulink.c" /* MEX-file interface mechanism */ #else # include "cg_sfun.h" /* Code generation registration function */ #endif /* [EOF] sfix_target_specific.c */