2015-12-28 02:14 AM
Good morning,
I have a strange problem with the FreeGCC compiler installed with the release 4.0 of SPC5Studio. The following code give me an internal compielr error: segmentation faultif (*ubReadWinIndex != 255)
{
/* In the precedent reading cycle I have already found where it is the reading window. */
ulVoltage = ulPendingValues[*ubReadWinIndex];
*ubReadWinIndex = 255;
}
else
{
/* Analyse wave. */
UBYTE i = 1;
for (i = 1; i <= SAMPLES; i++)
{
ULONG y1 = ulPendingValues[i-1];
ULONG y2 = ulPendingValues[i];
/* Approximation of derivative calculated on a delta time of 20 milliseconds, as the span between measures. */
SLONG der = (y2-y1) / TIME_SPAN_IN_SAMPLES;
if (der >= POSITIVE_DERIVATIVE)
{
/* Found a rising front. The signal is flashing. */
isFlashing = TRUE;
systemStatus->ubReadingStatus = FLASHING_SIGNAL;
/* Reading window is after 250 ms*/
*ubReadWinIndex = i + READING_WINDOW;
if (*ubReadWinIndex <= SAMPLES)
{
/* Read the value*/
ulVoltage = ulPendingValues[*ubReadWinIndex];
*ubReadWinIndex = 255;
isToCheck = TRUE;
}
else
{
/* Reading window in the next 500ms. */
*ubReadWinIndex = 25 - *ubReadWinIndex;
isToCheck = FALSE;
}
break;
}
else if (der <= NEGATIVE_DERIVATIVE)
{
isFlashing = TRUE;
}
}
/* If the wave is not flashing, the signal is fixed. */
if(!isFlashing)
{
systemStatus->ubReadingStatus = FIXED_SIGNAL;
ulVoltage = ulPendingValues[READING_WINDOW];
isToCheck = TRUE;
}
}
The code is not yet elegant (it's a first implementation). It analyze a input wave and search the presence of derivative to identify the shape of this wave (continuous or ''flashing'').
The problem is that this code, with the trial version of the HighTech compiler, compile.
The new installed FreeGCC error give me a segmentation fault of the compiler in the last if [if(!isFlashing)].
The strange thing is that if I rmeove the check on the condition
/* If the wave is not flashing, the signal is fixed. */
//if(!isFlashing)
//{
systemStatus->ubReadingStatus = FIXED_SIGNAL;
ulVoltage = ulPendingValues[READING_WINDOW];
isToCheck = TRUE;
//}
then the code compile.
I can also compile if I comment the for cycle.
As I already said, the problem arose when I changed compiler. I cannot see where the problem is.
Thank you.
#compiler-segmentation-fault
2016-01-04 02:00 AM
Hello Ivan ,
Could you confirm your options settings ? Did you use ''-O2'' options ? could you try ''-O0'' options ? Best Regards Erwan2016-01-19 08:00 AM
Hello wan35fr,
I tried your solution and it works like a charm.Thank you very much. By the way, do you happen to know why this happens?2016-01-20 12:15 AM