0

I would like to calculate a checksum (preferable 8 bit) that will yield a result that is not FF and not 0. It is to be used in a circular log SPI flash file system for a microcontroller. In the file system 0 marks the start of a record, and FF indicates erased memory. Thus when I calculate the checksum I do not want the result to be confused with the start of a record or unused memory.

I have looked at Fletcher's checksums, but that could still yield 0 as a result. Alternatively I though of using a 7 bit checksum and using the last bit to make sure I do not have a zero or FF result.

Does anyone know about such an implementation?

Armand Jordaan
  • 348
  • 2
  • 11

1 Answers1

0

I ended up doing the following:

uint8_t CrcCalc(uint8_t* buffer, size_t len)
{
    // .... some calculation here with polynomial of own choice
}

uint8_t CrcCalcNon0orFF(uint8_t* buffer, size_t len)
{
    uint8_t tempCrc = CrcCalc(buffer,len);

    if (tempCrc == 0xFF) tempCrc++;
    if (tempCrc == 0) tempCrc++;

    return tempCrc;
}

The above can be extended to 16 and 32 bit problems as well.

I am not sure if it will satisfy the math purists, but it worked for me.

Armand Jordaan
  • 348
  • 2
  • 11