📄 cdma20001x_acc.c
字号:
/*
* This file is not available for use in any application other than as a
* MATLAB(R) MEX file for use with the Simulink(R) Accelerator product.
*/
/*
* Real-Time Workshop code generation for Simulink model "cdma20001x_acc.mdl".
*
* Model Version : 1.114
* Real-Time Workshop file version : 5.0 $Date: 2002/05/30 19:21:33 $
* Real-Time Workshop file generated on : Wed Jan 07 16:12:29 2009
* TLC version : 5.0 (Jun 18 2002)
* C source code generated on : Wed Jan 07 16:12:30 2009
*/
#include <math.h>
#include <string.h>
#include "cdma20001x_acc.h"
#include "cdma20001x_acc_private.h"
#include <stdio.h>
#include "simstruc.h"
#define CodeFormat S-Function
#define AccDefine1 Accelerator_S-Function
/* Initial conditions for atomic system: '<Root>/Spectrum Scope' */
void cdma20001x_Spectrum_Scope_Init(SimStruct *S)
{
/* simstruct variables */
cdma20001x_D_Work *cdma20001x_DWork = (cdma20001x_D_Work *) ssGetRootDWork(S);
cdma20001x_Parameters *cdma20001x_P = (cdma20001x_Parameters *)
ssGetDefaultParam(S);
/* Level1 S-Function Block: <S3>/Frame Scope (sdspfscope2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 0, 0, SS_CALL_MDL_INITIALIZE_CONDITIONS);
/* DSP Blockset Buffer/Unbuffer (sdsprebuff2) - '<S24>/Buffer' */
/* Copy ICs into circular buffer */
{
const int_T bufLenBytes = 256 * sizeof(creal_T);
byte_T *circBufPtr = (byte_T *)&cdma20001x_DWork->Buffer_CircBuff[0];
const byte_T *icPtr = (const byte_T *)&cdma20001x_P->Buffer_IC;
int_T i = 1;
while (i-- > 0) {
MWDSP_CopyScalarICs(circBufPtr, icPtr, 128, sizeof(creal_T));
circBufPtr += bufLenBytes;
}
}
/* Initialize DWork for IN_BUF_PTR and OUT_BUF_PTR */
{
*&cdma20001x_DWork->Buffer_IN_BUF_PTR = (void *)( (byte_T
*)&cdma20001x_DWork->Buffer_CircBuff[0] + 128 * sizeof(creal_T) );
*&cdma20001x_DWork->Buffer_OUT_BUF_PTR = (void *)( (byte_T
*)&cdma20001x_DWork->Buffer_CircBuff[0] + 64 * sizeof(creal_T) );
}
/* Calculate shiftPerElement
* (assuming that number of bits
* per element is power of two)
*/
{
int_T expn;
const double frac = frexp((double)sizeof(creal_T), &expn);
*&cdma20001x_DWork->Buffer_ShiftPerElem = expn - 1;
UNUSED_ARG(frac);
}
/* DSP Blockset Filter Implementation (sdspfilter) - '<S25>/Digital Filter' */
{
real_T *statePtr = (real_T *)
&cdma20001x_DWork->Digital_Filter_FILT_STATES[0];
/* Scalar expansion of ICs with extra zero element per channel */
int_T chanCount = 128;
while (chanCount--) {
*statePtr++ = *(const real_T *)&cdma20001x_P->Digital_Filter_ICRTP;
*statePtr++ = 0.0;
}
}
}
/* Outputs for atomic system: '<Root>/Spectrum Scope' */
void cdma20001x_Spectrum_Scope(SimStruct *S, int_T tid)
{
/* simstruct variables */
cdma20001x_BlockIO *cdma20001x_B = (cdma20001x_BlockIO *) _ssGetBlockIO(S);
cdma20001x_D_Work *cdma20001x_DWork = (cdma20001x_D_Work *) ssGetRootDWork(S);
cdma20001x_Parameters *cdma20001x_P = (cdma20001x_Parameters *)
ssGetDefaultParam(S);
/* local block i/o variables */
creal_T rtb_Window_o1[128];
creal_T rtb_temp39[128];
real_T rtb_S_Function_b;
real_T rtb_Math_Function1;
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [1.3020833333333334E-005, 0.0] */
/* Level1 S-Function Block: <S3>/Frame Scope (sdspfscope2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 0, 0, SS_CALL_MDL_OUTPUTS);
}
/* DSP Blockset Buffer/Unbuffer (sdsprebuff2) - '<S24>/Buffer' */
{
/* Copy input samples to buffer */
if (ssIsSampleHit(S, 0, tid)) {
MWDSP_Buf_CopyScalar_OL_1ch((const byte_T *)&cdma20001x_B->Gain_Product,
(byte_T **)&cdma20001x_DWork->Buffer_IN_BUF_PTR, (byte_T
*)&cdma20001x_DWork->Buffer_CircBuff[0],
*&cdma20001x_DWork->Buffer_ShiftPerElem, 256 * sizeof(creal_T));
}
/* Copy output samples from buffer */
if (ssIsSampleHit(S, 2, tid)) {
MWDSP_Buf_OutputFrame_1ch((byte_T *)&cdma20001x_B->Buffer[0], (byte_T
**)&cdma20001x_DWork->Buffer_OUT_BUF_PTR, (byte_T
*)&cdma20001x_DWork->Buffer_CircBuff[0],
*&cdma20001x_DWork->Buffer_ShiftPerElem, 256 * sizeof(creal_T) ,128, 64 *
sizeof(creal_T));
}
}
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [1.3020833333333334E-005, 0.0] */
/* DSP Blockset Window (sdspwindow2) - '<S25>/Window' */
{
int_T i;
for (i=0; i<128; i++) {
rtb_Window_o1[i].re = cdma20001x_B->Buffer[i].re *
cdma20001x_B->Window_o2[i];
rtb_Window_o1[i].im = cdma20001x_B->Buffer[i].im *
cdma20001x_B->Window_o2[i];
}
}
/* DSP Blockset Pad (sdsppad) - '<S26>/Zero Pad' */
/* Input dimensions: [128 x 1], output dimensions: [128 x 1] */
memcpy( &rtb_temp39[0], &rtb_Window_o1[0], (256 * sizeof(real_T)) );
/* DSP Blockset FFT (sdspfft2) - '<S26>/FFT' */
/* Complex input, 1 channels, 128 rows, linear output order */
MWDSP_R2BR_Z(&rtb_temp39[0], 1, 128, 128); /* In-place bit-reverse reordering */
/* Radix-2 DIT FFT using TableSpeed twiddle computation */
MWDSP_R2DIT_TBLS_Z(&rtb_temp39[0], 1, 128, 128,
&cdma20001x_P->FFT_TwiddleTable[0], 1, 0);
/* Math: '<S26>/Magnitude Squared'
*
* Regarding '<S26>/Magnitude Squared':
* Op: magnitude^2
*/
{
int_T i1;
const creal_T *u0 = &rtb_temp39[0];
real_T *y0 = &cdma20001x_B->Magnitude_Squared[0];
for (i1=0; i1 < 128; i1++) {
y0[i1] = u0[i1].re * u0[i1].re + u0[i1].im * u0[i1].im;
}
}
/* DSP Blockset Filter Implementation (sdspfilter) - '<S25>/Digital Filter' */
/* Filter algorithm: FIR Direct-Form (double precision floating-point) */
/* Complexities: input - real, num coeffs - real */
/* Implementing filter algorithm */
MWDSP_FIR_DF_DD(&cdma20001x_B->Magnitude_Squared[0],
&cdma20001x_B->Digital_Filter[0],
&cdma20001x_DWork->Digital_Filter_FILT_STATES[0],
&cdma20001x_DWork->Digital_Filter_DF_INDX, 2, 1, 128,
&cdma20001x_P->Digital_Filter_RTP1COEFF[0], 1);
/* S-Function Block (sdotproduct): <S29>/S-Function */
rtb_S_Function_b = cdma20001x_B->Window_o2[0] * cdma20001x_B->Window_o2[0];
{
int_T i1;
const real_T *u0 = &cdma20001x_B->Window_o2[1];
const real_T *u1 = &cdma20001x_B->Window_o2[1];
for (i1=0; i1 < 127; i1++) {
rtb_S_Function_b += u0[i1] * u1[i1];
}
}
/* Math: '<S27>/Math Function1'
*
* Regarding '<S27>/Math Function1':
* Op: reciprocal
*/
rtb_Math_Function1 = 1.0/(rtb_S_Function_b);
/* Product: '<S25>/Product2' */
{
int_T i1;
const real_T *u0 = &cdma20001x_B->Digital_Filter[0];
real_T *y0 = &cdma20001x_B->Product2_b[0];
for (i1=0; i1 < 128; i1++) {
y0[i1] = u0[i1] * rtb_Math_Function1;
}
}
}
}
/* Update for atomic system: '<Root>/Spectrum Scope' */
void cdma20001x_Spectrum_Scope_Update(SimStruct *S, int_T tid)
{
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [1.3020833333333334E-005, 0.0] */
/* Level1 S-Function Block: <S3>/Frame Scope (sdspfscope2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 0, 0, SS_CALL_MDL_UPDATE);
}
}
/* Outputs for root system: '<Root>' */
static void mdlOutputs(SimStruct *S, int_T tid)
{
/* simstruct variables */
cdma20001x_BlockIO *cdma20001x_B = (cdma20001x_BlockIO *) _ssGetBlockIO(S);
cdma20001x_D_Work *cdma20001x_DWork = (cdma20001x_D_Work *) ssGetRootDWork(S);
cdma20001x_Parameters *cdma20001x_P = (cdma20001x_Parameters *)
ssGetDefaultParam(S);
/* local block i/o variables */
creal_T rtb_Real_Imag_to_Complex;
real_T rtb_Reshape_b;
real_T rtb_I_Product;
real_T rtb_Product1;
real_T rtb_Q_Product2;
real_T rtb_temp60;
real_T rtb_temp61[172];
int16_T rtb_Add1;
int16_T rtb_Product2_a;
int16_T rtb_temp64;
if (ssIsSampleHit(S, 4, tid)) { /* Sample time: [2.6666666666666668E-002, 0.0] */
/* Level2 S-Function Block: <S18>/PN Sequence (scompnseq2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 0, SS_CALL_MDL_OUTPUTS);
/* Level2 S-Function Block: <S18>/Insert Zero (scomselect) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 1, SS_CALL_MDL_OUTPUTS);
}
/* DSP Blockset Buffer/Unbuffer (sdsprebuff2) - '<S18>/Unbuffer' */
{
if (ssIsSampleHit(S, 1, tid)) {
MWDSP_Buf_CopyInputToOutput_1ch((const byte_T
*)&cdma20001x_B->Insert_Zero_a[0], (byte_T *)&cdma20001x_B->Unbuffer_a,
(int32_T *)&cdma20001x_DWork->Unbuffer_a_CircBuff, sizeof(real_T),
sizeof(real_T)*1, 32768, 1);
}
}
if (ssIsSampleHit(S, 1, tid)) { /* Sample time: [8.1380208333333339E-007, 0.0] */
/* Constant: '<S20>/Constant' */
cdma20001x_B->Constant_a = cdma20001x_P->Constant_a_Value;
/* Level2 S-Function Block: <S17>/Long Code Generator (scompnseq2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 7, SS_CALL_MDL_OUTPUTS);
/* Constant: '<S19>/Constant' */
cdma20001x_B->Constant_b = cdma20001x_P->Constant_b_Value;
/* Gain: '<S19>/Polarity' incorporates:
* Sum: '<S19>/Sum'
* Gain: '<S19>/Gain'
*
* Regarding '<S19>/Polarity':
* Gain value: cdma20001x_P->Polarity_b_Gain
*
* Regarding '<S19>/Gain':
* Gain value: cdma20001x_P->Gain_b_Gain
*/
cdma20001x_B->Polarity_b = ((cdma20001x_B->Long_Code_Generator *
cdma20001x_P->Gain_b_Gain) - cdma20001x_B->Constant_b) *
cdma20001x_P->Polarity_b_Gain;
/* Product: '<S17>/I Product' incorporates:
* Gain: '<S20>/Polarity'
* Sum: '<S20>/Sum'
* Gain: '<S20>/Gain'
*
* Regarding '<S20>/Polarity':
* Gain value: cdma20001x_P->Polarity_a_Gain
*
* Regarding '<S20>/Gain':
* Gain value: cdma20001x_P->Gain_a_Gain
*/
rtb_I_Product = (((cdma20001x_B->Unbuffer_a * cdma20001x_P->Gain_a_Gain) -
cdma20001x_B->Constant_a) * cdma20001x_P->Polarity_a_Gain) *
cdma20001x_B->Polarity_b;
/* Constant: '<Root>/data' */
cdma20001x_B->data = cdma20001x_P->data_Value;
/* Sum: '<S2>/Add'
*
* Regarding '<S2>/Add':
* Sum Block: '<S2>/Add'
*
* y = u0 + u1 + u2
*
* Input0 Data Type: Floating Point real_T
* Input1 Data Type: Floating Point real_T
* Input2 Data Type: Floating Point real_T
* Output0 Data Type: Fixed Point S16 2^-10
* Round Mode: Floor
* Saturation Mode: Wrap
*/
{
int16_T castIn;
{
double uTemp;
uTemp = floor(ldexp(cdma20001x_B->data,10));
uTemp = fmod( uTemp, ldexp( 1.0, 16 ) );
if ( uTemp < ldexp( -1.0, 15 ) )
{
uTemp += ldexp( 1.0, 16 );
}
else if ( uTemp >= ldexp( 1.0, 15 ) )
{
uTemp -= ldexp( 1.0, 16 );
}
rtb_temp64 = (int16_T)uTemp;
}
{
double uTemp;
uTemp = floor(ldexp(cdma20001x_B->data,10));
uTemp = fmod( uTemp, ldexp( 1.0, 16 ) );
if ( uTemp < ldexp( -1.0, 15 ) )
{
uTemp += ldexp( 1.0, 16 );
}
else if ( uTemp >= ldexp( 1.0, 15 ) )
{
uTemp -= ldexp( 1.0, 16 );
}
castIn = (int16_T)uTemp;
}
rtb_temp64 += castIn;
{
double uTemp;
uTemp = floor(ldexp(cdma20001x_B->data,10));
uTemp = fmod( uTemp, ldexp( 1.0, 16 ) );
if ( uTemp < ldexp( -1.0, 15 ) )
{
uTemp += ldexp( 1.0, 16 );
}
else if ( uTemp >= ldexp( 1.0, 15 ) )
{
uTemp -= ldexp( 1.0, 16 );
}
castIn = (int16_T)uTemp;
}
rtb_temp64 += castIn;
}
/* Product: '<S2>/Product1' */
/* Product Block: '<S2>/Product1'
*
* y = u0 * u1
*
* Input0 Data Type: Floating Point real_T
* Input1 Data Type: Fixed Point S16 2^-10
* Output0 Data Type: Floating Point real_T
* Round Mode: Floor
* Saturation Mode: Saturate
*/
{
rtb_Product1 = (rtb_I_Product*ldexp((double)rtb_temp64,-10));
}
}
if (ssIsSampleHit(S, 4, tid)) { /* Sample time: [2.6666666666666668E-002, 0.0] */
/* Level2 S-Function Block: <S22>/PN Sequence (scompnseq2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 17, SS_CALL_MDL_OUTPUTS);
/* Level2 S-Function Block: <S22>/Insert Zero (scomselect) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 18, SS_CALL_MDL_OUTPUTS);
}
/* DSP Blockset Buffer/Unbuffer (sdsprebuff2) - '<S22>/Unbuffer' */
{
if (ssIsSampleHit(S, 1, tid)) {
MWDSP_Buf_CopyInputToOutput_1ch((const byte_T
*)&cdma20001x_B->Insert_Zero_b[0], (byte_T *)&cdma20001x_B->Unbuffer_b,
(int32_T *)&cdma20001x_DWork->Unbuffer_b_CircBuff, sizeof(real_T),
sizeof(real_T)*1, 32768, 1);
}
}
if (ssIsSampleHit(S, 1, tid)) { /* Sample time: [8.1380208333333339E-007, 0.0] */
/* Constant: '<S21>/Constant' */
cdma20001x_B->Constant_c = cdma20001x_P->Constant_c_Value;
/* Product: '<S17>/Q Product1' incorporates:
* UnitDelay: '<S17>/Unit Delay'
* Gain: '<S21>/Polarity'
* Sum: '<S21>/Sum'
* Gain: '<S21>/Gain'
*
* Regarding '<S21>/Polarity':
* Gain value: cdma20001x_P->Polarity_c_Gain
*
* Regarding '<S21>/Gain':
* Gain value: cdma20001x_P->Gain_c_Gain
*/
cdma20001x_B->Q_Product1 = (cdma20001x_DWork->Unit_Delay_DSTATE) *
(((cdma20001x_B->Unbuffer_b * cdma20001x_P->Gain_c_Gain) -
cdma20001x_B->Constant_c) * cdma20001x_P->Polarity_c_Gain);
/* Level1 S-Function Block: <S17>/Conversion (MS_SFUN_QConvert) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 25, SS_CALL_MDL_OUTPUTS);
/* Product: '<S17>/Q Product2' */
rtb_Q_Product2 = rtb_I_Product * cdma20001x_B->Conversion;
/* Constant: '<Root>/Relative Gain' */
cdma20001x_B->Relative_Gain = cdma20001x_P->Relative_Gain_Value;
}
if (ssIsSampleHit(S, 3, tid)) { /* Sample time: [0.02, 0.0] */
/* DSP Blockset Random Source (sdsprandsrc2) - '<S8>/Random Source' */
MWDSP_RandSrc_U_D((real64_T*)&rtb_temp61[0],&cdma20001x_P->Random_Source_Min,1,&cdma20001x_P->Random_Source_Max,1,&cdma20001x_DWork->Random_Source_STATE_DWORK[0],1,172);
/* Rounding: '<S8>/Rounding Function' */
{
int_T i1;
const real_T *u0 = &rtb_temp61[0];
real_T *y0 = &rtb_temp61[0];
for (i1=0; i1 < 172; i1++) {
y0[i1] = ceil(u0[i1]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -