📄 s_intra_interleaver.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 | 4: nSlots = number of slots in a frame | | Inputs: | input bits (nFrames * bits_in_frame) | | Outputs: | interleaved bits (bits_in_frame /nSlot) | | 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_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_in_frame (int_T)(mxGetPr(B_PARAM(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 slots in each frame /**/#define SLOTS(S) ssGetSFcnParam(S,3)#define nSlots (int_T)(mxGetPr(SLOTS(S))[0]) /* Pointer to Input Port */#define U(element) (*uPtrs[element]) /* Sampletime -- defined in config_cdma /**/#define tdI nFrames * TD_FRAME /*input sample time /**/ #define tdO TD_FRAME / (real_T)nSlots /*output sample time /**/ /* Output block size = coded_bits_in_slot/**/#define nOutputs (int_T)(bits_in_frame/nSlots) /*====================* * 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_in_frame); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; ssSetOutputPortWidth(S, 0, nOutputs); /* Initialize number of sample times and simulink work vectors /**/ ssSetNumSampleTimes(S, 2); ssSetNumIWork(S, 3); ssSetNumRWork(S, nFrames*bits_in_frame); /* 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 times */static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, tdO); /*Output sample time/**/ ssSetOffsetTime(S, 0, 0.0); ssSetSampleTime(S, 1, tdI); /*input sample time/**/ ssSetOffsetTime(S, 1, 0.0);}/* Function: mdlOutputs ======================================================= * Abstract: * Call the intra frame interleaver for each slot * Outputs bits in one slot at each sample time */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 *rwork = ssGetRWork(S); int_T flag = (int_T)(mxGetPr(intra_flag(S))[0]) ; int_T i; int_T outputs[nFrames*bits_in_frame]; /* Input sample time /**/ if (ssIsSampleHit(S, 1, tid)) { /* save the input vector to simulink memory /**/ for (i=0; i < (nFrames * bits_in_frame); i++) rwork[i] = U(i); /* if the flag for intra frame interleaver is on /**/ if (flag > 1){ for (i=0; i < nFrames ; i++) /* call separately for each slot /**/ wcdma_intraframe_interleaver(bits_in_frame, &rwork[i*bits_in_frame]); } iwork[2] = 0; /* reset the slot calculator/**/ } /* Output sample time /**/ if (ssIsSampleHit(S, 0, tid)) { /* just check that no overflows occur /**/ if (iwork[2] > nSlots * nFrames - 1) iwork[2] = nSlots * nFrames - 1; /* output correct number of bits each time /**/ for (i = 0; i < nOutputs; i++) y[i] = rwork[iwork[2] * nOutputs + i]; iwork[2] += 1; }}/* 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 + -