Hi all,
I came accross with an issue , while i am calculating the CRC for particular location in Flash memory.
In File1.c(for reference), i am passing start and end address of the block to fucntion where calculating the CRC.
But, while Debuging i noticed that, CRC calculating for 8000 to FFFF instead of 7EC000 to 7EFFFF.
and while returning the value it's returning 2 byte value instead of 4 byte value.
but variable crc holding the 4 bytes values
IDE: CW
Microcontroller: MC9S12XS128
file1.c
#define BLOCK1START 0xFB8000
#define BLOCK1END 0xFBBFFF
crcBoot[0]= _Checksum_CheckAreaCRC32_PreCalc(BLOCK1START,((BLOCK1END+0x1)-BLOCK1START));
file2.c
_CheckSum4ByteType _Checksum_CheckAreaCRC32_PreCalc(_CHECKSUM_ConstMemBytePtr start, unsigned int len) {
const _CheckSum1ByteType*_CHECKSUM_QUALI ptr= (const _CheckSum1ByteType* _CHECKSUM_QUALI)start;
_CheckSum4ByteType crc = 0xFFFFFFFF;
const _CheckSum1ByteType* _CHECKSUM_QUALI endPtr= ptr + len;
while (ptr != endPtr) {
crc= CheckSumByteCRC32_PreCalc(crc, *ptr);
//__FEED_COP; /* COP enabled? If so, feed it */
PTM=PTM^0x04; /* toggle self reset */
ptr++;
}
return (crc); /*== check->checkSumCRC32 *
please help me on above issue, how to pass address properly and how to return values correctly without losing 2 bytes value...
thanks in advance
You have to use far pointers.
In attachment you can find simple example code for CRC calculation.
Note: I created this example code for S12G. In case of S12XS we can use global addresses (default for far pointers in case of S12X) and calculate checksum in one loop.
Note: More details about checksum calculation and automatic checksum calculation by CW you can find in example codes on your disk. Example path is:
"C:\Program Files\Freescale\CWS12v5.1\(CodeWarrior_Examples)\HC12\Checksums\2. Single App"