you are here: home bare essentials barefoot blog Warm start detection on Microchip PIC24s

Warm start detection on Microchip PIC24s

December 2012

Some while ago we adjusted our firmware to suppress C's traditional initialisation of RAM, to provide a random number seed for RS485 collision avoidance.

The undefined power-on contents of RAM have since proved handy for other things. For example, it has become useful for us to detect the difference between a cold (power-on) firmware start-up, and a warm restart (e.g. after a firmware update). This is a simple job of allocating and testing a variable, with 16 bits chosen to minimise the risk of false information by chance:-

static Word warmStartWord;

Byte boardWasWarmStarted()
     if (warmStartWord == WARM_START_WORD_VALUE)
         return 1;

     warmStartWord = WARM_START_WORD_VALUE;
     return 0;

where Word and Byte are defined as unsigned short, and unsigned char, respectively.

The actual numerical value of WARM_START_WORD_VALUE is completely arbitrary - 0x42E9 just happened to be the start of BASIC code storage on TRS-80s and Video Genies :)

See also:-
Last Updated on Wednesday, 12 December 2012 13:58

navigate to...