SNIU028D February 2016 – September 2020 UCD3138 , UCD3138064 , UCD3138064A , UCD3138128 , UCD3138A , UCD3138A64
This first code typically goes into the software interrupt, as it must be used in system mode, not in user mode. This code copies the actual checksum clearing program into RAM.
case 12: // clear integrity word.
{
{
register Uint32 * program_index = (Uint32 *) 0x19000; //store destination address for
//program
register Uint32 * source_index = (Uint32 *)zero_out_integrity_word; //Set source
//address of
//PFLASH;
register Uint32 counter;
for(counter=0; counter < 500; counter++) //Copy program from PFLASH to RAM
{
*(program_index++)=*(source_index++);
}
}
{
register FUNC_PTR func_ptr;
func_ptr=(FUNC_PTR)0x19000; //Set function to 0x19000
func_ptr();
func_ptr=(FUNC_PTR)0x70000; //Set function to illegal location
func_ptr(); //force reset
} //execute erase checksum
return;
}
This is the code for actually clearing the checksum which is copied into RAM:
void zero_out_integrity_word(void)
{
DecRegs.FLASHILOCK.all = 0x42DC157E; //Write key to Program Flash
//Interlock Register
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K; //enable program flash write
program_flash_integrity_word = 0;
DecRegs.MFBALR1.all = MFBALRX_BYTE0_BLOCK_SIZE_32K + //expand program flash out to 4x real
//size
MFBALRX_BYTE0_RONLY;
while(DecRegs.PFLASHCTRL.bit.BUSY != 0)
{
; //do nothing while it programs
}
return;
}