
FLASHER 5 Manual 11
CRC calculation used in Flasher and PC program.
The Flasher PC program and Flasher calculate a CRC over all data downloaded to the Flasher. The CRC is
used to verify correct data transfer as well as an integrity check of target-data stored in the on board non
volatile memory.
The CRC is calculated over all bytes of all selected flash sectors of the target device. The calculation is
compatible to the algorithm used in the CRC generator circuit inside a Renesas M16C/62P device.
The Renesas application note REU05B0007-0100Z describes how the CRC is calculated.
To calculate the CRC of a target application you have to perform the following steps:
• Create a buffer, large enough to hold all bytes of all selected flash banks of the target.
• Fill the whole buffer with the fill-byte which is defined as fill byte in the Flasher Filling & misc. options.
• Parse your hex-file and fill all defined bytes into the buffer. Bytes not defined in the hex-file were set to
the fill byte in step 2.
• Calculate the CRC over the whole buffer following the algorithm from the application note, or the follow-
ing program example.
Alternatively, the CRC over all bytes may be calculated without a buffer, when a function delivers all bytes of
all selected flash banks, including fill bytes, in ascending address order from a stream.
Program example for CRC calculation
//
// CRC_Calc1_M16() calculates the CRC for one byte.
// Before calling the function the first time, set the CRC to 0x0000
//
void CRC_Calc1_M16(unsigned int* pCRC, unsigned char Data) {
unsigned int crc;
unsigned int x16;
int i;
crc = *pCRC;
for (i = 0; i < 8; i++) {
if ((crc & 0x0001) ^ (Data & 0x01)) {
x16 = 0x8408;
} else {
x16 = 0x0000;
}
crc = crc >> 1;
crc ^= x16;
Data = Data >> 1;
}
*pCRC = crc;
}
//
// CRC_Calc() calculates the CRC over NumBytes bytes in a buffer
//
unsigned int CRC_Calc(unsigned char* pBuffer, unsigned long NumBytes) {
unsigned int CRC_M16;
unsigned long i;
//
// Initialize CRC and calculate the CRC over all bytes
//
CRC_M16 = 0x0000;
for (i = 0; i < NumBytes; i++) {
CRC_Calc1_M16(&CRC_M16, ((char) pBuffer[i]));
}
return CRC_M16;
}
Comentarios a estos manuales