How to check the source of reset in ATMEGA644p
According to the ATMEGA644p datasheet section 9.3.1 page 57 , there is the MCU Status Register MCUSR that provides information on which reset source caused an MCU reset.