/* Calculates a 16-bit CRC value over the specified data. 
It uses the CRC16_CCITT_FALSE algorithm: */
uint16_t TbxChecksumCrc16Calculate(uint8_t const *data, size_t len)
/* Calculates a 16-bit CRC value over the specified data. 
It uses the CRC16_CCITT_FALSE algorithm: */
uint16_t TbxChecksumCrc16Calculate(uint8_t const *data, size_t len)
{
  uint16_t result = 0;
  TBX_ASSERT((data != NULL) && (len > 0U));
  if ( (data != NULL) && (len > 0U) )
  {
    result = TBX_CONF_CHECKSUM_CRC16_INITIAL;
    for (size_t byteIdx = 0U; byteIdx < len; byteIdx++)
    {
      result = result ^ ((uint16_t)data[byteIdx] << 8U);
      for (uint8_t bitIdx = 0U; bitIdx <= 7U; bitIdx++)
      {
        if ((result & 0x8000U) != 0U)
        {
          result = ((uint16_t)(result << 1U)) ^ TBX_CONF_CHECKSUM_CRC16_POLYNOM;
        }
        else
        {
          result = (uint16_t)(result << 1U);
        }
      }
    }
  }
  return result;
}