📄 s_intra_deinterleaver.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: May 28, 1999 | | History: | May 28, 1999 Maarit Melvasalo | Initial version | | File : | Abstract: | | USER GIVEN PARAMETERS | | 1: B = Size of real input vector (= packet size) | 2: FALG = indicates if the frame interleaver is used of not. | -- NOT IMPLEMENTED | 3: nFrames = number of frames that indicate the number of | frames in the input block | | Inputs: | input bits (nFrames * bits_in_frame) | Flag indicating if inputdata is valid or not | | Outputs: | interleaved bits (bits_in_frame /nSlot) | Flag indicating if inputdata is valid or not | | 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_intra_deinterleaver #define S_FUNCTION_LEVEL 2#include <math.h>#include "simstruc.h"#include "tmwtypes.h"#include "config_wcdma.h"#include "wcdma_simulink.h"#include "blockcollect.h"/*Number of input and output ports/**/#define NINPUTS 2#define NOUTPUTS 2/* Number of user given parameters/**/ #define NPARAMS 3 /* Input and Output Size parameters /**/#define IN_SIZE(S) ssGetSFcnParam(S,0) #define nInputs (int_T)(mxGetPr(IN_SIZE(S))[0]) /* Intra frame interleaver mode flag (on /off) */#define intra_flag(S) ssGetSFcnParam(S,1) /* Number of frames in one block/**/#define frame(S) ssGetSFcnParam(S,2)#define nFrames (int_T)(mxGetPr(frame(S))[0]) /*number of bits in output/**/#define nOutputs nInputs*nFrames /* Pointers to Input Ports */#define U(element) (*uPtrs[element])#define F(element) (*fPtrs[element])/* Sampletime -- defined in config_cdma /**/#define tdI TD_FRAME /* Input Sampletime */#define tdO nFrames * TD_FRAME /* Output sample time/**//*====================* * 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); ssSetInputPortWidth(S, 1, nSide); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; ssSetOutputPortWidth(S, 0, nOutputs); ssSetOutputPortWidth(S, 1, nSide); /* Initialize number of sample times and simulink work vectors /**/ if(nFrames == 1) {ssSetNumSampleTimes(S, 1);} else ssSetNumSampleTimes(S, 2); ssSetNumIWork(S, 5); ssSetNumRWork(S, nInputs*nFrames); /**/ /* To Speeds up the simulations/**/ ssSetSFcnParamNotTunable(S,0); ssSetSFcnParamNotTunable(S,1); ssSetSFcnParamNotTunable(S,2); /* Take care when specifying exception free code - see sfuntmpl.doc */ ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);}/* Function: mdlInitializeSampleTimes ========================================= * Abstract: * Spefify the imput times * NOTE: if nFrames is 1 tehn only one sample time is needed */static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, tdO); /*Output sample time/**/ ssSetOffsetTime(S, 0, 0.0); if (nFrames >1) { ssSetSampleTime(S, 1, tdI); /*input sample time/**/ ssSetOffsetTime(S, 1, 0.0);}}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: * Initialize the symbol buffer * */static void mdlInitializeConditions(SimStruct *S){ int_T *iwork = ssGetIWork(S); if(nFrames >1 ) iwork[0] = wcdma_symbolbuffer_init(nOutputs);}/* Function: mdlOutputs ======================================================= * Abstract: * Calls intra frame interleaver for each frame * Then buffers the inputs to bigger blocks if necessary * */static void mdlOutputs(SimStruct *S, int_T tid){ real_T *y = ssGetOutputPortRealSignal(S,0); real_T *flag_out = ssGetOutputPortRealSignal(S,1); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType fPtrs = ssGetInputPortRealSignalPtrs(S,1); int_T *iwork = ssGetIWork(S); real_T *rwork = ssGetRWork(S); int_T flag = (int_T)(mxGetPr(intra_flag(S))[0]) ; int_T i,rows; int_T out[nOutputs]; int_T lp,lp_tmp,ready = 0; /* if nFrames > 1 i.e. input time is different than output time /**/ if(nFrames >1 ){ /* if input time and if the input is valid data /**/ if (ssIsSampleHit(S, 1, tid) && F(0) > 0 ) { wcdma_symbolbuffer(iwork[0], &U(0), nInputs, &ready, rwork); if (ready > 0) iwork[1] = 1; } /* if output time and there is enough data in the buffer to output/**/ if (ssIsSampleHit(S, 0, tid) && iwork[1] > 0) { for (lp = 0; lp < nOutputs; lp++){ y[lp] = rwork[lp]; }/**/ flag_out[0] = iwork[1]; iwork[1] = 0; } } /* If the input and output blocks have same widht, i.e. nFrames == 1/**/ else { /* if the input is valid data/**/ if (F(0) > 0 ) { for (lp = 0; lp < nOutputs; lp++){ y[lp] = U(lp); }/**/ } flag_out[0] = F(0); }}/* Function: mdlTerminate ===================================================== * Abstract: * Termination is needed if the nFrames >1 */static void mdlTerminate(SimStruct *S){ int_T *iwork = ssGetIWork(S); if(nFrames >1 ) wcdma_symbolbuffer_free(iwork[0]);}#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 + -