/* Calculate checksum according to CCITT CRC16. 
This functionality is also present internally in the API, but is duplicated here to allow for much more efficient calculations specific to the hardware. */
void NVMHAL_Checksum(uint16_t *pChecksum, void *pMemory, uint16_t len)
/* Calculate checksum according to CCITT CRC16. 
This functionality is also present internally in the API, but is duplicated here to allow for much more efficient calculations specific to the hardware. */
void NVMHAL_Checksum(uint16_t *pChecksum, void *pMemory, uint16_t len)
{
  uint8_t *pointer = (uint8_t *) pMemory;
  uint16_t crc = *pChecksum;
  while(len--)
  {
    crc = (crc >> 8) | (crc << 8);
    crc ^= *pointer++;
    crc ^= (crc & 0xf0) >> 4;
    crc ^= (crc & 0x0f) << 12;
    crc ^= (crc & 0xff) << 5;
  }
  *pChecksum = crc;
}