📄 example5_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 "example5_acc.mdl".
*
* Model Version : 1.35
* Real-Time Workshop file version : 5.0 $Date: 2002/05/30 19:21:33 $
* Real-Time Workshop file generated on : Mon Jan 10 16:29:25 2005
* TLC version : 5.0 (Jun 18 2002)
* C source code generated on : Mon Jan 10 16:29:25 2005
*/
#include <math.h>
#include <string.h>
#include "example5_acc.h"
#include "example5_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 example5_Spectrum_Scope_Init(SimStruct *S)
{
/* simstruct variables */
example5_D_Work *example5_DWork = (example5_D_Work *) ssGetRootDWork(S);
example5_Parameters *example5_P = (example5_Parameters *) ssGetDefaultParam(S);
/* Level1 S-Function Block: <S5>/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) - '<S19>/Buffer' */
/* Copy ICs into circular buffer */
{
const int_T bufLenBytes = 2048 * sizeof(real_T);
byte_T *circBufPtr = (byte_T *)&example5_DWork->Buffer_CircBuff[0];
const byte_T *icPtr = (const byte_T *)&example5_P->Buffer_IC;
int_T i = 1;
while (i-- > 0) {
MWDSP_CopyScalarICs(circBufPtr, icPtr, 1024, sizeof(real_T));
circBufPtr += bufLenBytes;
}
}
/* Initialize DWork for IN_BUF_PTR and OUT_BUF_PTR */
{
*&example5_DWork->Buffer_IN_BUF_PTR = (void *)( (byte_T
*)&example5_DWork->Buffer_CircBuff[0] + 1024 * sizeof(real_T) );
*&example5_DWork->Buffer_OUT_BUF_PTR = (void *)( (byte_T
*)&example5_DWork->Buffer_CircBuff[0] + 256 * sizeof(real_T) );
}
/* Calculate shiftPerElement
* (assuming that number of bits
* per element is power of two)
*/
{
int_T expn;
const double frac = frexp((double)sizeof(real_T), &expn);
*&example5_DWork->Buffer_ShiftPerElem = expn - 1;
UNUSED_ARG(frac);
}
/* DSP Blockset Filter Implementation (sdspfilter) - '<S20>/Digital Filter' */
{
real_T *statePtr = (real_T *) &example5_DWork->Digital_Filter_FILT_STATES[0];
/* Scalar expansion of ICs with extra zero element per channel */
int_T chanCount = 128;
while (chanCount--) {
int_T numElems = 19;
while (numElems--) {
*statePtr++ = *(const real_T *)&example5_P->Digital_Filter_ICRTP;
}
*statePtr++ = 0.0;
}
}
}
/* Outputs for atomic system: '<Root>/Spectrum Scope' */
void example5_Spectrum_Scope(SimStruct *S, int_T tid)
{
/* simstruct variables */
example5_BlockIO *example5_B = (example5_BlockIO *) _ssGetBlockIO(S);
example5_D_Work *example5_DWork = (example5_D_Work *) ssGetRootDWork(S);
example5_Parameters *example5_P = (example5_Parameters *) ssGetDefaultParam(S);
/* local block i/o variables */
creal_T rtb_FFT[128];
real_T rtb_S_Function;
real_T rtb_Math_Function1;
real_T rtb_Window_o1[1024];
real_T rtb_Zero_Pad[128];
if (ssIsSampleHit(S, 3, tid)) { /* Sample time: [0.016, 0.0] */
/* Level1 S-Function Block: <S5>/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) - '<S19>/Buffer' */
{
/* Copy input samples to buffer */
if (ssIsSampleHit(S, 0, tid)) {
MWDSP_Buf_CopyScalar_OL_1ch((const byte_T *)&example5_B->Inherit_Shape1_b,
(byte_T **)&example5_DWork->Buffer_IN_BUF_PTR, (byte_T
*)&example5_DWork->Buffer_CircBuff[0],
*&example5_DWork->Buffer_ShiftPerElem, 2048 * sizeof(real_T));
}
/* Copy output samples from buffer */
if (ssIsSampleHit(S, 3, tid)) {
MWDSP_Buf_OutputFrame_1ch((byte_T *)&example5_B->Buffer[0], (byte_T
**)&example5_DWork->Buffer_OUT_BUF_PTR, (byte_T
*)&example5_DWork->Buffer_CircBuff[0],
*&example5_DWork->Buffer_ShiftPerElem, 2048 * sizeof(real_T) ,1024, 256 *
sizeof(real_T));
}
}
if (ssIsSampleHit(S, 3, tid)) { /* Sample time: [0.016, 0.0] */
/* DSP Blockset Window (sdspwindow2) - '<S20>/Window' */
{
int_T i;
for (i=0; i<1024; i++) {
rtb_Window_o1[i] = example5_B->Buffer[i] * example5_B->Window_o2[i];
}
}
/* DSP Blockset Pad (sdsppad) - '<S21>/Zero Pad' */
/* Input dimensions: [1024 x 1], output dimensions: [128 x 1] */
memcpy( &rtb_Zero_Pad[0], &rtb_Window_o1[0], (128 * sizeof(real_T)) );
/* DSP Blockset FFT (sdspfft2) - '<S21>/FFT' */
/* Real input, 1 channels, 128 rows, linear output order */
/* Interleave data to prepare for real-data algorithms: */
MWDSP_FFTInterleave_BR_D(&rtb_FFT[0], &rtb_Zero_Pad[0], 1, 128);
/* Apply half-length algorithm to single real signal: */
{
creal_T *lastCol = &rtb_FFT[0]; /* Point to last column of input */
MWDSP_R2DIT_TBLS_Z(lastCol, 1, 128, 64, &example5_P->FFT_TwiddleTable[0],
2, 0); /* Radix-2 DIT FFT using TableSpeed twiddle computation */
MWDSP_DblLen_TBL_Z(lastCol, 128, &example5_P->FFT_TwiddleTable[0], 1);
}
/* Math: '<S21>/Magnitude Squared'
*
* Regarding '<S21>/Magnitude Squared':
* Op: magnitude^2
*/
{
int_T i1;
const creal_T *u0 = &rtb_FFT[0];
real_T *y0 = &example5_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) - '<S20>/Digital Filter' */
/* Filter algorithm: FIR Direct-Form (double precision floating-point) */
/* Complexities: input - real, num coeffs - real */
/* Implementing filter algorithm */
MWDSP_FIR_DF_DD(&example5_B->Magnitude_Squared[0],
&example5_B->Digital_Filter[0],
&example5_DWork->Digital_Filter_FILT_STATES[0],
&example5_DWork->Digital_Filter_DF_INDX, 20, 1, 128,
&example5_P->Digital_Filter_RTP1COEFF[0], 1);
/* S-Function Block (sdotproduct): <S24>/S-Function */
rtb_S_Function = example5_B->Window_o2[0] * example5_B->Window_o2[0];
{
int_T i1;
const real_T *u0 = &example5_B->Window_o2[1];
const real_T *u1 = &example5_B->Window_o2[1];
for (i1=0; i1 < 1023; i1++) {
rtb_S_Function += u0[i1] * u1[i1];
}
}
/* Math: '<S22>/Math Function1'
*
* Regarding '<S22>/Math Function1':
* Op: reciprocal
*/
rtb_Math_Function1 = 1.0/(rtb_S_Function);
/* Product: '<S20>/Product2' */
{
int_T i1;
const real_T *u0 = &example5_B->Digital_Filter[0];
real_T *y0 = &example5_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 example5_Spectrum_Scope_Update(SimStruct *S, int_T tid)
{
if (ssIsSampleHit(S, 3, tid)) { /* Sample time: [0.016, 0.0] */
/* Level1 S-Function Block: <S5>/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 */
example5_BlockIO *example5_B = (example5_BlockIO *) _ssGetBlockIO(S);
example5_D_Work *example5_DWork = (example5_D_Work *) ssGetRootDWork(S);
example5_Parameters *example5_P = (example5_Parameters *) ssGetDefaultParam(S);
/* local block i/o variables */
creal_T rtb_temp35;
real_T rtb_Complex_to_Real_Imag_o1;
real_T rtb_Complex_to_Real_Imag_o2;
real_T rtb_temp40;
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [8.3333333333333339E-004, 0.0] */
/* DSP Blockset Random Source (sdsprandsrc2) - '<S2>/Random Source' */
MWDSP_RandSrc_U_D((real64_T*)&rtb_temp40,&example5_P->Random_Source_a_Min,1,&example5_P->Random_Source_a_Max,1,&example5_DWork->Random_Source_a_STATE_DWORK[0],1,1);
/* Constant: '<S6>/Constant' */
example5_B->Constant = example5_P->Constant_Value;
/* RelationalOperator: '<S2>/Relational Operator' */
rtb_temp40 = (rtb_temp40 > example5_B->Constant);
/* S-Function Block: <S2>/Reshape */
example5_B->Reshape = rtb_temp40;
}
if (ssIsSampleHit(S, 1, tid)) { /* Sample time: [1.0416666666666667E-004, 0.0] */
/* DSP Blockset Delay (sdspdly2) - '<S3>/Integer Delay1' */
{
int_T ti = example5_DWork->Integer_Delay1_BUFF_OFFSET;
memcpy(&example5_B->Integer_Delay1, ((byte_T *)
&example5_DWork->Integer_Delay1_BUFF[0] + (ti*(2 * sizeof(real_T)))), (2
* sizeof(real_T)));
}
}
/* Level2 S-Function Block: <S3>/M-FSK Demodulator Baseband (scomfskdemod) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 5, SS_CALL_MDL_OUTPUTS);
/* Level2 S-Function Block: <S11>/Inherit Shape1 (scominhshape) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 6, SS_CALL_MDL_OUTPUTS);
if (ssIsSampleHit(S, 2, tid)) { /* Sample time: [8.3333333333333339E-004, 0.0] */
/* Level2 S-Function Block: <Root>/Error Rate Calculation (scomerrrate2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 7, SS_CALL_MDL_OUTPUTS);
/* Display: '<Root>/Display' */
/* Call into Simulink for Display */
ssCallAccelRunBlock(S, 1, 8, SS_CALL_MDL_OUTPUTS);
/* DSP Blockset Delay (sdspdly2) - '<Root>/Integer Delay' */
{
int_T ti = example5_DWork->Integer_Delay_BUFF_OFFSET;
memcpy(&example5_B->Integer_Delay, ((byte_T *)
&example5_DWork->Integer_Delay_BUFF[0] + (ti*sizeof(real_T))),
sizeof(real_T));
}
/* RelationalOperator: '<Root>/Relational Operator' */
example5_B->Relational_Operator_b = (example5_B->Inherit_Shape1_a !=
example5_B->Integer_Delay);
/* Scope: '<Root>/Scope' */
/* Call into Simulink for Scope */
ssCallAccelRunBlock(S, 1, 11, SS_CALL_MDL_OUTPUTS);
}
/* Level2 S-Function Block: <S4>/M-FSK Modulator Baseband (scomfskmod) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 1, 12, SS_CALL_MDL_OUTPUTS);
if (ssIsSampleHit(S, 1, tid)) { /* Sample time: [1.0416666666666667E-004, 0.0] */
/* ComplexToRealImag: '<S14>/Complex to Real-Imag1' */
example5_B->Complex_to_Real_Imag1_o1 =
example5_B->M_FSK_Modulator_Baseband.re;
example5_B->Complex_to_Real_Imag1_o2 =
example5_B->M_FSK_Modulator_Baseband.im;
/* DSP Blockset FIR Interpolation S-Function (sdspupfir2) - '<S16>/FIR Interpolation' */
{
/* Input port polyphase filtering */
MWDSP_UpFIR_DF_DblBuf_DD(&example5_B->Complex_to_Real_Imag1_o1,
(real_T *)&example5_DWork->FIR_Interpolati_a_OutBuff[0],
(real_T *)&example5_DWork->FIR_Interpolati_a_TapDelayBuff[0],
&example5_P->FIR_Interpolati_a_FILTER_COEFF[0],
&example5_DWork->FIR_Interpolati_a_TapDelayIndex,
&example5_DWork->FIR_Interpolati_a_wrtBufIdx,
1,
1,
1,
5,
1);
/* Output port buffer processing */
MWDSP_UpFIR_CopyDataToOutPort((byte_T
*)&example5_DWork->FIR_Interpolati_a_OutBuff[0],
(byte_T *)&example5_B->FIR_Interpolati_a,
&example5_DWork->FIR_Interpolati_a_ReadIdx,
1,
1,
sizeof(real_T),
1 * sizeof(real_T),
1,
1 * sizeof(real_T),
0 * sizeof(real_T),
2);
}
/* DSP Blockset FIR Interpolation S-Function (sdspupfir2) - '<S16>/FIR Interpolation1' */
{
/* Input port polyphase filtering */
MWDSP_UpFIR_DF_DblBuf_DD(&example5_B->FIR_Interpolati_a,
(real_T *)&example5_DWork->FIR_Interpolati_b_OutBuff[0],
(real_T *)&example5_DWork->FIR_Interpolati_b_TapDelayBuff[0],
&example5_P->FIR_Interpolati_b_FILTER_COEFF[0],
&example5_DWork->FIR_Interpolati_b_TapDelayIndex,
&example5_DWork->FIR_Interpolati_b_wrtBufIdx,
1,
1,
1,
5,
1);
/* Output port buffer processing */
MWDSP_UpFIR_CopyDataToOutPort((byte_T
*)&example5_DWork->FIR_Interpolati_b_OutBuff[0],
(byte_T *)&example5_B->FIR_Interpolati_b,
&example5_DWork->FIR_Interpolati_b_ReadIdx,
1,
1,
sizeof(real_T),
1 * sizeof(real_T),
1,
1 * sizeof(real_T),
0 * sizeof(real_T),
2);
}
}
/* DSP Blockset FIR Interpolation S-Function (sdspupfir2) - '<S16>/FIR Interpolation2' */
{
/* Input port polyphase filtering */
if (ssIsSampleHit(S, 1, tid))
MWDSP_UpFIR_DF_DblBuf_DD(&example5_B->FIR_Interpolati_b,
(real_T *)&example5_DWork->FIR_Interpolati_c_OutBuff[0],
(real_T *)&example5_DWork->FIR_Interpolati_c_TapDelayBuff[0],
&example5_P->FIR_Interpolati_c_FILTER_COEFF[0],
&example5_DWork->FIR_Interpolati_c_TapDelayIndex,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -