mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
Merge branch 'docs/esp_crc_rom_api' into 'master'
fix(esp_crc): clarify CRC ROM helper usage documentation Closes IDFGH-17804 See merge request espressif/esp-idf!50177
This commit is contained in:
@@ -210,3 +210,78 @@ TEST_CASE("async_crc multiple requests", "[async_crc]")
|
||||
TEST_ESP_OK(esp_async_crc_uninstall(driver));
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t test_rom_crc32_le_reference(const uint8_t *data, size_t len)
|
||||
{
|
||||
uint32_t crc = (uint32_t)~UINT32_MAX;
|
||||
|
||||
crc = esp_crc32_le(crc, data, len);
|
||||
|
||||
return ~crc ^ UINT32_MAX;
|
||||
}
|
||||
|
||||
static uint16_t test_rom_crc16_xmodem_reference(const uint8_t *data, size_t len)
|
||||
{
|
||||
uint16_t crc = (uint16_t)~0x0000;
|
||||
|
||||
crc = esp_crc16_be(crc, data, len);
|
||||
|
||||
return (uint16_t)(~crc ^ 0x0000);
|
||||
}
|
||||
|
||||
static void test_async_crc_matches_rom_helper(async_crc_handle_t driver, bool supports_crc32)
|
||||
{
|
||||
static const char test_input_string[] __attribute__((aligned(16))) = "GDMACRC::TEST::LONGSTRING::REPEAT::GDMACRC::TEST::LONGSTRING::REPEAT::GDMACRC::TEST::LONGSTRING::REPEAT::GDMACRC::TEST::LONGSTRING::REPEAT::END!";
|
||||
size_t input_len = strlen(test_input_string);
|
||||
uint32_t async_result = 0;
|
||||
|
||||
if (supports_crc32) {
|
||||
async_crc_params_t crc32_params = {
|
||||
.width = 32,
|
||||
.polynomial = 0x04C11DB7,
|
||||
.init_value = UINT32_MAX,
|
||||
.final_xor_value = UINT32_MAX,
|
||||
.reverse_input = true,
|
||||
.reverse_output = true,
|
||||
};
|
||||
uint32_t crc32_rom_result = test_rom_crc32_le_reference((const uint8_t *)test_input_string, input_len);
|
||||
TEST_ESP_OK(esp_crc_calc_blocking(driver, test_input_string, input_len, &crc32_params, -1, &async_result));
|
||||
printf("CRC-32 async result: 0x%"PRIx32", ROM helper result: 0x%"PRIx32"\r\n", async_result, crc32_rom_result);
|
||||
TEST_ASSERT_EQUAL_HEX32(crc32_rom_result, async_result);
|
||||
}
|
||||
|
||||
async_crc_params_t crc16_params = {
|
||||
.width = 16,
|
||||
.polynomial = 0x1021,
|
||||
.init_value = 0x0000,
|
||||
.final_xor_value = 0x0000,
|
||||
.reverse_input = false,
|
||||
.reverse_output = false,
|
||||
};
|
||||
uint16_t crc16_rom_result = test_rom_crc16_xmodem_reference((const uint8_t *)test_input_string, input_len);
|
||||
TEST_ESP_OK(esp_crc_calc_blocking(driver, test_input_string, input_len, &crc16_params, -1, &async_result));
|
||||
printf("CRC-16/XMODEM async result: 0x%"PRIx32", ROM helper result: 0x%04x\r\n", async_result, crc16_rom_result);
|
||||
TEST_ASSERT_EQUAL_HEX16(crc16_rom_result, async_result);
|
||||
}
|
||||
|
||||
TEST_CASE("async_crc matches ROM helper results for standard CRC flavors", "[async_crc]")
|
||||
{
|
||||
async_crc_config_t config = {
|
||||
.backlog = 1,
|
||||
.dma_burst_size = 16,
|
||||
};
|
||||
async_crc_handle_t driver = NULL;
|
||||
#if SOC_HAS(AHB_GDMA)
|
||||
printf("Testing async CRC against ROM helper by AHB GDMA\r\n");
|
||||
TEST_ESP_OK(esp_async_crc_install_gdma_ahb(&config, &driver));
|
||||
test_async_crc_matches_rom_helper(driver, true);
|
||||
TEST_ESP_OK(esp_async_crc_uninstall(driver));
|
||||
#endif
|
||||
|
||||
#if SOC_HAS(AXI_GDMA)
|
||||
printf("Testing async CRC against ROM helper by AXI GDMA\r\n");
|
||||
TEST_ESP_OK(esp_async_crc_install_gdma_axi(&config, &driver));
|
||||
test_async_crc_matches_rom_helper(driver, false);
|
||||
TEST_ESP_OK(esp_async_crc_uninstall(driver));
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user