|
@@ -388,25 +388,49 @@ void appStart(uint8_t rstFlags) __attribute__ ((naked));
|
|
|
|
|
|
|
|
|
|
#define buff ((uint8_t*)(RAMSTART))
|
|
#define buff ((uint8_t*)(RAMSTART))
|
|
|
|
+
|
|
|
|
+
|
|
#ifdef VIRTUAL_BOOT_PARTITION
|
|
#ifdef VIRTUAL_BOOT_PARTITION
|
|
#define rstVect0_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+4))
|
|
#define rstVect0_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+4))
|
|
#define rstVect1_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+5))
|
|
#define rstVect1_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+5))
|
|
-#define wdtVect0_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+6))
|
|
+#define saveVect0_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+6))
|
|
-#define wdtVect1_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+7))
|
|
+#define saveVect1_sav (*(uint8_t*)(RAMSTART+SPM_PAGESIZE*2+7))
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#if !defined (save_vect_num)
|
|
|
|
+#if defined (SPM_RDY_vect_num)
|
|
|
|
+#define save_vect_num (SPM_RDY_vect_num)
|
|
|
|
+#elif defined (SPM_READY_vect_num)
|
|
|
|
+#define save_vect_num (SPM_READY_vect_num)
|
|
|
|
+#elif defined (WDT_vect_num)
|
|
|
|
+#define save_vect_num (WDT_vect_num)
|
|
|
|
+#else
|
|
|
|
+#error Cant find SPM or WDT interrupt vector for this CPU
|
|
|
|
+#endif
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#if (SPM_PAGESIZE <= save_vect_num)
|
|
|
|
+#error Save vector not in the same page as reset!
|
|
|
|
+#endif
|
|
#if FLASHEND > 8192
|
|
#if FLASHEND > 8192
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
#define rstVect0 2
|
|
#define rstVect0 2
|
|
#define rstVect1 3
|
|
#define rstVect1 3
|
|
-#define wdtVect0 (WDT_vect_num*4+2)
|
|
+#define saveVect0 (save_vect_num*4+2)
|
|
-#define wdtVect1 (WDT_vect_num*4+3)
|
|
+#define saveVect1 (save_vect_num*4+3)
|
|
-#define appstart_vec (WDT_vect_num*2)
|
|
+#define appstart_vec (save_vect_num*2)
|
|
#else
|
|
#else
|
|
|
|
|
|
#define rstVect0 0
|
|
#define rstVect0 0
|
|
#define rstVect1 1
|
|
#define rstVect1 1
|
|
-#define wdtVect0 (WDT_vect_num*2)
|
|
+#define saveVect0 (save_vect_num*2)
|
|
-#define wdtVect1 (WDT_vect_num*2+1)
|
|
+#define saveVect1 (save_vect_num*2+1)
|
|
-#define appstart_vec (WDT_vect_num)
|
|
+#define appstart_vec (save_vect_num)
|
|
#endif
|
|
#endif
|
|
#else
|
|
#else
|
|
#define appstart_vec (0)
|
|
#define appstart_vec (0)
|
|
@@ -561,6 +585,7 @@ int main(void) {
|
|
#if FLASHEND > 8192
|
|
#if FLASHEND > 8192
|
|
|
|
|
|
* AVR with 4-byte ISR Vectors and "jmp"
|
|
* AVR with 4-byte ISR Vectors and "jmp"
|
|
|
|
+ * WARNING: this works only up to 128KB flash!
|
|
*/
|
|
*/
|
|
if (address == 0) {
|
|
if (address == 0) {
|
|
|
|
|
|
@@ -569,14 +594,15 @@ int main(void) {
|
|
|
|
|
|
rstVect0_sav = buff[rstVect0];
|
|
rstVect0_sav = buff[rstVect0];
|
|
rstVect1_sav = buff[rstVect1];
|
|
rstVect1_sav = buff[rstVect1];
|
|
- wdtVect0_sav = buff[wdtVect0];
|
|
+ saveVect0_sav = buff[saveVect0];
|
|
- wdtVect1_sav = buff[wdtVect1];
|
|
+ saveVect1_sav = buff[saveVect1];
|
|
|
|
|
|
-
|
|
+
|
|
- buff[wdtVect0] = rstVect0_sav;
|
|
+ buff[saveVect0] = rstVect0_sav;
|
|
- buff[wdtVect1] = rstVect1_sav;
|
|
+ buff[saveVect1] = rstVect1_sav;
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
buff[rstVect0] = ((uint16_t)main) & 0xFF;
|
|
buff[rstVect0] = ((uint16_t)main) & 0xFF;
|
|
buff[rstVect1] = ((uint16_t)main) >> 8;
|
|
buff[rstVect1] = ((uint16_t)main) >> 8;
|
|
}
|
|
}
|
|
@@ -589,22 +615,23 @@ int main(void) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
rstVect0_sav = buff[rstVect0];
|
|
rstVect0_sav = buff[rstVect0];
|
|
rstVect1_sav = buff[rstVect1];
|
|
rstVect1_sav = buff[rstVect1];
|
|
- wdtVect0_sav = buff[wdtVect0];
|
|
+ saveVect0_sav = buff[saveVect0];
|
|
- wdtVect1_sav = buff[wdtVect1];
|
|
+ saveVect1_sav = buff[saveVect1];
|
|
|
|
|
|
|
|
|
|
- uint16_t vect=rstVect0_sav+(rstVect1_sav<<8);
|
|
+ uint16_t vect=(rstVect0_sav & 0xff) | ((rstVect1_sav & 0x0f)<<8);
|
|
- vect -= WDT_vect_num;
|
|
+ vect = (vect-save_vect_num) & 0x0fff;
|
|
-
|
|
+
|
|
- buff[wdtVect0] = vect & 0xff;
|
|
+ buff[saveVect0] = vect & 0xff;
|
|
- buff[wdtVect1] = vect >> 8;
|
|
+ buff[saveVect1] = (vect >> 8) | 0xc0;
|
|
|
|
|
|
- buff[0] = (((uint16_t)main) & 0xFFF) & 0xFF;
|
|
+ vect = ((uint16_t)main) &0x0fff;
|
|
- buff[1] = ((((uint16_t)main) & 0xFFF) >> 8) | 0xC0;
|
|
+ buff[0] = vect & 0xFF;
|
|
|
|
+ buff[1] = (vect >> 8) | 0xC0;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
@@ -812,7 +839,7 @@ void appStart(uint8_t rstFlags) {
|
|
|
|
|
|
|
|
|
|
__asm__ __volatile__ (
|
|
__asm__ __volatile__ (
|
|
-
|
|
+
|
|
"ldi r30,%[rstvec]\n"
|
|
"ldi r30,%[rstvec]\n"
|
|
"clr r31\n"
|
|
"clr r31\n"
|
|
"ijmp\n"::[rstvec] "M"(appstart_vec)
|
|
"ijmp\n"::[rstvec] "M"(appstart_vec)
|
|
@@ -905,8 +932,8 @@ static inline void read_mem(uint8_t memtype, uint16_t address, pagelen_t length)
|
|
|
|
|
|
if (address == rstVect0) ch = rstVect0_sav;
|
|
if (address == rstVect0) ch = rstVect0_sav;
|
|
else if (address == rstVect1) ch = rstVect1_sav;
|
|
else if (address == rstVect1) ch = rstVect1_sav;
|
|
- else if (address == wdtVect0) ch = wdtVect0_sav;
|
|
+ else if (address == saveVect0) ch = saveVect0_sav;
|
|
- else if (address == wdtVect1) ch = wdtVect1_sav;
|
|
+ else if (address == saveVect1) ch = saveVect1_sav;
|
|
else ch = pgm_read_byte_near(address);
|
|
else ch = pgm_read_byte_near(address);
|
|
address++;
|
|
address++;
|
|
#elif defined(RAMPZ)
|
|
#elif defined(RAMPZ)
|