📄 gmsksimulation_acc.c
字号:
creal_T *rxSym = &((D_Work *) ssGetRootDWork(S))->RxSym;
creal_T *refSym = &((D_Work *) ssGetRootDWork(S))->RefSym[0];
real_T *metricVec = &((D_Work *) ssGetRootDWork(S))->MetricVec[0];
real_T *pathMemMetric = &((D_Work *) ssGetRootDWork(S))->PathMemMetric
[0];
real_T *tmpPathMemMetric = &((D_Work *) ssGetRootDWork(S))
->TmpPMemMetric[0];
int32_T *inBuffDTAvail = &((D_Work *) ssGetRootDWork(S))
->InBuffDtAvail;
creal_T *inputBuff = &((D_Work *) ssGetRootDWork(S))->InputBuff[0];
int32_T *outputBuff = &((D_Work *) ssGetRootDWork(S))->OutputBuff[0];
boolean_T *decTB = &((D_Work *) ssGetRootDWork(S))->DecTBack;
int32_T *decPathPos = &((D_Work *) ssGetRootDWork(S))->DecPathPos;
int32_T *decStMemInput = &((D_Work *) ssGetRootDWork(S))
->DecStMemInput[0];
int32_T *decStMemPrevSt = &((D_Work *) ssGetRootDWork(S))
->DecStMemPrevSt[0];
creal_T *trOut = &((D_Work *) ssGetRootDWork(S))->TrOutput[0];
real_T *trNxtPhase = &((D_Work *) ssGetRootDWork(S))->TrNxtPhase[0];
int32_T *trInput = &((D_Work *) ssGetRootDWork(S))->TrInput[0];
int32_T stateIdx, nextPosIdx, survivorPath= 0, symIdx;
/* Maximum metric used to scale metrics and to determine survivor */
real_T maxMetric = MIN_METRIC;
/* --- Decode the required number of symbols */
for (symIdx=0; inBuffDTAvail[0] >= 1; symIdx++) {
readBuffer( (void *)inputBuff, (void *)rxSym, 1,
&((D_Work *) ssGetRootDWork(S))->InBuffBotIdx,
inBuffDTAvail,
2, sizeof(creal_T) );
/* --- Move the next pointer forward */
nextPosIdx = (decPathPos[0]+1) % 5;
/* --- Determine the transitions from each state and determine the survivor */
for (stateIdx=0; stateIdx < 32; stateIdx++) {
real_T tempMetric;
int32_T inputIdx, idx;
/* --- Create the array of reference pointers */
for (inputIdx = 0; inputIdx < 2; inputIdx++) {
for (idx = 0; idx < 1; idx++) {
refSym[inputIdx * 1 + idx].re = trOut[stateIdx* 2 + inputIdx *
1 + idx].re;
refSym[inputIdx * 1 + idx].im = trOut[stateIdx* 2 + inputIdx *
1 + idx].im;
}
}
/* Compute Metric */
for (inputIdx=0; inputIdx < 2; inputIdx++) {
real_T tempSum = 0;
for (idx=0; idx < 1; idx++) {
tempSum += rxSym[idx].re * refSym[inputIdx * 1 + idx].re +
rxSym[idx].im * refSym[inputIdx * 1 + idx].im;
}
metricVec[inputIdx] = tempSum;
}
tempMetric = pathMemMetric[stateIdx];
for (inputIdx=0; inputIdx< 2; inputIdx++) {
int32_T nextStateIdx;
nextStateIdx = (int32_T) trNxtPhase[stateIdx*2 + inputIdx];
if (tempMetric + metricVec[inputIdx] > tmpPathMemMetric
[nextStateIdx]) {
int32_T stateMemIdx;
stateMemIdx = nextPosIdx * 32 + nextStateIdx;
tmpPathMemMetric[nextStateIdx] = tempMetric + metricVec
[inputIdx];
decStMemInput[stateMemIdx] = trInput[stateIdx* 2 + inputIdx];
decStMemPrevSt[stateMemIdx] = stateIdx;
/* --- Track the maximum value of the metric and store the state in */
/* which the maximum was found. */
if (tmpPathMemMetric[nextStateIdx] > maxMetric) {
maxMetric = tmpPathMemMetric[nextStateIdx];
survivorPath = nextStateIdx;
}
}
} /* end inputIdx loop */
} /* end stateIdx loop */
/* --- The temporary path metrics become the current metrics */
/* Temporary path metrics are cleared */
for (stateIdx=0; stateIdx< 32; stateIdx++) {
pathMemMetric[stateIdx] = tmpPathMemMetric[stateIdx];
tmpPathMemMetric[stateIdx] = MIN_METRIC;
/* --- Rescale the metrics */
pathMemMetric[stateIdx] -= maxMetric;
pathMemMetric[stateIdx] = MAX(pathMemMetric[stateIdx], MIN_METRIC);
}
maxMetric = MIN_METRIC; /* Reset the maximum value for the next pass */
/* --- Update the postion in the trellis */
decPathPos[0] = nextPosIdx;
if (decPathPos[0] >= 4) {
decTB[0] = true;
}
/* --- Traceback if required */
if (decTB[0]) {
int32_T currentStateIdx, prevStateIdx, stateMemIdx= 0, tbIdx;
int32_T outputSym;
prevStateIdx = survivorPath;
for (tbIdx=0; tbIdx <= 4; tbIdx++) {
int32_T tempPosIdx;
tempPosIdx = decPathPos[0]-tbIdx;
tempPosIdx = (tempPosIdx < 0) ? tempPosIdx + 5 : tempPosIdx;
stateMemIdx = (tempPosIdx * 32) + prevStateIdx;
currentStateIdx = prevStateIdx;
prevStateIdx = decStMemPrevSt[stateMemIdx];
}
outputSym = decStMemInput[stateMemIdx];
writeBuffer( (void *)outputBuff, (const void *)&outputSym, 1,
&((D_Work *) ssGetRootDWork(S))->OutBuffTopIdx,
&((D_Work *) ssGetRootDWork(S))->OutBuffDtAvail,
8, sizeof(int32_T) );
}
} /* end for symIdx */
}
}
{
real_T *output = &((BlockIO *) _ssGetBlockIO(S))->B_0_6_0;
int32_T *outputBuff = &((D_Work *) ssGetRootDWork(S))->OutputBuff[0];
int32_T *tmpOutSymbols = &((D_Work *) ssGetRootDWork(S))->TmpOutSymbols;
readBuffer( (void *)outputBuff, (void *)tmpOutSymbols, 1,
&((D_Work *) ssGetRootDWork(S))->OutBuffBotIdx,
&((D_Work *) ssGetRootDWork(S))->OutBuffDtAvail,
8, sizeof(int32_T) );
/* Perform the bit conversion */
{
int32_T i;
for (i = 0; i < 1; i++) {
int32_T j, count, inNum;
inNum = (tmpOutSymbols[i] + 1)/2;
count = (i * 1) + 0;
if (inNum >= 0) {
for (j = 0; j < 1; j++) {
output[count] = (real_T) (inNum % 2);
inNum /= 2;
count--;
}
}
} /* end for i */
}
}
}
}
/* Level2 S-Function Block: '<Root>/B_0_6' (scomerrrate2) */
/* Call into Simulink for MEX-version of S-function */
ssCallAccelRunBlock(S, 0, 7, SS_CALL_MDL_OUTPUTS);
/* tid is required for a uniform function interface. This system
* is single rate, and in this case, tid is not accessed. */
UNUSED_PARAMETER(tid);
}
/* Update for root system: '<Root>' */
#define MDL_UPDATE
static void mdlUpdate(SimStruct *S, int_T tid)
{
/* tid is required for a uniform function interface. This system
* is single rate, and in this case, tid is not accessed. */
UNUSED_PARAMETER(tid);
}
/* Function to initialize sizes */
static void mdlInitializeSizes(SimStruct *S)
{
/* checksum */
ssSetChecksumVal(S, 0, 3140260219U);
ssSetChecksumVal(S, 1, 3970174456U);
ssSetChecksumVal(S, 2, 3435823168U);
ssSetChecksumVal(S, 3, 271671709U);
/* options */
ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
/* Accelerator check memory map size match for DWork */
if (ssGetSizeofDWork(S) != sizeof(D_Work)) {
ssSetErrorStatus(S,"Unexpected error: Internal DWork sizes do "
"not match for accelerator mex file.");
}
/* Accelerator check memory map size match for BlockIO */
if (ssGetSizeofGlobalBlockIO(S) != sizeof(BlockIO)) {
ssSetErrorStatus(S,"Unexpected error: Internal BlockIO sizes do "
"not match for accelerator mex file.");
}
/* model parameters */
_ssSetDefaultParam(S, (real_T *) &rtDefaultParameters);
/* non-finites */
rt_InitInfAndNaN(sizeof(real_T));
}
/* Empty mdlInitializeSampleTimes function (never called) */
static void mdlInitializeSampleTimes(SimStruct *S)
{
}
/* Empty mdlTerminate function (never called) */
static void mdlTerminate(SimStruct *S)
{
}
/* MATLAB MEX Glue */
#include "simulink.c"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -