www.pudn.com > communicationmatlab.rar > SIMBI2DE.C
/*
* simbi2de binary to decimal conversion for SIMULINK block
*
* Syntax: [sys, x0] = simbi2de(t,x,u,flag,p)
* where p is the calculation base.
* Wes Wang 6/14/94
* Copyright (c) 1994-96 The MathWorks, Inc.
* All Rights Reserved
* $Revision: 1.1 $ $Date: 1996/04/01 19:04:24 $
*/
/* specify the name of this S-Function. */
#define S_FUNCTION_NAME simbi2de
/* Defines for easy access the matrices which are passed in */
#define NUM_ARGS 1
#define CAL_BASE ssGetArg(S, 0)
#include "simstruc.h"
/*
* mdlInitializeSizes - initialize the sizes array
*/
static void mdlInitializeSizes (S)
SimStruct *S;
{
ssSetNumContStates( S, 0); /* number of continuous states */
ssSetNumDiscStates( S, 0); /* number of discrete states */
ssSetNumInputs ( S, -1); /* number of inputs */
ssSetNumOutputs ( S, 1); /* number of outputs */
ssSetDirectFeedThrough(S, 1); /* direct feedthrough flag */
ssSetNumSampleTimes( S, 1); /* number of sample times */
ssSetNumInputArgs( S, NUM_ARGS);/* number of input arguments */
ssSetNumRWork( S, 0); /* number of real work vector elements */
ssSetNumIWork( S, 0); /* number of integer work vector elements */
ssSetNumPWork( S, 0); /* number of pointer work vector elements */
}
/*
* mdlInitializeSampleTimes - initialize the sample times array
*
* This function is used to specify the sample time(s) for your S-function.
* If your S-function is continuous, you must specify a sample time of 0.0.
* Sample times must be registered in ascending order.
*/
static void mdlInitializeSampleTimes(S)
SimStruct *S;
{
ssSetSampleTimeEvent(S, 0, 0.0);
ssSetOffsetTimeEvent(S, 0, 0.0);
}
/*
* mdlInitializeConditions - initialize the states
* Initialize the states, Integers and real-numbers
*/
static void mdlInitializeConditions(x0, S)
double *x0;
SimStruct *S;
{
}
/*
* mdlOutputs - compute the outputs
*
* In this function, you compute the outputs of your S-function
* block. The outputs are placed in the y variable.
*/
static void mdlOutputs(y, x, u, S, tid)
double *y, *x, *u;
SimStruct *S;
int tid;
{
long inSize, i, pow, p;
inSize = (int)ssGetNumInputs(S);
p = (int)mxGetPr(CAL_BASE)[0];
if (p < 2)
p = 2;
y[0] = 0;
pow = 1;
for (i=0; i