Counting of Restart Reasons

Post Reply
User avatar
davidd
Posts: 4
Joined: Tue Dec 04, 2012 8:02 pm

Counting of Restart Reasons

Post by davidd »

During my tests with multiWii (with no original firmware) I experienced multiple times "stange" behaviour. After short investigation and few other tests I relised that restarts was caused by Brown Out detection circuit.
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.

User avatar
Hamburger
Posts: 2580
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Counting of Restart Reasons

Post by Hamburger »

I cannot see the code that acutally attains the info on the last reset?
You could also extend the LOG_PERMANENT feature to automatically store this info in eeprom

User avatar
davidd
Posts: 4
Joined: Tue Dec 04, 2012 8:02 pm

Re: Counting of Restart Reasons

Post by davidd »

I forgot the code snippet. The EEPROM data have to be read before that.

Code: Select all

   {
      uint8_t resStatus = MCUSR;
      if (resStatus & _BV (PORF)) {
         conf.ResCntPwrOn++;
         MCUSR &= ~(1<<PORF);
      } else if (resStatus & _BV (WDRF)) {
         conf.ResCntWDT++;
         MCUSR &= ~(1<<WDRF);
      } else if (resStatus & _BV (BORF)) {
         conf.ResCntBrownOut++;
         MCUSR &= ~(1<<BORF);
      } else if (resStatus & _BV (EXTRF)) {
         conf.ResCntExtReset++;
         MCUSR &= ~(1<<EXTRF);
      }
      Conf_Save (&conf);
   }


Post Reply