Rich Bair

Flash Update from in ISR

Discussion created by Rich Bair on Jul 11, 2006
Latest reply on Jul 12, 2006 by Jeff Smith
Hello,
 
I'd like to use flash to update variables that indicate abnormalities.  Consider the following:
 
----------8<-----------------------------
 
ISR(COP_internal_isr)
/*
 * Vector here for COP reset
 *
 *
 *
 *
 *
 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */
{
    signed char fl_retval;
    ++ram_COPcnt;
    // /* Update flash */
    /*lint -e{511} */
    fl_retval = Flash_Erase_Sector((unsigned int *far)0x3E8000);
    if (fl_retval == 1) {
        /*lint -e{511} */
        fl_retval = Flash_Write_Word((unsigned int *far)0x3E8000U, (unsigned int)ram_SWIcnt);
        /*lint -e{511} */
        fl_retval = Flash_Write_Word((unsigned int *far)0x3E8002U, (unsigned int)ram_COPcnt);
        /*lint -e{511} */
        fl_retval = Flash_Write_Word((unsigned int *far)0x3E8004U, (unsigned int)ram_UimpInstrcnt);
    }
}
ISR(SWI_isr)
/*
 * Vector here for the software interrupt.  NOTE: Unused flash is set to 0x3F
 * so if the program counter (PC) is corrupted you could come here.
 *
 *
 *
 *
 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 */
{
    ++ram_SWIcnt;
    /* 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;
}
 
----------8<-----------------------------
 
...this assumes the SWI "forced reset" will trigger the COP ISR which I don't acutally know that to be the case.  Other than that, should there be any issues with this?  These flash functions work in main(); however, when I have a random while(1) injected for test only to create a COP ISR, the flash is not updated.  Any thoughts?
 
Thanks!

Outcomes