📄 s_interleaver.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: MAy 24, 1999 | | History: | May 23, 1999 Maarit Melvasalo | Interleaver separated from channel coding | see s_chcoding.c | May 28, 1999 Maarit Melvasalo | sample time changed -- new parameter added | June 21, 1999 Maarit Melvasalo | Multistage interleaver added | | | File : s_interleaving.c | Abstract: | | USER GIVEN PARAMETERS | | 1: B = Number of bits in a frame | 2: COL = Number of colums for interleaver | 3: nFrames = Number of frames in a block | 4: inter_mode = Inter interleaver mode | | Inputs: | input bits | | Outputs: | Interleaved bits | | DEPENDS ON FILES | interleaving.c | | | | 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_interleaver #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 input and output ports/**/#define NINPUTS 1#define NOUTPUTS 1/* Number of user given parameters/**/ #define NPARAMS 4 /* Input and Output Size parameters /**/#define B_PARAM(S) ssGetSFcnParam(S,0) #define bits_frame (int_T)(mxGetPr(B_PARAM(S))[0]) /* Number of columns for block interleaver/**/ #define COL_PARAM(S) ssGetSFcnParam(S,1) /* Number of frames in one block/**/#define frame(S) ssGetSFcnParam(S,2)#define nFrames (int_T)(mxGetPr(frame(S))[0]) /* Inter frame interleaver mode flag */#define inter_mode(S) ssGetSFcnParam(S,3) /* 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, nFrames*bits_frame); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; ssSetOutputPortWidth(S, 0, nFrames*bits_frame); /* Initialize number of sample times and simulink work vectors /**/ ssSetNumSampleTimes(S, 1); ssSetNumIWork(S, 3); /* 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 sample tiem */static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, td); ssSetOffsetTime(S, 0, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: * For block interleaver calculate number of rows */static void mdlInitializeConditions(SimStruct *S){ int_T *iwork = ssGetIWork(S); int_T cols = (int_T)(mxGetPr(COL_PARAM(S))[0]); real_T mode = mxGetPr(inter_mode(S))[0]; int_T rows; /* If the Block interleaver is selected /**/ if ( mode <2 ){ iwork[0] = cols; if(cols > 0) { rows = (nFrames * bits_frame)/ cols; if (rows * cols == (nFrames * bits_frame)){ iwork[1] = rows; } /* if there there is something wrong with the cols /**/ else iwork[0] = 0; } } }/* Function: mdlOutputs ======================================================= * Abstract: * Performs for the given block (nFrames * bits_in_frame * block interleaving or multistage interleaving * Depending on the mode parameter * */static void mdlOutputs(SimStruct *S, int_T tid){ real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); int_T *iwork = ssGetIWork(S); real_T mode = mxGetPr(inter_mode(S))[0]; int_T i; int_T inputs[nFrames*bits_frame]; int_T outputs[nFrames*bits_frame]; /* Move the input bits to a vector /**/ for (i=0; i < nFrames*bits_frame; i++) inputs[i] = (int_T)U(i); /* If the Block interleaver is selected /**/ if ( mode <2 ){ if(iwork[0] > 0) { wcdma_block_interleaver(iwork[1], iwork[0], inputs, outputs); } } /* If the Multistage interleaver is selected /**/ else { wcdma_interframe_interleaver(nFrames*bits_frame,bits_frame,inputs,outputs); } /* Update the return value /**/ for (i = 0; i < nFrames*bits_frame; i++) y[i] = outputs[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 + -