📄 s_dl_discmod.c
字号:
/* | Project: WCDMA simulation environment | Module: | Author: | Date: February 23, 1999 | | History: | | February 23, 1999 Maarit Melvasalo | Initial version. | March 11, 1999 Maarit Melvasalo | Comments added and extra code removed | May 3, 1999 Maarit Melvasalo | Downlink and uplink separated and sample changed | to internal | | File : s_dl_discmod.c | Abstract: | | USER GIVEN PARAMETERS | | 1: B = the number of real input chips | 2: C = the spreading code | 3: SF = spreading factor | | | DEPENDS ON FILES | discmod.c | qpsk_ints.c | spreading.c | mealy.c | bitroutines.c | conversions.c | utility.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_dl_discmod#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 2/* Number of user given parameters/**/ #define NPARAMS 4 /* Spreading code parameter /**/#define C_PARAM(S) ssGetSFcnParam(S,1) /* Code */#define nC mxGetN(C_PARAM(S)) /* Code length */ #define SF_PARAM(S) ssGetSFcnParam(S,2) /* Spreading factor*/#define SF (int_T)(mxGetPr(SF_PARAM(S))[0]) /* Number of slots in each frame /**/#define SLOTS(S) ssGetSFcnParam(S,3)#define nSlots (int_T)(mxGetPr(SLOTS(S))[0]) /* Input and Output Size parameters /**/#define B_DLmod(S) ssGetSFcnParam(S,0) #define inDLmod (int_T)(mxGetPr(B_DLmod(S))[0]) /* Output block size /**/#define outDLmod (int_T)(inDLmod * SF / 2) /* Pointer to Input Port */#define U(element) (*uPtrs[element]) /* Sampletime -- defined in config_cdma /**/#define td TD_FRAME / (real_T)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, inDLmod); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, NOUTPUTS)) return; /* TWO output port/**/ ssSetOutputPortWidth(S, 0,outDLmod); ssSetOutputPortWidth(S, 1,outDLmod); /* Initialize number of sample times and simulink work vectors /**/ ssSetNumSampleTimes(S, 1); ssSetNumIWork(S, nC); /* 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);} /* do not use mxCalloc or mexErrMsgTxt functions *//* Function: mdlInitializeSampleTimes ========================================= * Abstract: * Specify the sample time */static void mdlInitializeSampleTimes(SimStruct *S){ ssSetSampleTime(S, 0, td); ssSetOffsetTime(S, 0, 0.0);}#define MDL_INITIALIZE_CONDITIONS/* Function: mdlInitializeConditions ======================================== * Abstract: * Stores the spreading code to IWork vector */static void mdlInitializeConditions(SimStruct *S){ int_T *iwork = ssGetIWork(S); real_T *cpr = mxGetPr(C_PARAM(S)); int_T i; for (i =0; i<nC;i++){ iwork[i] = (int_T)cpr[i]; } i = wcdma_mod_init(); /*is a empty function*/}/* Function: mdlOutputs ======================================================= * Abstract: * */static void mdlOutputs(SimStruct *S, int_T tid){ real_T *yI = ssGetOutputPortRealSignal(S,0); real_T *yQ = ssGetOutputPortRealSignal(S,1); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); int_T I_out[outDLmod]; int_T Q_out[outDLmod]; int_T inputs[inDLmod]; int_T *iwork = ssGetIWork(S); /*spreading code/**/ int_T lp,tmp; /* save the inputs to a int vector /**/ for (lp=0; lp<inDLmod; lp++){ inputs[lp]=(int_T)U(lp); } tmp = wcdma_dl_mod(inputs,inDLmod,iwork,nC,SF,I_out,Q_out ); /* int inputs[], /* input bit vector */ /* int inDLmod, /* input vector size */ /* int code[], /* spreading code */ /* int code_len, /* length of spreading code */ /* int sf, /* spreadign factor */ /* int I_out[], /* modulated I output */ /* int Q_out[]) /* modulated Q output */ /* Output update/**/ for (lp=0; lp < outDLmod; lp++){ yI[lp] = (real_T)I_out[lp]; yQ[lp] = (real_T)Q_out[lp]; }}/* Function: mdlTerminate ===================================================== * Abstract: */static void mdlTerminate(SimStruct *S){ int_T tmp; tmp = wcdma_dl_mod_free(); /*is a empty function*/}#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 + -