Hi,
The S12G contains only one memory block so it is not possible to perform read while write code on the flash block. The code must be stored in other type of memory. Reading while not writing is not any problem anytime.
//==============================================================================
//PFLASH Send_Command – the routine placed in the RAM to perform safe write to a flash
//==============================================================================
//this function is stored in RAM memory
//in C language:
// {
// FSTAT_CCIF = 1; //launch command
// while(FSTAT_CCIF == 0); //wait for done
// }
static unsigned char Send_Command[]=
{
0x1C, 0x01, 0x06, 0x80, 0x1F, 0x01, 0x06, 0x80, 0xFB, 0x3D
};
//==============================================================================
//PFLASH_Program - the parameter MUST be global address
//==============================================================================
unsigned char PFLASH_Program(unsigned long int address, unsigned int *ptr)
{
unsigned char i;
//check if address is aligned (global address [2:0] != 000)
if((address & 0x00000007) != 0)
return MISALIGNED_ADDRESS;
//check if the phrase is erased
if((PFLASH_Erase_Verify_Section(address, 1)) == NON_ERASED)
return NON_ERASED;
while(FSTAT_CCIF == 0); //wait if command in progress
FSTAT = 0x30; //clear ACCERR and PVIOL
FCCOBIX = 0x00;
FCCOB = 0x0600 | ((address & 0x00030000)>>16);
FCCOBIX = 0x01;
FCCOB = (address & 0x0000FFFF);
for(i=2; i<6; i++) //fill data (4 words) to FCCOB register
{
FCCOBIX = i;
FCCOB = *ptr;
ptr++;
}
asm JSR Send_Command;
if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return ACCESS_ERROR;
else
return OK;
}
Best regards,
Ladislav