📄 evc.c
字号:
/*
* File: evc.c
*
*
*
* --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 2.0 ---
*
* This file is an S-function produced by the S-Function
* Builder which only recognizes certain fields. Changes made
* outside these fields will be lost the next time the block is
* used to load, edit, and resave this file. This file will be overwritten
* by the S-function Builder block. If you want to edit this file by hand,
* you must change it only in the area defined as:
*
* %%%-SFUNWIZ_defines_Changes_BEGIN
* #define NAME 'replacement text'
* %%% SFUNWIZ_defines_Changes_END
*
* DO NOT change NAME--Change the 'replacement text' only.
*
* For better compatibility with the Real-Time Workshop, the
* "wrapper" S-function technique is used. This is discussed
* in the Real-Time Workshop User's Manual in the Chapter titled,
* "Wrapper S-functions".
*
* -------------------------------------------------------------------------
* | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
* -------------------------------------------------------------------------
* Created: Thu May 5 17:25:44 2005
*
*
*/
#define S_FUNCTION_NAME evc
#define S_FUNCTION_LEVEL 2
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */
#define NUM_INPUTS 1
/* Input Port 0 */
#define IN_PORT_0_NAME signal
#define INPUT_0_WIDTH -1
#define INPUT_DIMS_0_COL 1
#define INPUT_0_DTYPE real_T
#define INPUT_0_COMPLEX COMPLEX_NO
#define IN_0_FRAME_BASED FRAME_YES
#define IN_0_DIMS 1-D
#define INPUT_0_FEEDTHROUGH 1
#define NUM_OUTPUTS 1
/* Output Port 0 */
#define OUT_PORT_0_NAME output
#define OUTPUT_0_WIDTH -1
#define OUTPUT_DIMS_0_COL 1
#define OUTPUT_0_DTYPE real_T
#define OUTPUT_0_COMPLEX COMPLEX_NO
#define OUT_0_FRAME_BASED FRAME_YES
#define OUT_0_DIMS 1-D
#define NPARAMS 2
/* Parameter 1 */
#define PARAMETER_0_NAME omig
#define PARAMETER_0_DTYPE real_T
#define PARAMETER_0_COMPLEX COMPLEX_NO
/* Parameter 2 */
#define PARAMETER_1_NAME beta
#define PARAMETER_1_DTYPE real_T
#define PARAMETER_1_COMPLEX COMPLEX_NO
#define SAMPLE_TIME_0 INHERITED_SAMPLE_TIME
#define NUM_DISC_STATES 0
#define DISC_STATES_IC [0]
#define NUM_CONT_STATES 0
#define CONT_STATES_IC [0]
#define SFUNWIZ_GENERATE_TLC 0
#define SOURCEFILES ""
#define PANELINDEX 6
#define SFUNWIZ_REVISION 2.0
/* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "simstruc.h"
#define PARAM_DEF0(S) ssGetSFcnParam(S, 0)
#define PARAM_DEF1(S) ssGetSFcnParam(S, 1)
#define IS_PARAM_DOUBLE(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) &&\
!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsDouble(pVal))
#define IS_PARAM_DOUBLE(pVal) (mxIsNumeric(pVal) && !mxIsLogical(pVal) &&\
!mxIsEmpty(pVal) && !mxIsSparse(pVal) && !mxIsComplex(pVal) && mxIsDouble(pVal))
/*
* Include Files
*
*/
#include "tmwtypes.h"
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output functions
*
*/
void evc_Outputs_wrapper(SimStruct *S,const real_T *signal,
real_T *output,
const real_T *omig, const int_T p_width0,
const real_T *beta, const int_T p_width1)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
/* This sample sets the output equal to the input
y0[0] = u0[0];
For complex signals use: y0[0].re = u0[0].re;
y0[0].im = u0[0].im;
y1[0].re = u1[0].re;
y1[0].im = u1[0].im;*/
int_T datawidth = ssGetInputPortWidth(S,0);
int_T i;
for ( i= 0 ; i < datawidth ; i++ )
{
if ( signal[i]>= -2*(*omig) && signal[i]<=2*(*omig) )
{
output[i] = signal[i] ;
}
if ( signal[i]>2*(*omig) )
{
output[i] = signal[i] * (*beta) + (1-(*beta))*2*(*omig) ;
}
if ( signal[i]<-2*(*omig))
{
output[i] = signal[i] * (*beta) - (1-(*beta))*2*(*omig) ;
}
}
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Updates function
*
*/
void evc_Update_wrapper(const real_T *signal,
const real_T *output,
const real_T *omig, const int_T p_width0,
const real_T *beta, const int_T p_width1)
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
/*
* Code example
* xD[0] = u0[0];
*/
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Derivatives function
*
*/
void evc_Derivatives_wrapper(const real_T *signal,
const real_T *output,
real_T *dx,
const real_T *omig, const int_T p_width0,
const real_T *beta, const int_T p_width1)
{
/* %%%-SFUNWIZ_wrapper_Derivatives_Changes_BEGIN --- EDIT HERE TO _END */
/*
* Code example
* dx[0] = xC[0];
*/
/* %%%-SFUNWIZ_wrapper_Derivatives_Changes_END --- EDIT HERE TO _BEGIN */
}
/*====================*
* S-function methods *
*====================*/
#define MDL_CHECK_PARAMETERS
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
/* Function: mdlCheckParameters =============================================
* Abstract:
* Validate our parameters to verify they are okay.
*/
static void mdlCheckParameters(SimStruct *S)
{
#define PrmNumPos 46
int paramIndex = 0;
bool validParam = false;
char paramVector[] ={'1','2'};
static char parameterErrorMsg[] ="The data type and/or complexity of parameter does not match the information "
"specified in the S-function Builder dialog. For non-double parameters you will need to cast them using int8, int16,"
"int32, uint8, uint16, uint32 or boolean.";
/* All parameters must match the S-function Builder Dialog */
{
const mxArray *pVal0 = ssGetSFcnParam(S,0);
if (!IS_PARAM_DOUBLE(pVal0)) {
validParam = true;
paramIndex = 0;
goto EXIT_POINT;
}
}
{
const mxArray *pVal1 = ssGetSFcnParam(S,1);
if (!IS_PARAM_DOUBLE(pVal1)) {
validParam = true;
paramIndex = 1;
goto EXIT_POINT;
}
}
EXIT_POINT:
if (validParam) {
parameterErrorMsg[PrmNumPos] = paramVector[paramIndex];
ssSetErrorStatus(S,parameterErrorMsg);
}
return;
}
#endif /* MDL_CHECK_PARAMETERS */
/* Function: mdlInitializeSizes ===============================================
* Abstract:
* Setup sizes of the various vectors.
*/
static void mdlInitializeSizes(SimStruct *S)
{
DECL_AND_INIT_DIMSINFO(inputDimsInfo);
DECL_AND_INIT_DIMSINFO(outputDimsInfo);
ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */
#if defined(MATLAB_MEX_FILE)
if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
mdlCheckParameters(S);
if (ssGetErrorStatus(S) != NULL) {
return;
}
} else {
return; /* Parameter mismatch will be reported by Simulink */
}
#endif
ssSetNumContStates(S, NUM_CONT_STATES);
ssSetNumDiscStates(S, NUM_DISC_STATES);
if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
inputDimsInfo.width = INPUT_0_WIDTH;
ssSetInputPortDimensionInfo(S, 0, &inputDimsInfo);
ssSetInputPortMatrixDimensions( S ,0, INPUT_0_WIDTH, INPUT_DIMS_0_COL);
ssSetInputPortFrameData(S, 0, IN_0_FRAME_BASED);
ssSetInputPortDataType(S, 0, SS_DOUBLE);
ssSetInputPortComplexSignal(S, 0, INPUT_0_COMPLEX);
ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/
if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
outputDimsInfo.width = OUTPUT_0_WIDTH;
ssSetOutputPortDimensionInfo(S, 0, &outputDimsInfo);
ssSetOutputPortMatrixDimensions( S ,0, OUTPUT_0_WIDTH, OUTPUT_DIMS_0_COL);
ssSetOutputPortFrameData(S, 0, OUT_0_FRAME_BASED);
ssSetOutputPortDataType(S, 0, SS_DOUBLE);
ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
/* Take care when specifying exception free code - see sfuntmpl_doc.c */
ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
SS_OPTION_USE_TLC_WITH_ACCELERATOR |
SS_OPTION_WORKS_WITH_CODE_REUSE));
}
#if defined(MATLAB_MEX_FILE)
#define MDL_SET_INPUT_PORT_DIMENSION_INFO
static void mdlSetInputPortDimensionInfo(SimStruct *S,
int_T port,
const DimsInfo_T *dimsInfo)
{
if(!ssSetInputPortDimensionInfo(S, port, dimsInfo)) return;
}
#endif
#define MDL_SET_OUTPUT_PORT_DIMENSION_INFO
#if defined(MDL_SET_OUTPUT_PORT_DIMENSION_INFO)
static void mdlSetOutputPortDimensionInfo(SimStruct *S,
int_T port,
const DimsInfo_T *dimsInfo)
{
if (!ssSetOutputPortDimensionInfo(S, port, dimsInfo)) return;
}
#endif
# define MDL_SET_INPUT_PORT_FRAME_DATA
static void mdlSetInputPortFrameData(SimStruct *S,
int_T port,
Frame_T frameData)
{
ssSetInputPortFrameData(S, port, frameData);
}
/* Function: mdlInitializeSampleTimes =========================================
* Abstract:
* Specifiy the sample time.
*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, SAMPLE_TIME_0); ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_SET_INPUT_PORT_DATA_TYPE
static void mdlSetInputPortDataType(SimStruct *S, int port, DTypeId dType)
{
ssSetInputPortDataType( S, 0, dType);
}
#define MDL_SET_OUTPUT_PORT_DATA_TYPE
static void mdlSetOutputPortDataType(SimStruct *S, int port, DTypeId dType)
{
ssSetOutputPortDataType(S, 0, dType);
}
#define MDL_SET_DEFAULT_PORT_DATA_TYPES
static void mdlSetDefaultPortDataTypes(SimStruct *S)
{
ssSetInputPortDataType( S, 0, SS_DOUBLE);
ssSetOutputPortDataType(S, 0, SS_DOUBLE);
}
/* Function: mdlOutputs =======================================================
*
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
const real_T *signal = (const real_T*) ssGetInputPortSignal(S,0);
real_T *output = (real_T *)ssGetOutputPortRealSignal(S,0);
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const int_T p_width1 = mxGetNumberOfElements(PARAM_DEF1(S));
const real_T *omig = mxGetData(PARAM_DEF0(S));
const real_T *beta = mxGetData(PARAM_DEF1(S));
evc_Outputs_wrapper(S,signal,output, omig, p_width0, beta, p_width1);
}
#undef MDL_UPDATE /* Change to #define to use the function */
#if defined(MDL_UPDATE)
/* Function: mdlUpdate ======================================================
* Abstract:
* This function is called once for every major integration time step.
* Discrete states are typically updated here, but this function is useful
* for performing any tasks that should only take place once per
* integration step.
*/
static void mdlUpdate(SimStruct *S, int_T tid)
{
const real_T *signal = (const real_T*) ssGetInputPortSignal(S,0);
real_T *xD = ssGetDiscStates(S);
real_T *output = (real_T *)ssGetOutputPortRealSignal(S,0);
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const int_T p_width1 = mxGetNumberOfElements(PARAM_DEF1(S));
const real_T *omig = mxGetData(PARAM_DEF0(S));
const real_T *beta = mxGetData(PARAM_DEF1(S));
evc_Update_wrapper(signal,output, omig, p_width0, beta, p_width1);
}
#endif /* MDL_UPDATE */
#undef MDL_DERIVATIVES /* Change to #define to use function */
#if defined(MDL_DERIVATIVES)
/* Function: mdlDerivatives =================================================
* Abstract:
* In this function, you compute the S-function block's derivatives.
* The derivatives are placed in the derivative vector, ssGetdX(S).
*/
static void mdlDerivatives(SimStruct *S)
{
const real_T *signal = (const real_T*) ssGetInputPortSignal(S,0);
real_T *dx = ssGetdX(S);
real_T *xC = ssGetContStates(S);
real_T *output = (real_T *) ssGetOutputPortRealSignal(S,0);
const int_T p_width0 = mxGetNumberOfElements(PARAM_DEF0(S));
const int_T p_width1 = mxGetNumberOfElements(PARAM_DEF1(S));
const real_T *omig = mxGetData(PARAM_DEF0(S));
const real_T *beta = mxGetData(PARAM_DEF1(S));
evc_Derivatives_wrapper(signal,output, dx, omig, p_width0, beta, p_width1);
}
#endif /* MDL_DERIVATIVES */
/* Function: mdlTerminate =====================================================
* Abstract:
* No termination needed, but we are required to have this routine.
*/
static void mdlTerminate(SimStruct *S)
{
}
#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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -