Thanks for the help. I think it is definitely my confusion! Ok, so a COP is a reset that you can "hook" to run code. So below is a snippet from my vectors.c file...
Code:
RTI_isr, /* 56: RTI isr */ Unimplemented_ISR, /* 57 Default (unused) interrupt, address 0xFFF2 */ Unimplemented_ISR, /* 58 Default (unused) interrupt, address 0xFFF4 */ SWI_isr, /* 59: Software Interrup (0x3F flash default isr) */ Unimp_instr_isr, /* 60 Default (unused) interrupt, address 0xFFF8 */ COP_internal_isr, /* 61: internal COP */ Unimplemented_ISR, /* 62 Default (unused) interrupt, address 0xFFFC */ _EntryPoint /* Reset vector, address 0xFFFE */ };
So when exactly does COP_internal_isr execute? I surmise it is before the reset actually occurs. If so, it seems FCLK should stil be initialized and I could technically write a variable to flash in that "isr." I plan to change my strategy a bit so that the SWI_isr and Unimp_instr_isr both become Unimplemented_ISR so that any unplanned vectoring basically forces a COP reset and I have a single variable in flash indicating how often that happens. So Unimplemented__ISR will look something like:
Code:
/* Force reset by writing other than 0x55 followed by 0xAA to ARMCOP */ (*(volatile unsigned char*)_COP_RST_ADR) = 0x33; (*(volatile unsigned char*)_COP_RST_ADR) = 0x37;
I think this will force a COP reset immediately and COP_internal_isr will execute followed by a reset. Does that sound correct?
As for the SWI, I'm still confused. Suppose I fill unused flash with 0x3F and my PC is corrupted. Would this then cause a vector to the handler SWI_isr (soon to be Unimplemented_ISR)? If so, it would vector there and I could force a COP reset withing SWI_isr, correct?
Thanks!