[C] 纯文本查看 复制代码
/*
* File: stm32f4discovery_cmsis_crl.c
*
* Code generated for Simulink model 'stm32f4discovery_cmsis_crl'.
*
* Model version : 1.34
* Simulink Coder version : 8.14 (R2018a) 06-Feb-2018
* C/C++ source code generated on : Wed Mar 23 18:43:39 2022
*
* Target selection: ert.tlc
* Embedded hardware selection: ARM Compatible->ARM Cortex
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "stm32f4discovery_cmsis_crl.h"
#include "stm32f4discovery_cmsis_crl_private.h"
/* Block signals (default storage) */
B_stm32f4discovery_cmsis_crl_T stm32f4discovery_cmsis_crl_B;
/* Block states (default storage) */
DW_stm32f4discovery_cmsis_crl_T stm32f4discovery_cmsis_crl_DW;
/* Real-time model */
RT_MODEL_stm32f4discovery_cms_T stm32f4discovery_cmsis_crl_M_;
RT_MODEL_stm32f4discovery_cms_T *const stm32f4discovery_cmsis_crl_M =
&stm32f4discovery_cmsis_crl_M_;
void RandSrc_GZ_R(real32_T y[], const real32_T mean[], int32_T meanLen, const
real32_T xstd[], int32_T xstdLen, uint32_T state[], int32_T
nChans, int32_T nSamps)
{
int32_T i;
int32_T j;
real32_T r;
real32_T x;
real32_T s;
real32_T y_0;
int32_T chan;
uint32_T icng;
uint32_T jsr;
int32_T samp;
static const real32_T vt[65] = { 0.340945F, 0.45731461F, 0.539779305F,
0.606242716F, 0.663169086F, 0.713697493F, 0.759612501F, 0.80203563F,
0.841722727F, 0.879210174F, 0.914894819F, 0.949079096F, 0.98200053F,
1.01384926F, 1.04478097F, 1.07492542F, 1.10439169F, 1.13327384F, 1.16165304F,
1.18960094F, 1.21718144F, 1.24445164F, 1.27146351F, 1.29826498F, 1.32490075F,
1.35141253F, 1.37783992F, 1.40422106F, 1.43059289F, 1.45699155F, 1.48345268F,
1.51001215F, 1.53670609F, 1.56357121F, 1.59064543F, 1.61796796F, 1.64558017F,
1.67352545F, 1.7018503F, 1.73060453F, 1.75984216F, 1.78962231F, 1.82001F,
1.85107696F, 1.88290441F, 1.91558313F, 1.9492166F, 1.98392391F, 2.0198431F,
2.05713558F, 2.09599304F, 2.13664508F, 2.17937136F, 2.22451758F, 2.27251863F,
2.32393384F, 2.37950087F, 2.44022179F, 2.50751162F, 2.58346581F, 2.67139149F,
2.77699423F, 2.77699423F, 2.77699423F, 2.77699423F };
/* S-Function (sdsprandsrc2): '<Root>/Random Source' */
/* RandSrc_GZ_R */
for (chan = 0; chan < nChans; chan++) {
icng = state[chan << 1];
jsr = state[(chan << 1) + 1];
for (samp = 0; samp < nSamps; samp++) {
icng = 69069U * icng + 1234567U;
jsr ^= jsr << 13;
jsr ^= jsr >> 17;
jsr ^= jsr << 5;
i = (int32_T)(icng + jsr);
j = (i & 63) + 1;
r = (real32_T)i * 4.65661287E-10F * vt[j];
if (!((real32_T)fabs(r) <= vt[j - 1])) {
x = ((real32_T)fabs(r) - vt[j - 1]) / (vt[j] - vt[j - 1]);
icng = 69069U * icng + 1234567U;
jsr ^= jsr << 13;
jsr ^= jsr >> 17;
jsr ^= jsr << 5;
y_0 = (real32_T)(int32_T)(icng + jsr) * 2.32830644E-10F + 0.5F;
s = x + y_0;
if (s > 1.30119801F) {
r = r < 0.0F ? 0.487899214F * x - 0.487899214F : 0.487899214F -
0.487899214F * x;
} else {
if (!(s <= 0.96892792F)) {
x = 0.487899214F - 0.487899214F * x;
if (y_0 > 12.6770601F - (real32_T)exp(-0.5F * x * x) * 12.3758602F)
{
r = r < 0.0F ? -x : x;
} else {
if (!((real32_T)exp(-0.5F * vt[j] * vt[j]) + y_0 * 0.0195830297F /
vt[j] <= (real32_T)exp(-0.5F * r * r))) {
do {
icng = 69069U * icng + 1234567U;
jsr ^= jsr << 13;
jsr ^= jsr >> 17;
jsr ^= jsr << 5;
x = (real32_T)log((real32_T)(int32_T)(icng + jsr) *
2.32830644E-10F + 0.5F) / 2.77699399F;
icng = 69069U * icng + 1234567U;
jsr ^= jsr << 13;
jsr ^= jsr >> 17;
jsr ^= jsr << 5;
} while ((real32_T)log((real32_T)(int32_T)(icng + jsr) *
2.32830644E-10F + 0.5F) * -2.0F <= x * x);
r = r < 0.0F ? x - 2.77699399F : 2.77699399F - x;
}
}
}
}
}
y[chan * nSamps + samp] = xstd[xstdLen > 1 ? chan : 0] * r + mean[meanLen >
1 ? chan : 0];
}
state[chan << 1] = icng;
state[(chan << 1) + 1] = jsr;
}
/* End of S-Function (sdsprandsrc2): '<Root>/Random Source' */
}
void RandSrcInitState_GZ(const uint32_T seed[], uint32_T state[], int32_T nChans)
{
int32_T i;
/* InitializeConditions for S-Function (sdsprandsrc2): '<Root>/Random Source' */
/* RandSrcInitState_GZ */
for (i = 0; i < nChans; i++) {
state[i << 1] = 362436069U;
state[(i << 1) + 1] = seed[i] == 0U ? 521288629U : seed[i];
}
/* End of InitializeConditions for S-Function (sdsprandsrc2): '<Root>/Random Source' */
}
/* Model step function */
void stm32f4discovery_cmsis_crl_step(void)
{
real32_T updateVal;
int32_T j;
/* S-Function (sdspsine2): '<Root>/Sine Wave' */
updateVal = stm32f4discovery_cmsis_crl_P.SineWave_Frequency * 0.000785398181F;
for (j = 0; j < 75; j++) {
/* Update accumulated normalized freq value
for next sample. Keep in range [0 2*pi) */
stm32f4discovery_cmsis_crl_DW.SineWave_AccFreqNorm += updateVal;
if (stm32f4discovery_cmsis_crl_DW.SineWave_AccFreqNorm >= 6.28318548F) {
stm32f4discovery_cmsis_crl_DW.SineWave_AccFreqNorm -= 6.28318548F;
} else {
if (stm32f4discovery_cmsis_crl_DW.SineWave_AccFreqNorm < 0.0F) {
stm32f4discovery_cmsis_crl_DW.SineWave_AccFreqNorm += 6.28318548F;
}
}
}
/* End of S-Function (sdspsine2): '<Root>/Sine Wave' */
/* S-Function (sdspsine2): '<Root>/Sine Wave1' */
updateVal = stm32f4discovery_cmsis_crl_P.SineWave1_Frequency * 0.000785398181F;
for (j = 0; j < 75; j++) {
/* Update accumulated normalized freq value
for next sample. Keep in range [0 2*pi) */
stm32f4discovery_cmsis_crl_DW.SineWave1_AccFreqNorm += updateVal;
if (stm32f4discovery_cmsis_crl_DW.SineWave1_AccFreqNorm >= 6.28318548F) {
stm32f4discovery_cmsis_crl_DW.SineWave1_AccFreqNorm -= 6.28318548F;
} else {
if (stm32f4discovery_cmsis_crl_DW.SineWave1_AccFreqNorm < 0.0F) {
stm32f4discovery_cmsis_crl_DW.SineWave1_AccFreqNorm += 6.28318548F;
}
}
}
/* End of S-Function (sdspsine2): '<Root>/Sine Wave1' */
/* S-Function (sdsprandsrc2): '<Root>/Random Source' */
RandSrc_GZ_R(stm32f4discovery_cmsis_crl_B.RandomSource,
&stm32f4discovery_cmsis_crl_P.RandomSource_MeanVal, 1,
&stm32f4discovery_cmsis_crl_P.RandomSource_VarianceRTP, 1,
stm32f4discovery_cmsis_crl_DW.RandomSource_STATE_DWORK, 1, 75);
}
/* Model initialize function */
void stm32f4discovery_cmsis_crl_initialize(void)
{
/* Registration code */
/* initialize error status */
rtmSetErrorStatus(stm32f4discovery_cmsis_crl_M, (NULL));
/* states (dwork) */
(void) memset((void *)&stm32f4discovery_cmsis_crl_DW, 0,
sizeof(DW_stm32f4discovery_cmsis_crl_T));
{
real32_T arg;
/* Start for S-Function (sdspsine2): '<Root>/Sine Wave' */
/* Trigonometric mode: compute accumulated
normalized trig fcn argument for each channel */
/* Keep normalized value in range [0 2*pi) */
arg = (real32_T)fmod(stm32f4discovery_cmsis_crl_P.SineWave_Phase,
6.2831854820251465);
if (arg < 0.0F) {
arg += 6.28318548F;
}
stm32f4discovery_cmsis_crl_DW.SineWave_AccFreqNorm = arg;
/* End of Start for S-Function (sdspsine2): '<Root>/Sine Wave' */
/* Start for S-Function (sdspsine2): '<Root>/Sine Wave1' */
/* Trigonometric mode: compute accumulated
normalized trig fcn argument for each channel */
/* Keep normalized value in range [0 2*pi) */
arg = (real32_T)fmod(stm32f4discovery_cmsis_crl_P.SineWave1_Phase,
6.2831854820251465);
if (arg < 0.0F) {
arg += 6.28318548F;
}
stm32f4discovery_cmsis_crl_DW.SineWave1_AccFreqNorm = arg;
/* End of Start for S-Function (sdspsine2): '<Root>/Sine Wave1' */
/* InitializeConditions for S-Function (sdspsine2): '<Root>/Sine Wave' */
/* This code only executes when block is re-enabled in an
enabled subsystem when the enabled subsystem states on
re-enabling are set to 'Reset' */
/* Reset to time zero on re-enable */
/* Trigonometric mode: compute accumulated
normalized trig fcn argument for each channel */
/* Keep normalized value in range [0 2*pi) */
arg = (real32_T)fmod(stm32f4discovery_cmsis_crl_P.SineWave_Phase,
6.2831854820251465);
if (arg < 0.0F) {
arg += 6.28318548F;
}
stm32f4discovery_cmsis_crl_DW.SineWave_AccFreqNorm = arg;
/* End of InitializeConditions for S-Function (sdspsine2): '<Root>/Sine Wave' */
/* InitializeConditions for S-Function (sdspsine2): '<Root>/Sine Wave1' */
/* This code only executes when block is re-enabled in an
enabled subsystem when the enabled subsystem states on
re-enabling are set to 'Reset' */
/* Reset to time zero on re-enable */
/* Trigonometric mode: compute accumulated
normalized trig fcn argument for each channel */
/* Keep normalized value in range [0 2*pi) */
arg = (real32_T)fmod(stm32f4discovery_cmsis_crl_P.SineWave1_Phase,
6.2831854820251465);
if (arg < 0.0F) {
arg += 6.28318548F;
}
stm32f4discovery_cmsis_crl_DW.SineWave1_AccFreqNorm = arg;
/* End of InitializeConditions for S-Function (sdspsine2): '<Root>/Sine Wave1' */
/* InitializeConditions for S-Function (sdsprandsrc2): '<Root>/Random Source' */
RandSrcInitState_GZ(&stm32f4discovery_cmsis_crl_P.RandomSource_rawSeed,
stm32f4discovery_cmsis_crl_DW.RandomSource_STATE_DWORK,
1);
}
}
/* Model terminate function */
void stm32f4discovery_cmsis_crl_terminate(void)
{
/* (no terminate code required) */
}
/*
* File trailer for generated code.
*
* [EOF]
*/