⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s_crc_add.c

📁 wcdma模型
💻 C
字号:
/* | Project:     WCDMA simulation environment | Module:       | Author:       | Date:        February 18, 1999 | | History: |  |              February 18,  1999 Maarit Melvasalo  |                      Initial version. New channel model. | | * *  File    : s_crc_add.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 * * Inputs: *        Decoded bits with CRC bits *        Flag indicating if inputdata is valid or not * Outputs:  *        Decoded bits without CRC bits         *        Cumulative frame error rate | | 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. | |   We would appreciate acknowledgement if the software is used. | */#define S_FUNCTION_NAME s_crc_add#define S_FUNCTION_LEVEL 2#include <math.h>#include "simstruc.h"#include "tmwtypes.h"#include "config_wcdma.h"#include "wcdma_simulink.h"#include "crc_routines.h"/* USER GIVEN PARAMETERS AND DEFINITIONS /**//*Number of inputs and outputs/**/#define NINPUTS   1#define NOUTPUTS  1/* number of user given parameters /**/#define NPARAMS 4                                  /* Input block size*/#define IN_SIZE(S) ssGetSFcnParam(S,0)             #define nInputs (int_T)(mxGetPr(IN_SIZE(S))[0])    /* Number of CRC bits*/#define CRC_SIZE(S) ssGetSFcnParam(S,1)         #define nCRC (int_T)(mxGetPr(CRC_SIZE(S))[0])    /* CRC Polynomial/**/#define CRC_POL(S) ssGetSFcnParam(S,2)         /* Number of frames in one block/**/#define FRAME_PARAM(S) ssGetSFcnParam(S,3)   #define nFrames (int_T)(mxGetPr(FRAME_PARAM(S))[0]) /* Pointer to Input Port */#define U(element) (*uPtrs[element]) /* Sampletime -- defined in config_cdma /**/#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){  /* Number of expected parameters */  ssSetNumSFcnParams(S, NPARAMS);    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))  {      return; }  /* Initialize the input and output port sizes/**/    if (!ssSetNumInputPorts(S, NINPUTS)) return;    ssSetInputPortWidth(S, 0, nInputs);    ssSetInputPortDirectFeedThrough(S, 0, 1);    if (!ssSetNumOutputPorts(S, NOUTPUTS)) return;    ssSetOutputPortWidth(S, 0, nInputs + nCRC);    /* Initialize number of sample times /**/    ssSetNumSampleTimes(S, 1);    /* To Speeds up the simulations/**/    ssSetSFcnParamNotTunable(S,0);     ssSetSFcnParamNotTunable(S,1);     ssSetSFcnParamNotTunable(S,2);     ssSetSFcnParamNotTunable(S,3);     /* Take care when specifying exception free code - see sfuntmpl.doc */    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);}/* Function: mdlInitializeSampleTimes ========================================= * Abstract: *    Specifiy the sample time */static void mdlInitializeSampleTimes(SimStruct *S){     ssSetSampleTime(S, 0, td);  ssSetOffsetTime(S, 0, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: *    Initialize the CRC table with given polynomial. */static void mdlInitializeConditions(SimStruct *S){  int_T            crc_poly  = (int_T)mxGetPr(CRC_POL(S))[0];    wcdma_crctable_init(crc_poly);}/* Function: mdlOutputs ======================================================= * Abstract: *           Calculate and add the CRC bits to given input *           vector.  *  */static void mdlOutputs(SimStruct *S, int_T tid){    real_T            *y    = ssGetOutputPortRealSignal(S,0);    InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);    int_T             input[nInputs];    int_T             crc[nCRC];    int_T             i;    int_T             crc_poly  = (int_T)mxGetPr(CRC_POL(S))[0];     for (i = 0; i < nInputs; i++){	input[i] = (int_T)U(i);	y[i] = U(i);     }    if (nCRC > 0 ){      i = wcdma_get_crc_value(input, nInputs, crc);            for (i = 0; i < nCRC; i++)	y[i + nInputs] = crc[i];    }}/* 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 + -