-
Notifications
You must be signed in to change notification settings - Fork 8
/
jump.c
51 lines (40 loc) · 994 Bytes
/
jump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "jump.h"
#include <avr/wdt.h>
#include <avr/eeprom.h>
uint16_t boot_key __attribute__((section (".noinit")));
const uint8_t *valid_app_addr = (uint8_t *) (E2END - BOOTLOADER_EEPROM_SIZE);
void jump_check (void)
{
uint8_t valid_app = 0;
/* Check to see if we should read BLE data from EEPROM */
valid_app = eeprom_read_byte (valid_app_addr);
if ((MCUSR & (1 << WDRF)) &&
(boot_key == BOOTLOADER_KEY) &&
valid_app == 1)
{
/* Clear watchdog reset flag and the boot key */
MCUSR &= ~(1 << WDRF);
boot_key = 0;
/* Disable watchdog */
WDTCSR = _BV(WDCE) | _BV(WDE);
WDTCSR = 0;
/* Jump to application */
((void (*)(void)) 0x0000)();
}
}
void jump_boot_key_clear (void)
{
boot_key = 0;
}
void jump_boot_key_set (void)
{
boot_key = BOOTLOADER_KEY;
}
void jump_app_key_clear (void)
{
eeprom_write_byte ((uint8_t *)valid_app_addr, 0);
}
void jump_app_key_set (void)
{
eeprom_write_byte ((uint8_t *)valid_app_addr, 1);
}