📄 s_ber_calc.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: February 23, 1999 | | History: | | June 8, 1999 Maarit Melvasalo | Initial version. * * File : s_ber_calc.c * Abstract: * * USER GIVEN PARAMETERS * * * 1: N = the number of input bits * 2: CRC = number of CRC bits * 3: CRC_POL = polynomial for CRC calulation * 4: nFrames = number of frames in a block * * | | Copyright disclaimer: | This software was developed at the National Institute of Standards | and Technology by employees of the Federal Government in the course | of their official duties. Pursuant to title 17 Section 105 of the | United States Code this software is not subject to copyright | protection and is in the public domain. | */#define S_FUNCTION_NAME s_ber_calc#define S_FUNCTION_LEVEL 2#include <math.h>#include "simstruc.h"#include "tmwtypes.h"#include "config_wcdma.h"#include "wcdma_simulink.h"/* USER GIVEN PARAMETERS AND DEFINITIONS /**//*Number of inputs and outputs/**/#define NINPUTS 2#define NOUTPUTS 1/* Number of user given parameters/**/ #define NPARAMS 2 /* Input and Output Size parameters /**/#define SIZE_PARAM(S) ssGetSFcnParam(S,0) #define nInput (int_T)(mxGetPr(SIZE_PARAM(S))[0]) /* Number of frames in one block/**/#define FRAME_PARAM(S) ssGetSFcnParam(S,1) #define nFrames (mxGetPr(FRAME_PARAM(S))[0]) /* Pointers to Input Ports */#define I(element) (*iPtrs[element]) #define O(element) (*oPtrs[element]) /* Sampletime -- defined in config_cdma /**/#define td nFrames * TD_FRAME /* Input and Output Size parameters /**/#define td nFrames * TD_FRAME /*====================* * S-function methods * *====================*//* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). */static void mdlInitializeSizes(SimStruct *S){ ssSetNumSFcnParams(S, NPARAMS); /* Number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; } if (!ssSetNumInputPorts(S, NINPUTS)) return; /* ONE input port/**/ ssSetInputPortWidth(S, 0, nInput); ssSetInputPortWidth(S, 1, nInput); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); /* ssSetInputPortDirectFeedThrough(S, 2, 1);/**/ if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; /* TWO output port/**/ ssSetOutputPortWidth(S, 0, 2); ssSetNumSampleTimes(S, 1); ssSetNumIWork(S, nInput); ssSetNumRWork(S, 1); ssSetSFcnParamNotTunable(S,0); /* speeds up simulations*/ ssSetSFcnParamNotTunable(S,1); /**/ /* Take care when specifying exception free code - see sfuntmpl.doc */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);} /* do not use mxCalloc or mexErrMsgTxt functions *//* Function: mdlInitializeSampleTimes ========================================= * Abstract: * Specifiy that sampletime is given by the user */static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, td); ssSetOffsetTime(S, 0, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: * */static void mdlInitializeConditions(SimStruct *S){ real_T *rwork = ssGetRWork(S); rwork[0] = 0;}/* Function: mdlOutputs ======================================================= * Abstract: * */static void mdlOutputs(SimStruct *S, int_T tid){ real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType iPtrs = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType oPtrs = ssGetInputPortRealSignalPtrs(S,1); real_T *rwork = ssGetRWork(S); int_T *iwork = ssGetIWork(S); int_T i, tmp_ber = 0; for (i = 0; i < nInput; i++){ /* if ( iwork[i] != O(i)) rwork[0] ++;/**/ if ( abs(iwork[i] - O(i)) > 0.01) tmp_ber++; iwork[i] = (int_T)I(i); } rwork[0] += tmp_ber; y[0] = rwork[0];/**/ y[1] = tmp_ber;}/* Function: mdlTerminate ===================================================== * Abstract: */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 + -