#define CONFIG_H
#define MAJ_VERS 0x01
- #define MIN_VERS 0x11
+ #define MIN_VERS 0x12
#define MCU_1284P 0x91
const uint8_t SIG_SYNCED = 0x02;
const uint8_t RX_ONGOING = 0x04;
+ // Boot flags
+ #define START_FROM_BOOTLOADER 0x01
+ #define START_FROM_POWERON 0x02
+ #define START_FROM_BROWNOUT 0x03
+ #define START_FROM_JTAG 0x04
+
#endif
\ No newline at end of file
}
void validateStatus() {
- if (eeprom_lock_set()) {
- if (eeprom_product_valid() && eeprom_model_valid() && eeprom_hwrev_valid()) {
- if (eeprom_checksum_valid()) {
- hw_ready = true;
-
- if (eeprom_have_conf()) {
- eeprom_conf_load();
- op_mode = MODE_TNC;
- startRadio();
+ if (OPTIBOOT_MCUSR & (1<<PORF)) {
+ boot_vector = START_FROM_POWERON;
+ } else if (OPTIBOOT_MCUSR & (1<<BORF)) {
+ boot_vector = START_FROM_BROWNOUT;
+ } else if (OPTIBOOT_MCUSR & (1<<WDRF)) {
+ boot_vector = START_FROM_BOOTLOADER;
+ } else {
+ Serial.write("Error, indeterminate boot vector\r\n");
+ led_indicate_boot_error();
+ }
+
+ if (boot_vector == START_FROM_BOOTLOADER) {
+ if (eeprom_lock_set()) {
+ if (eeprom_product_valid() && eeprom_model_valid() && eeprom_hwrev_valid()) {
+ if (eeprom_checksum_valid()) {
+ hw_ready = true;
+
+ if (eeprom_have_conf()) {
+ eeprom_conf_load();
+ op_mode = MODE_TNC;
+ startRadio();
+ }
}
+ } else {
+ hw_ready = false;
}
} else {
hw_ready = false;
}
} else {
hw_ready = false;
+ Serial.write("Error, incorrect boot vector\r\n");
+ led_indicate_boot_error();
}
}
#include "Framing.h"
#include "MD5.h"
+uint8_t boot_vector = 0x00;
+uint8_t OPTIBOOT_MCUSR __attribute__ ((section(".noinit")));
+void resetFlagsInit(void) __attribute__ ((naked)) __attribute__ ((used)) __attribute__ ((section (".init0")));
+void resetFlagsInit(void) {
+ __asm__ __volatile__ ("sts %0, r2\n" : "=m" (OPTIBOOT_MCUSR) :);
+}
+
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
digitalWrite(pin_led_tx, LOW);
}
+void led_indicate_boot_error() {
+ while (true) {
+ led_tx_on();
+ led_rx_off();
+ delay(10);
+ led_rx_on();
+ led_tx_off();
+ delay(5);
+ }
+}
+
void led_indicate_warning(int cycles) {
bool forever = (cycles == 0) ? true : false;
cycles = forever ? 1 : cycles;