📄 s_frame_buffer.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: June 2, 1999 | | History: | June 2, 1999 Maarit Melvasalo | Initial version | June 16, 1999 Maarit Melvasalo | Comments added | | File : | | Abstract: Buffers the inputs to given buffer size | | | INPUTS: 1) Depread bits in one slot | OUTPUT: 1) Coded data bits per frame | 2) Flag (0 or 1) if output is valid | | DEPENDS ON FILES | blockcollect.c | control_bits.c | | | USER GIVEN PARAMETERS | | | 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_frame_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"#define NPARAMS 3/* Input block siaze/**/#define IN_SIZE(S) ssGetSFcnParam(S,0) #define nIn (int_T)(mxGetPr(IN_SIZE(S))[0])/* out put block size = number of coded bits in frame = buffer size/**/#define OUT_SIZE(S) ssGetSFcnParam(S,1) #define nOut (int_T)(mxGetPr(OUT_SIZE(S))[0]) /* Number of slot in a frame/**/ #define SLOTS(S) ssGetSFcnParam(S,2) #define nSlots (int_T)(mxGetPr(SLOTS(S))[0]) /* Pointer to input ports /**/#define I(element) (*IPtrs[element]) #define Is(element) (*IsPtrs[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, 2)) return; ssSetInputPortWidth(S, 0, nIn); ssSetInputPortWidth(S, 1, nSide); ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); if (!ssSetNumOutputPorts(S, 2)) return; ssSetOutputPortWidth(S, 0,nOut); ssSetOutputPortWidth(S, 1,nSide); /* flag /**/ ssSetNumSampleTimes(S, 2); ssSetNumIWork(S, 2); ssSetNumRWork(S, nOut); ssSetSFcnParamNotTunable(S,0); /* speeds up simulations*/ ssSetSFcnParamNotTunable(S,1); ssSetSFcnParamNotTunable(S,2); /* 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(nOut); }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); int_T *iwork = ssGetIWork(S); real_T *rwork = ssGetRWork(S); real_T out[nOut]; real_T S_in[nIn]; /**/ 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[lp] = I(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)), &ready, out);/**/ if (ready > 0){ iwork[1] = 1; for (lp = 0; lp <nOut; 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 <nOut; 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 + -