strange loop behavior
Posted: Mon Oct 22, 2018 8:24 pm
Hello,
This problem is so bizarre I thought not to post here as I must be doing something obviously wrong, although I cannot myself figure out what.
I have a "for" loop that erroneously never ends when an array variable of type "mic_array_frame_time_domain" is accessed inside the loop. When I comment out the variable's access the loop ends as expected. I can also force the loop to end by putting a test of the index inside the loop and breaking on the desired index value. I can access and modfiy other variables in the loop with no problem.
This is occurring in code I have based on the low resolution delay example (AN00219), modified to work with different hardware and different parameters. The basic problem looks as follows (with "nSamp" the index and "current" the variable showing the bizarre behavior):
The problem doesn't matter how the offending variable is used. For example, copying the variable to another variable or incrementing the variable's value will also cause the loop to run longer than expected, although in the latter case the loop stops when a memory access exception is thrown (albeit with the index far beyond the intended stop value).
This is running in a region marked unsafe.
My flag settings are XCC_FLAGS = -O2 -g -report.
The variable is typedef-ed in lib_mic_array.h:
I know there are other ways to exchange data as I need to do, but either something's horribly wrong or I fundamentally don't understand something (probably the latter) and I believe there's something for me to learn here.
I would be grateful if anyone could suggest something to pursue.
Sincerely,
Bill
This problem is so bizarre I thought not to post here as I must be doing something obviously wrong, although I cannot myself figure out what.
I have a "for" loop that erroneously never ends when an array variable of type "mic_array_frame_time_domain" is accessed inside the loop. When I comment out the variable's access the loop ends as expected. I can also force the loop to end by putting a test of the index inside the loop and breaking on the desired index value. I can access and modfiy other variables in the loop with no problem.
This is occurring in code I have based on the low resolution delay example (AN00219), modified to work with different hardware and different parameters. The basic problem looks as follows (with "nSamp" the index and "current" the variable showing the bizarre behavior):
Code: Select all
while(1)
{
mic_array_frame_time_domain * current = mic_array_get_next_time_domain_frame(c_ds_output, DECIMATOR_COUNT, buffer, audio, dc);
for(uint8_t nMic = 0; nMic < MIC_ARRAY_NUM_MICS; nMic++)
{
for(uint8_t nSamp = 0; nSamp < (uint8_t)FRAME_SIZE; nSamp++)
{
c_audio <: current->data[nMic][nSamp]; // send the audio data out over the channel.
}
}
}
// etc. ...
This is running in a region marked unsafe.
My flag settings are XCC_FLAGS = -O2 -g -report.
The variable is typedef-ed in lib_mic_array.h:
Code: Select all
typedef struct {
long long alignment; /**<Used to force double work alignment. */
#if MIC_ARRAY_WORD_LENGTH_SHORT
int16_t data[MIC_ARRAY_NUM_MICS][1<<MIC_ARRAY_MAX_FRAME_SIZE_LOG2];/**< Raw audio data*/
#else
int32_t data[MIC_ARRAY_NUM_MICS][1<<MIC_ARRAY_MAX_FRAME_SIZE_LOG2];/**< Raw audio data*/
#endif
mic_array_metadata_t metadata[(MIC_ARRAY_NUM_MICS+3)/4]; /**< Frame metadata*/
} mic_array_frame_time_domain;
I would be grateful if anyone could suggest something to pursue.
Sincerely,
Bill