K64F CRC driver: Fix handling of CRC final XOR value

According to the test results final XOR was incorrectly handled by the CRC driver.
This patch fixes this issue.
pull/6831/head
Przemyslaw Stekiel 2018-06-07 15:02:35 +02:00
parent da557a58a6
commit ee6a07e7ab
1 changed files with 30 additions and 14 deletions

View File

@ -50,7 +50,12 @@ void hal_crc_compute_partial_start(const crc_mbed_config_t* config)
platform_config.seed = config->initial_xor;
platform_config.reflectIn = config->reflect_in;
platform_config.reflectOut = config->reflect_out;
platform_config.complementChecksum = (config->final_xor == 0xFFFFFFFFU);
if ((width == kCrcBits16 && config->final_xor == 0xFFFFU) ||
(width == kCrcBits32 && config->final_xor == 0xFFFFFFFFU)) {
platform_config.complementChecksum = true;
} else {
platform_config.complementChecksum = false;
}
platform_config.crcBits = width;
platform_config.crcResult = kCrcFinalChecksum;
@ -72,20 +77,31 @@ void hal_crc_compute_partial(const uint8_t *data, const size_t size)
uint32_t hal_crc_get_result(void)
{
if ((final_xor != 0x00000000U) && (final_xor != 0xFFFFFFFFU)) {
CRC_WriteData(CRC0, (uint8_t*)&final_xor, sizeof(final_xor));
}
uint32_t result;
switch (width)
{
case kCrcBits16:
return CRC_Get16bitResult(CRC0);
case kCrcBits32:
return CRC_Get32bitResult(CRC0);
default:
MBED_ASSERT("Unhandled switch case");
return 0;
}
const bool manual_final_xor = ((final_xor != 0x00000000U) &&
((final_xor != 0xFFFFFFFFU && width == kCrcBits32) ||
(final_xor != 0xFFFFU && width == kCrcBits16)));
switch (width)
{
case kCrcBits16:
result = CRC_Get16bitResult(CRC0);
if (manual_final_xor) {
result ^= final_xor;
result &= 0xFFFF;
}
return result;
case kCrcBits32:
result = CRC_Get32bitResult(CRC0);
if (manual_final_xor) {
result ^= final_xor;
}
return result;
default:
MBED_ASSERT("Unhandled switch case");
return 0;
}
}
#endif // DEVICE_CRC