We have encountered an issue with our TinyOS application dealing with an array declaration inside of a command. Specifically, if we size the array as a parameter to the command call, the application compiles properly but is broken in its operation, even if the aforementioned command is not called at runtime. If we size the same array as a constant (255), making no other changes, we find our application to operate properly and completely. We use parameter based array sizes throughout the rest of the app without any problems.
Below is the offending command, the "sortedData" array is the array in question.
<code>
command uint8_t Feature.calculate(int16_t** data, uint8_t channelMask, uint16_t dataLen, int8_t* result) {
uint8_t i;
uint8_t mask = 0x08;
uint8_t rChCount = 0;
int16_t sortedData[255]; // TODO: understand why this array ( only here ) must by statically sized
int32_t tmpResult;
for (i = 0; i<MAX_VALUE_TYPES; i++)
if ( (channelMask & (mask>>i)) == (mask>>i)) {
memcpy(sortedData, data[i], (dataLen * sizeof(int16_t)) );
call Sort.mergeSort(sortedData, dataLen, 0, dataLen-1);
tmpResult = (dataLen%2 == 0)? (sortedData[dataLen/2] + sortedData[(dataLen/2)-1])/2 : sortedData[(dataLen-1)/2];
((uint16_t *) result)[rChCount++] = (uint16_t)tmpResult;
}
return channelMask;
}
</code>
NesC implementation file containing example code