Worrying Weirdness
Posted: Thu Apr 18, 2013 8:27 pm
I got past all the RS232 weirdness and my project has grown greatly without issue. I took Ben's advice and stripped as much code as I can out of the RS232 interrupts. That worked well. Much time past without issue but today I found a new gremlin, or maybe it's the same old one. With some very minor changes (just tidying up unused variables) my RS232 output started to be corrupt. After looking at all the sensible thing I started to put back the variables. I found one string variable whose presence dictates whether the code works or not. With it, it works, without, it doesn't. This variable is not being used anywhere. It is just declared[20] and set to "". It does not matter if I change the name but it stops working if it is too big [200] or too small [2]. I can also change it to a ULONG and it still works but smaller vars do not. Obviously this is something to do with the stack or space it consumes but I still have about 25% free ram, lots of rom and about half the heap left. I am not assuming this is RS232 related this time. I have a routine that converts ASCII encoded hex to an int to be transmitted via SendRS232Char and that routine seems to be where things go wrong (the output top 4 bits are varied, though not correct, but the bottom 4 bits are stuck stuck at 8. I suspect this routine because it creates a byte from two ascii hex chars). The routine has worked just fine for weeks. Having something flaky like this happening without having a solid cause and effect worries me for the reliability of my code. I'd really like to get to the bottom of it. Oh, and the code compiles fine, just the usual
Due to IP concerns I cannot attach the whole program anymore, but here is the routine that I suspect falls over with and without the var:
Any ideas?
TIA
which I don't know how to avoid.Serious Warning: Possible sw stack corruption, function 'delay_us' called by more than one asynchronous thread (main/Task, interrupt, interrupt low)
Due to IP concerns I cannot attach the whole program anymore, but here is the routine that I suspect falls over with and without the var:
Code: Select all
MX_UINT8 FCM_Hex2Int(MX_CHAR* PFCL_HEX2_INT_STR)
{
//Local variable definitions
MX_UINT8 FCL_LENGTH;
MX_UINT8 FCL_COUNT = (0x0);
MX_UINT8 FCL_INT_VALUE = (0x0);
MX_UINT8 FCL_INT_CONVERSION = (0x0);
MX_UINT8 FCL_INT_VAR = (0x0);
MX_UINT8 FCL_INDEX = (0x0);
#define FC_SZ_HEX2_INT_STR 20
MX_UINT8 FCL_HEX2_INT_STR[FC_SZ_HEX2_INT_STR];
FCI_CONCATENATE(PFCL_HEX2_INT_STR,FC_SZ_HEX2_INT_STR,"",0,FCL_HEX2_INT_STR,FC_SZ_HEX2_INT_STR);
MX_UINT8 FCR_RETVAL;
//String Manipulation
//Calculation:
// .length = Length$ (.hex2_int_str)
FCL_LENGTH = FCI_GETLENGTH(FCL_HEX2_INT_STR, FC_SZ_HEX2_INT_STR);
//Calculation
//Calculation:
// .count = 0
// .int_value = 0
// .int_conversion = 0
FCL_COUNT = 0;
FCL_INT_VALUE = 0;
FCL_INT_CONVERSION = 0;
//Loop
//Loop: While .count < .length
while (1)
{
//Calculation
//Calculation:
// .int_var = (.length - .count) - 1
FCL_INT_VAR = (FCL_LENGTH - FCL_COUNT) - 1;
//Calculation
//Calculation:
// .index = (.length - .count) - 1
// .int_var = .hex2_int_str[.index]
FCL_INDEX = (FCL_LENGTH - FCL_COUNT) - 1;
FCL_INT_VAR = FCL_HEX2_INT_STR[FCL_INDEX];
//Decision
//Decision: .int_var > 64?
if (FCL_INT_VAR > 64)
{
//Calculation
//Calculation:
// .int_var = .int_var - 55
FCL_INT_VAR = FCL_INT_VAR - 55;
} else {
//Calculation
//Calculation:
// .int_var = .int_var - 48
FCL_INT_VAR = FCL_INT_VAR - 48;
}
//Calculation
//Calculation:
// .int_value = .int_var << .count * 4
// .int_conversion = .int_conversion + .int_value
FCL_INT_VALUE = FCL_INT_VAR << FCL_COUNT * 4;
FCL_INT_CONVERSION = FCL_INT_CONVERSION + FCL_INT_VALUE;
//Calculation
//Calculation:
// .count = .count + 1
FCL_COUNT = FCL_COUNT + 1;
if ((FCL_COUNT < FCL_LENGTH) == 0) break;
}
//Calculation
//Calculation:
// .Return = .int_conversion
FCR_RETVAL = FCL_INT_CONVERSION;
return (FCR_RETVAL);
//Local variable definitions
#undef FC_SZ_HEX2_INT_STR
}
TIA