ds3231/ds3231/bootloader.h

56 lines
811 B
C

/*
* Copyright (c) by BlackMark 2016
* Date 09/09/2016
* Version 1.4
*/
#ifndef BOOTLOADER_H
#define BOOTLOADER_H
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
typedef void (*flash)() __attribute__ ((noreturn));
flash boot = reinterpret_cast<flash>( 0x0000 );
flash bootloader = reinterpret_cast<flash>( 0x7E00 / 2 );
inline bool checkBootloader()
{
if( pgm_read_byte( reinterpret_cast<uint16_t>( bootloader ) * 2 ) == 0xF8 )
{
return true;
}
return false;
}
inline void callBootloader()
{
if( checkBootloader() )
{
bootloader();
}
else
{
boot();
}
}
inline uint8_t handleReset()
{
wdt_reset();
uint8_t ui8MCUSR = MCUSR;
MCUSR &= ~( 1 << WDRF );
wdt_disable();
return ui8MCUSR;
}
inline void reset()
{
wdt_enable( WDTO_15MS );
while( true );
}
#endif