I added counters to the system configuration, it have to be persistent over device switch off and/or accidental restart.
The config structure (stored in EEPROM) is enriched by:
Code: Select all
uint16_t // reset counters
ResCntPwrOn, // Power-on Reset Detected
ResCntExtReset, // External Reset Detected
ResCntBrownOut, // Brown-out Reset Detected
ResCntWDT; // Watchdog Reset Detected NOTE: WDT is not implemented yet
NOTE: You can see I decided to ignore JTAG reset at all.
I added new signal to the comm protocol:
Code: Select all
MSP_RESET_COUNTERS // in/out message (w) reset reason counters, if counters are cleared then whole configuration is stored as side effect
The code snippet from device side:
Code: Select all
static inline void processResetCounters (uint8_t dataSize)
{
if (0 == dataSize) { // query
headSerialReply (8);
serialize16 (conf.ResCntPwrOn);
serialize16 (conf.ResCntExtReset);
serialize16 (conf.ResCntBrownOut);
serialize16 (conf.ResCntWDT);
} else if (1 == dataSize) {
// uint8_t item = read8 ();
// if (item == ~MSP_RESET_COUNTERS) {
conf.ResCntPwrOn = 0;
conf.ResCntExtReset = 0;
conf.ResCntBrownOut = 0;
conf.ResCntWDT = 0;
Conf_Save (&conf);
headSerialReply (0);
// } else {
// headSerialError (0);
// }
} else { // mangled/unrecognized request
headSerialError (0);
}
} // processResetCounters
...
case MSP_RESET_COUNTERS:
processResetCounters (dataSize);
break;
...
And part of the GUI screen is attached. I didn't attached any GUI related code. Because code structure is totally different from original one.