This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hey all. A potential problem with the WDOG_clearCounter function in "sw/drivers/wdog/src/32b/f28x/f2806x/wdog.h" is that it's definition is;
void WDOG_clearCounter(WDOG_Handle wdogHandle)
{
WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
// write first sequence
wdog->WDKEY = 0x55;
// write second sequence
wdog->WDKEY = 0xAA;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of WDOG_clearCounter() function
When compiler optimizations are enabled the first write to WDKEY (0x55) can be removed, causing the WDT to trigger a reset. A potential way to solve this (that results in as little overhead as possible) is to change the definition to
void WDOG_clearCounter(WDOG_Handle wdogHandle)
{
volatile WDOG_Obj *wdog = (WDOG_Obj *)wdogHandle;
ENABLE_PROTECTED_REGISTER_WRITE_MODE;
// write first sequence
wdog->WDKEY = 0x55;
// write second sequence
wdog->WDKEY = 0xAA;
DISABLE_PROTECTED_REGISTER_WRITE_MODE;
return;
} // end of WDOG_clearCounter() function
Which ensures both writes are performed. Can someone verify/update this?
thanks, Jonathan. Let us look at this one.
BTW - if you post InstaSPIN/MotorWare topics in the InstaSPIN sub-forum you will be assured I am notified.
Jonathan,
Thanks for bringing this to our attention. I agree that this could be potentially be optimized out, but I'd like to ask if you've actually observed this?
I spent a few mins trying to recreate this with varying optimization levels and was unsuccessful. Declaring the struct as volatile should mitigate any potential issues nonetheless.
Regards,
Chris; OK, I'll keep that in mind!
Trey; Yes, I have noticed that the compiler did remove the initial statement. I'm using the TI 6.1.3 compiler for the C2000 family (controlStick Piccolo 28069 in particular) and I noticed this issue with the compiler flags;
-v28 -ml -mt -O4 -g --define=FAST_ROM_V1p6 --diag_warning=225 --display_error_number --diag_wrap=off --fp_reassoc=on --fp_mode=relaxed
When compiling when the struct is not defined as volatile the WDOG_clearCounter function generates the following assembly code;
61 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
00c77d: 7622 EALLOW
67 wdog->WDKEY = 0xAA;
00c77e: 56BFAADC MOVB *+XAR4[3], #0xaa, UNC
69 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
00c780: 761A EDIS
TBH I'm completely unversed in the C28x assembly instructions, but as there's only (what I assume to be) one move operation I don't see any way this could write both key values. When compiled with the struct declared as volatile I get;
61 ENABLE_PROTECTED_REGISTER_WRITE_MODE;
00c739: 7622 EALLOW
64 wdog->WDKEY = 0x55;
00c73a: 56BF55DC MOVB *+XAR4[3], #0x55, UNC
67 wdog->WDKEY = 0xAA;
00c73c: 56BFAADC MOVB *+XAR4[3], #0xaa, UNC
69 DISABLE_PROTECTED_REGISTER_WRITE_MODE;
00c73e: 761A EDIS
Which to me seems like the expected assembly code. In general my application is fairly generic; I'm not using any RTOS and the compiler flags seem fairly standard to my newbie eyes ;)
Jonathan, Hmmm...that's odd. I was using 6.1.3 as well and I tried the -O4 optimization setting but didn't see that compiled out. I'll try it again.
Either way it doesn't hurt to put the volatile in there, so I'll go ahead and file a bug to get this added.
Thanks,