📄 s_dl_demod_buffer.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: April 2, 1999 | | History: | April 2, 1999 Maarit Melvasalo | Initial version | June 16, 1999 Maarit Melvasalo | Comments added * * File : * Abstract: Buffers the inputs to given buffer size * And removes given number of control bits * From the beginning of each slot (= input block) * * INPUTS: 1) Depread bits in one slot * Include control bits * OUTPUT: 1) Coded data bits per frame * Control bits are removed. * 2) Flag (0 or 1) if output is valid * * DEPENDS ON FILES * blockcollect.c * control_bits.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. | *//* * USER GIVEN PARAMETERS * */#define S_FUNCTION_NAME s_dl_demod_buffer#define S_FUNCTION_LEVEL 2#include <math.h>#include "simstruc.h"#include "tmwtypes.h"#include "blockcollect.h"#include "config_wcdma.h"#include "wcdma_simulink.h"/* MAX_CHANNEL_TAPS/**/#define NPARAMS 4/* Input block siaze/**/#define IN_SIZE(S) ssGetSFcnParam(S,0) #define in_dem (int_T)(mxGetPr(IN_SIZE(S))[0])/* out put block size = number of coded bits in frame/**/#define OUT_SIZE(S) ssGetSFcnParam(S,1) #define out_dem (int_T)(mxGetPr(OUT_SIZE(S))[0]) /* Number of control bits per each slot to be removed/**/#define CONTROL_B(S) ssGetSFcnParam(S,2) #define nControl (int_T)mxGetPr(CONTROL_B(S))[0] /* Number of slot in a frame/**/ #define SLOTS(S) ssGetSFcnParam(S,3) #define nSlots (int_T)(mxGetPr(SLOTS(S))[0]) /* buffer size/**/#define bits_in_frame (int_T)(out_dem + nControl * nSlots) /* Pointer to input ports /**/#define I(element) (*IPtrs[element]) #define Is(element) (*IsPtrs[element]) #define Q(element) (*QPtrs[element])#define Qs(element) (*QsPtrs[element]) /* Sample times /**/#define tdI TD_FRAME/(real_T)nSlots /* Input /**/#define tdO TD_FRAME /* Output /**/static void mdlInitializeSizes(SimStruct *S){ ssSetNumSFcnParams(S, NPARAMS); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; } if (!ssSetNumInputPorts(S, 4)) return; ssSetInputPortWidth(S, 0, in_dem); ssSetInputPortWidth(S, 1, nSide); ssSetInputPortWidth(S, 2, in_dem); ssSetInputPortWidth(S, 3, nSide); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 3, 1); if (!ssSetNumOutputPorts(S, 2)) return; ssSetOutputPortWidth(S, 0,out_dem); ssSetOutputPortWidth(S, 1,nSide); /* flag /**/ ssSetNumSampleTimes(S, 2); ssSetNumIWork(S, 2); ssSetNumRWork(S, out_dem); ssSetSFcnParamNotTunable(S,0); /* speeds up simulations*/ 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); /* do not use mxCalloc or mexErrMsgTxt functions */} static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, tdI); ssSetOffsetTime(S, 0, 0.0); ssSetSampleTime(S, 1, tdO); ssSetOffsetTime(S, 1, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: */static void mdlInitializeConditions(SimStruct *S){ int_T *iwork = ssGetIWork(S); /* Initialize the buffer Find correct instance, set the correct buffer size etc/**/ iwork[0] = wcdma_symbolbuffer_init(bits_in_frame); }static void mdlOutputs(SimStruct *S, int_T tid){ real_T *y = ssGetOutputPortRealSignal(S,0); real_T *flag = ssGetOutputPortRealSignal(S,1); InputRealPtrsType IPtrs = ssGetInputPortRealSignalPtrs(S,0); InputRealPtrsType IsPtrs = ssGetInputPortRealSignalPtrs(S,1); InputRealPtrsType QPtrs = ssGetInputPortRealSignalPtrs(S,2); InputRealPtrsType QsPtrs = ssGetInputPortRealSignalPtrs(S,3); int_T *iwork = ssGetIWork(S); real_T *rwork = ssGetRWork(S); real_T out[bits_in_frame]; real_T S_in[2 * in_dem]; /**/ int_T lp,lp_tmp,ready = 0; /* If input sample time /**/ if (ssIsSampleHit(S, 0, tid)) { if(Is(0) > 0){ for (lp = 0; lp < (int_T)Is(0); lp++){ S_in[2*lp] = I(lp); S_in[2*lp+1] = Q(lp); } /*Tarkista ettei tule ongelmia jos alusssa on viivetta ja ensimmainen ulostulo ei tule silloin kun ensimmain/**/ wcdma_symbolbuffer(iwork[0], S_in, (int_T)(Is(0)+Qs(0)), &ready, out);/**/ if (ready > 0){ iwork[1] = 1; if (nControl > 0) { wcdma_remove_control_bits(out,bits_in_frame, nSlots, nControl, rwork);}/**/ else for (lp = 0; lp <out_dem; lp++){ rwork[lp] = out[lp];} } } } /* If output sample time and there is something to output Return the coded bits in a frame and set the output flag correctly /**/ if(ssIsSampleHit(S, 1, tid) && iwork[1] > 0){/**/ for (lp = 0; lp <out_dem; lp++){ y[lp] = rwork[lp]; }/**/ flag[0] = iwork[1]; iwork[1] = 0; } else { flag[0] = 0; }}/******************************************************************** At end of simulation termination is required/**//********************************************************************/static void mdlTerminate(SimStruct *S){ int_T *iwork = ssGetIWork(S); /* Free the symbol buffer instance /**/ 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 + -