diff --git a/Examples/MAX32655/CRC/main.c b/Examples/MAX32655/CRC/main.c index cb0bd83f368..363cd02526d 100644 --- a/Examples/MAX32655/CRC/main.c +++ b/Examples/MAX32655/CRC/main.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,97 +35,520 @@ #include "dma.h" /***** Definitions *****/ -#define POLY 0xEDB88320 -#define CHECK 0xDEBB20E3 +typedef struct _test_data_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint32_t dataLen; ///< Length of the data + uint32_t beginAddress; ///< Begin address of the data + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t expectedResultCRC; ///< Expected CRC result +} test_data_t; + +typedef struct _test_case_mxc_crc_full_req_t { + char *test_object; + test_data_t *test_req; +} test_case_mxc_crc_full_req_t; /***** Globals *****/ -volatile int wait; -volatile int callback_result; -volatile int counter; -volatile int fail = 0; +test_case_mxc_crc_full_req_t test_cases_crc[] = { + { .test_object = "Case 01 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x9DDD1DDF ///< Expected CRC result + } }, + { .test_object = "Case 02 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x07 }, ///< Pointer to the data + 0x4C667A2E ///< Expected CRC result + } }, + { .test_object = "Case 03 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x4E, 0xB2 }, ///< Pointer to the data + 0x0A4CA2D4 ///< Expected CRC result + } }, + { .test_object = "Case 04 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x89, 0x3D }, ///< Pointer to the data + 0xF3F07DEC ///< Expected CRC result + } }, + { .test_object = "Case 05 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 5, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0xD4, 0x6A, 0x1E, 0xB9, 0x03 }, ///< Pointer to the data + 0x547AF3D2 ///< Expected CRC result + } }, + { .test_object = "Case 06 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x5FC812A7, ///< The polynominal to calculate CRC + 0x3AE17FC4, ///< The initial value to calculate CRC + 0x760DA8F1, ///< The final xor value to calculate CRC + 23, ///< Length of the data + 1, ///< Begin address of the data + ( + uint8_t[]){ 0x00, 0x4D, 0x10, 0xDD, 0x70, 0xB9, 0x43, 0xFE, + 0xC1, 0x94, 0x1B, 0x09, 0xA0, 0x9C, 0xE8, 0x8D, + 0xF6, 0x04, 0x85, 0x9D, 0xCD, 0xE8, 0x69, 0x95 }, ///< Pointer to the data + 0x27823A8C ///< Expected CRC result + } }, + { .test_object = "Case 07 - CRC32 - Extra test Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x2CF7813E, ///< The polynominal to calculate CRC + 0xE358A17B, ///< The initial value to calculate CRC + 0x6DB42A90, ///< The final xor value to calculate CRC + 17, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x75, 0xDC, 0x92, 0xEB, 0xF6, 0x9D, 0x71, 0xF8, 0x7D, 0x1B, + 0x70, 0x86, 0xAC, 0x14, 0xF2, 0xF0, 0x8E }, ///< Pointer to the data + 0x0D346433 ///< Expected CRC result + } }, + { .test_object = "Case 08 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA53CE719, ///< The polynominal to calculate CRC + 0x4AD26F88, ///< The initial value to calculate CRC + 0xF936B02E, ///< The final xor value to calculate CRC + 13, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x8B, 0x1E, 0xD2, 0x7D, 0x7C, 0x8C, 0xA5, 0xAA, 0x06, + 0x8E, 0xCA, 0xCD, 0x4E }, ///< Pointer to the data + 0xDAA1D40B ///< Expected CRC result + } }, + { .test_object = "Case 09 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC72FA218, ///< The polynominal to calculate CRC + 0x7EC359A0, ///< The initial value to calculate CRC + 0xD81CF467, ///< The final xor value to calculate CRC + 79, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x3B, 0xAA, 0x9B, 0xAD, 0xBF, 0x8E, 0x73, 0x2A, 0x95, 0x00, 0x96, + 0xAF, 0xD0, 0xE4, 0x4D, 0xAB, 0x64, 0xB5, 0xAD, 0x76, 0x9C, 0x38, 0xEE, + 0xB3, 0xD6, 0x6D, 0x68, 0x43, 0xCB, 0xD9, 0x27, 0xFE, 0x95, 0x9A, 0xAD, + 0x01, 0x94, 0x84, 0xA8, 0x49, 0xAD, 0xC9, 0x3B, 0x0B, 0x3B, 0x5A, 0x55, + 0x99, 0xDE, 0xB4, 0x50, 0xAF, 0xE6, 0x85, 0xB4, 0x49, 0x1B, 0xB5, 0x45, + 0x94, 0x83, 0xAD, 0x68, 0x5D, 0x51, 0x43, 0xAB, 0x6B, 0xCC, 0xCB, 0xB4, + 0xD3, 0x6D, 0xCD, 0x03, 0x9D, 0x62, 0x1E, 0xAA }, ///< Pointer to the data + 0x8412B11F ///< Expected CRC result + } }, + { .test_object = "Case 0A - CRC32 - Extra test: Popular Example CRC-32/AUTOSAR", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xF4ACFB13, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 47, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x2E, 0x23, 0x58, 0xC9, 0x34, 0x9C, 0x57, 0xCB, 0x41, 0x77, 0xC2, + 0x4D, 0x66, 0xAB, 0x16, 0xDC, 0x96, 0xA8, 0x3D, 0xE4, 0x65, 0x10, 0x07, 0x33, + 0x1B, 0x85, 0x25, 0xED, 0xD3, 0x23, 0x70, 0xBA, 0xE3, 0xF9, 0x73, 0xDA, 0x5D, + 0x01, 0x90, 0x25, 0x82, 0x73, 0x73, 0x21, 0x9A, 0xD1, 0x7B }, ///< Pointer to the data + 0xF99AAB41 ///< Expected CRC result + } }, + { .test_object = "Case 11 - CRC16 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x6A }, ///< Pointer to the data buffer + 0xD07F ///< Expected CRC result + } }, + { .test_object = "Case 12 - CRC16 - AUG - CCITT", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1021, ///< The polynominal to calculate CRC + 0x1D0F, ///< The initial value to calculate CRC + 0x0, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xD4 }, ///< Pointer to the data buffer + 0x4765 ///< Expected CRC result + } }, + { .test_object = "Case 13 - CRC16 - USB", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0xFFFF, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x3F, 0xA6 }, ///< Pointer to the data buffer + 0xC56F ///< Expected CRC result + } }, + { .test_object = "Case 14 - CRC16 - TELEDISK", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA097, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xE9, 0x4C }, ///< Pointer to the data buffer + 0x5794 ///< Expected CRC result + } }, + { .test_object = "Case 15 - CRC16 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xB17E, ///< The polynominal to calculate CRC + 0x4FC0, ///< The initial value to calculate CRC + 0xA25B, ///< The final xor value to calculate CRC + 7, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x3C, 0xE7, 0xA9, 0x52, 0x1D, 0xB6, + 0x80 }, ///< Pointer to the data buffer + 0xE1FF ///< Expected CRC result + } }, + { .test_object = "Case 16 - CRC16 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x3AF7, ///< The polynominal to calculate CRC + 0x9C21, ///< The initial value to calculate CRC + 0x6ED4, ///< The final xor value to calculate CRC + 89, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xDD, 0xF1, 0xCB, 0xFB, 0xE8, 0x83, 0x9B, 0x1C, 0xB7, 0xE3, 0x5B, + 0xDB, 0x91, 0x4E, 0x3B, 0x05, 0xF3, 0x64, 0x4F, 0x42, 0x70, 0x1B, 0x98, + 0x2F, 0x71, 0xDF, 0xF2, 0x35, 0xD3, 0xE3, 0x22, 0x3D, 0xD7, 0x34, 0xD1, + 0x67, 0x49, 0x59, 0x2D, 0x35, 0x8C, 0x4F, 0xC9, 0x81, 0x2B, 0xDB, 0x1F, + 0xEA, 0x7F, 0x61, 0x78, 0x66, 0xDA, 0xDB, 0x31, 0xE6, 0xE7, 0xBD, 0x74, + 0xCE, 0x87, 0x9A, 0x72, 0xE7, 0x25, 0x90, 0xA8, 0xDE, 0x0D, 0x3B, 0x43, + 0xF9, 0x45, 0x7D, 0x43, 0x09, 0x63, 0xF2, 0x74, 0x9B, 0x90, 0x64, 0x8C, + 0xC1, 0x0A, 0x1C, 0x8D, 0x5D, 0xE7 }, ///< Pointer to the data buffer + 0x385B ///< Expected CRC result + } }, + { .test_object = "Case 21 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x4D ///< Expected CRC result + } }, + { .test_object = "Case 22 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x4E }, ///< Pointer to the data buffer + 0x59 ///< Expected CRC result + } }, + { .test_object = "Case 23 - CRC8 - SAE - J1850", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1D, ///< The polynominal to calculate CRC + 0xFF, ///< The initial value to calculate CRC + 0xFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0xB2, 0x7A }, ///< Pointer to the data buffer + 0xA5 ///< Expected CRC result + } }, + { .test_object = "Case 24 - CRC8 - ITU", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x55, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x3C, 0xE5 }, ///< Pointer to the data buffer + 0xE5 ///< Expected CRC result + } }, + { .test_object = "Case 25 - CRC8 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x6A, ///< The polynominal to calculate CRC + 0xD8, ///< The initial value to calculate CRC + 0x0F, ///< The final xor value to calculate CRC + 19, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x6C, 0xC7, 0x85, 0x25, 0x2E, 0xCE, 0x6C, 0xF3, 0x2A, + 0x25, 0x31, 0xBF, 0x85, 0x2E, 0xCA, 0xED, 0x98, 0x59, 0x12 }, ///< Pointer to the data buffer + 0x2D ///< Expected CRC result + } }, + { .test_object = "Case 26 - CRC8 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7E, ///< The polynominal to calculate CRC + 0xB4, ///< The initial value to calculate CRC + 0x19, ///< The final xor value to calculate CRC + 29, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0xA3, 0xF2, 0x34, 0x5C, 0xB9, 0x81, 0xF8, 0x0E, 0x54, + 0xC1, 0xDD, 0x01, 0x70, 0xFF, 0x5F, 0xEB, 0x2E, 0x74, 0xCE, + 0x31, 0x65, 0xD0, 0xA4, 0xE3, 0x1F, 0xAD, 0x97, 0x3A, 0x46 }, ///< Pointer to the data buffer + 0x57 ///< Expected CRC result + } }, + { .test_object = "Case 27 - CRC8 - Random 03", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC2, ///< The polynominal to calculate CRC + 0x5A, ///< The initial value to calculate CRC + 0x8F, ///< The final xor value to calculate CRC + 911, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x00, 0x4A, 0xD2, 0xFE, 0x95, 0xB6, 0x4F, 0xA5, 0xC0, 0x6B, 0x0C, + 0xF6, 0xD6, 0xA8, 0xDC, 0x3C, 0x9B, 0xED, 0x3C, 0xEB, 0xB9, 0x03, 0x05, 0x41, + 0x32, 0xF5, 0x91, 0x66, 0xD2, 0x7E, 0x65, 0xD1, 0x09, 0x19, 0x3C, 0xD9, 0xE3, + 0x58, 0x7B, 0x24, 0xCD, 0xD8, 0xB9, 0xC2, 0x5F, 0xF0, 0xE3, 0xF2, 0x68, 0x37, + 0xDC, 0xDC, 0xFA, 0x0C, 0x02, 0x2C, 0x7B, 0xC9, 0x60, 0x7F, 0x1E, 0x8F, 0x98, + 0x41, 0x00, 0x22, 0x66, 0x2C, 0xA8, 0x61, 0x5A, 0x2F, 0xCD, 0x52, 0x01, 0xB3, + 0xDC, 0xD6, 0x2B, 0x54, 0x3D, 0xA4, 0x86, 0xDE, 0xEB, 0xD8, 0x71, 0xC1, 0x7C, + 0xDE, 0x36, 0x16, 0x13, 0x29, 0xE9, 0xB7, 0x50, 0x7F, 0x78, 0x08, 0xCF, 0x07, + 0x7A, 0xF2, 0xAD, 0x36, 0x3A, 0x8E, 0x4A, 0x0C, 0xB0, 0x6C, 0xD2, 0x28, 0xD4, + 0xE9, 0x09, 0x85, 0x3E, 0xB5, 0x3E, 0x9C, 0x40, 0xE4, 0x38, 0xAE, 0x7B, 0x63, + 0xE5, 0xF7, 0xE9, 0x47, 0x94, 0xB6, 0x4D, 0x2E, 0xF9, 0x5C, 0x9B, 0xCF, 0xE0, + 0x16, 0xFC, 0xAF, 0x0B, 0x56, 0xA1, 0x0D, 0xD6, 0xA1, 0x3E, 0xDB, 0x7D, 0xA0, + 0x32, 0x32, 0xD8, 0x86, 0x30, 0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C3, 0xA7, 0xF7, + 0x35, 0xEB, 0x35, 0xBD, 0x1F, 0x55, 0x65, 0x44, 0x98, 0x74, 0xF8, 0x15, 0xFF, + 0xA3, 0xE5, 0x61, 0x4E, 0x96, 0x27, 0xCB, 0x0E, 0x30, 0x40, 0x00, 0xDB, 0x46, + 0x43, 0x90, 0x59, 0x37 }, ///< Pointer to the data buffer + 0xC9 ///< Expected CRC result + } } +}; /***** Functions *****/ -void DMA0_IRQHandler(void) +void run_demo_crc(int asynchronous) { - MXC_DMA_Handler(); - MXC_DMA_ReleaseChannel(0); - wait = 0; -} + int total_cases = sizeof(test_cases_crc) / sizeof(test_case_mxc_crc_full_req_t); + int i = 0; + int j = 0; + mxc_crc_full_req_t tmp_full_req; -void Test_CRC(int asynchronous) -{ - uint32_t array[101]; - int i; + printf("Demo MAXIM CRC-32 Accelerator, total = %d cases\n", total_cases); - printf(asynchronous ? "TEST CRC ASYNC\n" : "TEST CRC SYNC\n"); + printf(asynchronous ? "TEST CRC ASYNC ****************\n" : + "TEST CRC SYNC *****************\n"); - for (i = 0; i < 100; i++) { - array[i] = i; - } + for (i = 0; i < total_cases; i++) { + printf("%s:\n", test_cases_crc[i].test_object); - mxc_crc_req_t crc_req = { array, 100, 0 }; + if (test_cases_crc[i].test_req->inputReflected == CRC_REFLECTED) { + printf(" Input reflected: YES\n"); + } else { + printf(" Input reflected: NO\n"); + } - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + if (test_cases_crc[i].test_req->resultReflected == CRC_REFLECTED) { + printf(" Result reflected: YES\n"); + } else { + printf(" Result reflected: NO\n"); + } - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + printf(" Polynomial: 0x%08X\n", test_cases_crc[i].test_req->polynominal); + printf(" Initial Value: 0x%08X\n", test_cases_crc[i].test_req->initialValue); + printf(" Final Xor Value: 0x%08X\n", test_cases_crc[i].test_req->finalXorValue); + printf(" Length: %d byte(s)\n", test_cases_crc[i].test_req->dataLen); + printf( + " Begin Address: %p\n", + (void *)&( + test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress])); - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Input Data:", test_cases_crc[i].test_req->dataLen); + for (j = 0; j < test_cases_crc[i].test_req->dataLen; j++) { + printf(" 0x%02X", + test_cases_crc[i] + .test_req->dataBuffer[j + test_cases_crc[i].test_req->beginAddress]); + } + printf("\n"); - printf("\nCRC Poly Result: %x", crc_req.resultCRC); + printf(" Expected CRC Result: 0x%08X (From internet web ...)\n", + test_cases_crc[i].test_req->expectedResultCRC); - array[100] = ~(crc_req.resultCRC); + tmp_full_req.inputReflected = test_cases_crc[i].test_req->inputReflected; + tmp_full_req.resultReflected = test_cases_crc[i].test_req->resultReflected; + tmp_full_req.polynominal = test_cases_crc[i].test_req->polynominal; + tmp_full_req.initialValue = test_cases_crc[i].test_req->initialValue; + tmp_full_req.finalXorValue = test_cases_crc[i].test_req->finalXorValue; + tmp_full_req.dataLen = test_cases_crc[i].test_req->dataLen; + tmp_full_req.dataBuffer = + &(test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress]); - crc_req.dataLen = 101; + MXC_CRC_Init(); - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + if (asynchronous == 0) { + MXC_CRC_Calculate(&tmp_full_req); + } else { + MXC_CRC_CalculateAsync(&tmp_full_req); - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + while (tmp_full_req.req_state == CRC_NOT_DONE) {} + } - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Actual CRC Result: 0x%08X ", tmp_full_req.resultCRC); + if (test_cases_crc[i].test_req->expectedResultCRC == tmp_full_req.resultCRC) { + printf("PASSED!\n"); + } else { + printf("FAILED!\n"); + } - printf("\nCRC Check Result: %x", crc_req.resultCRC); + MXC_CRC_Shutdown(); - if (CHECK != crc_req.resultCRC) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); + printf("\n"); } +} - MXC_CRC_Shutdown(); +void DMA0_IRQHandler(void) +{ + MXC_DMA_Handler(); } // ***************************************************************************** int main(void) { - printf("\nCRC Sync and Async Example\n\n"); - - Test_CRC(0); - - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); + MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); // TBD NVIC_EnableIRQ(DMA0_IRQn); - Test_CRC(1); - if (fail) { - printf("\nExample Failed\n"); - return E_FAIL; - } + run_demo_crc(0); + run_demo_crc(1); + + while (1) {} - printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32655/CRC/project.mk b/Examples/MAX32655/CRC/project.mk index df25f6eb71c..12393623cde 100644 --- a/Examples/MAX32655/CRC/project.mk +++ b/Examples/MAX32655/CRC/project.mk @@ -1,6 +1,6 @@ ############################################################################### # - # Copyright (C) 2024 Analog Devices, Inc. + # Copyright (C) 2024-2025 Analog Devices, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,3 +25,5 @@ # ********************************************************** # Add your config here! + + diff --git a/Examples/MAX32670/CRC/main.c b/Examples/MAX32670/CRC/main.c index a325ad2c038..aae7ec9e5cb 100644 --- a/Examples/MAX32670/CRC/main.c +++ b/Examples/MAX32670/CRC/main.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,97 +33,520 @@ #include "dma.h" /***** Definitions *****/ -#define POLY 0xEDB88320 -#define CHECK 0xDEBB20E3 +typedef struct _test_data_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint32_t dataLen; ///< Length of the data + uint32_t beginAddress; ///< Begin address of the data + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t expectedResultCRC; ///< Expected CRC result +} test_data_t; + +typedef struct _test_case_mxc_crc_full_req_t { + char *test_object; + test_data_t *test_req; +} test_case_mxc_crc_full_req_t; /***** Globals *****/ -volatile int wait; -volatile int callback_result; -volatile int counter; -volatile int fail = 0; +test_case_mxc_crc_full_req_t test_cases_crc[] = { + { .test_object = "Case 01 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x9DDD1DDF ///< Expected CRC result + } }, + { .test_object = "Case 02 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x07 }, ///< Pointer to the data + 0x4C667A2E ///< Expected CRC result + } }, + { .test_object = "Case 03 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x4E, 0xB2 }, ///< Pointer to the data + 0x0A4CA2D4 ///< Expected CRC result + } }, + { .test_object = "Case 04 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x89, 0x3D }, ///< Pointer to the data + 0xF3F07DEC ///< Expected CRC result + } }, + { .test_object = "Case 05 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 5, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0xD4, 0x6A, 0x1E, 0xB9, 0x03 }, ///< Pointer to the data + 0x547AF3D2 ///< Expected CRC result + } }, + { .test_object = "Case 06 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x5FC812A7, ///< The polynominal to calculate CRC + 0x3AE17FC4, ///< The initial value to calculate CRC + 0x760DA8F1, ///< The final xor value to calculate CRC + 23, ///< Length of the data + 1, ///< Begin address of the data + ( + uint8_t[]){ 0x00, 0x4D, 0x10, 0xDD, 0x70, 0xB9, 0x43, 0xFE, + 0xC1, 0x94, 0x1B, 0x09, 0xA0, 0x9C, 0xE8, 0x8D, + 0xF6, 0x04, 0x85, 0x9D, 0xCD, 0xE8, 0x69, 0x95 }, ///< Pointer to the data + 0x27823A8C ///< Expected CRC result + } }, + { .test_object = "Case 07 - CRC32 - Extra test Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x2CF7813E, ///< The polynominal to calculate CRC + 0xE358A17B, ///< The initial value to calculate CRC + 0x6DB42A90, ///< The final xor value to calculate CRC + 17, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x75, 0xDC, 0x92, 0xEB, 0xF6, 0x9D, 0x71, 0xF8, 0x7D, 0x1B, + 0x70, 0x86, 0xAC, 0x14, 0xF2, 0xF0, 0x8E }, ///< Pointer to the data + 0x0D346433 ///< Expected CRC result + } }, + { .test_object = "Case 08 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA53CE719, ///< The polynominal to calculate CRC + 0x4AD26F88, ///< The initial value to calculate CRC + 0xF936B02E, ///< The final xor value to calculate CRC + 13, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x8B, 0x1E, 0xD2, 0x7D, 0x7C, 0x8C, 0xA5, 0xAA, 0x06, + 0x8E, 0xCA, 0xCD, 0x4E }, ///< Pointer to the data + 0xDAA1D40B ///< Expected CRC result + } }, + { .test_object = "Case 09 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC72FA218, ///< The polynominal to calculate CRC + 0x7EC359A0, ///< The initial value to calculate CRC + 0xD81CF467, ///< The final xor value to calculate CRC + 79, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x3B, 0xAA, 0x9B, 0xAD, 0xBF, 0x8E, 0x73, 0x2A, 0x95, 0x00, 0x96, + 0xAF, 0xD0, 0xE4, 0x4D, 0xAB, 0x64, 0xB5, 0xAD, 0x76, 0x9C, 0x38, 0xEE, + 0xB3, 0xD6, 0x6D, 0x68, 0x43, 0xCB, 0xD9, 0x27, 0xFE, 0x95, 0x9A, 0xAD, + 0x01, 0x94, 0x84, 0xA8, 0x49, 0xAD, 0xC9, 0x3B, 0x0B, 0x3B, 0x5A, 0x55, + 0x99, 0xDE, 0xB4, 0x50, 0xAF, 0xE6, 0x85, 0xB4, 0x49, 0x1B, 0xB5, 0x45, + 0x94, 0x83, 0xAD, 0x68, 0x5D, 0x51, 0x43, 0xAB, 0x6B, 0xCC, 0xCB, 0xB4, + 0xD3, 0x6D, 0xCD, 0x03, 0x9D, 0x62, 0x1E, 0xAA }, ///< Pointer to the data + 0x8412B11F ///< Expected CRC result + } }, + { .test_object = "Case 0A - CRC32 - Extra test: Popular Example CRC-32/AUTOSAR", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xF4ACFB13, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 47, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x2E, 0x23, 0x58, 0xC9, 0x34, 0x9C, 0x57, 0xCB, 0x41, 0x77, 0xC2, + 0x4D, 0x66, 0xAB, 0x16, 0xDC, 0x96, 0xA8, 0x3D, 0xE4, 0x65, 0x10, 0x07, 0x33, + 0x1B, 0x85, 0x25, 0xED, 0xD3, 0x23, 0x70, 0xBA, 0xE3, 0xF9, 0x73, 0xDA, 0x5D, + 0x01, 0x90, 0x25, 0x82, 0x73, 0x73, 0x21, 0x9A, 0xD1, 0x7B }, ///< Pointer to the data + 0xF99AAB41 ///< Expected CRC result + } }, + { .test_object = "Case 11 - CRC16 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x6A }, ///< Pointer to the data buffer + 0xD07F ///< Expected CRC result + } }, + { .test_object = "Case 12 - CRC16 - AUG - CCITT", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1021, ///< The polynominal to calculate CRC + 0x1D0F, ///< The initial value to calculate CRC + 0x0, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xD4 }, ///< Pointer to the data buffer + 0x4765 ///< Expected CRC result + } }, + { .test_object = "Case 13 - CRC16 - USB", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0xFFFF, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x3F, 0xA6 }, ///< Pointer to the data buffer + 0xC56F ///< Expected CRC result + } }, + { .test_object = "Case 14 - CRC16 - TELEDISK", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA097, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xE9, 0x4C }, ///< Pointer to the data buffer + 0x5794 ///< Expected CRC result + } }, + { .test_object = "Case 15 - CRC16 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xB17E, ///< The polynominal to calculate CRC + 0x4FC0, ///< The initial value to calculate CRC + 0xA25B, ///< The final xor value to calculate CRC + 7, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x3C, 0xE7, 0xA9, 0x52, 0x1D, 0xB6, + 0x80 }, ///< Pointer to the data buffer + 0xE1FF ///< Expected CRC result + } }, + { .test_object = "Case 16 - CRC16 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x3AF7, ///< The polynominal to calculate CRC + 0x9C21, ///< The initial value to calculate CRC + 0x6ED4, ///< The final xor value to calculate CRC + 89, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xDD, 0xF1, 0xCB, 0xFB, 0xE8, 0x83, 0x9B, 0x1C, 0xB7, 0xE3, 0x5B, + 0xDB, 0x91, 0x4E, 0x3B, 0x05, 0xF3, 0x64, 0x4F, 0x42, 0x70, 0x1B, 0x98, + 0x2F, 0x71, 0xDF, 0xF2, 0x35, 0xD3, 0xE3, 0x22, 0x3D, 0xD7, 0x34, 0xD1, + 0x67, 0x49, 0x59, 0x2D, 0x35, 0x8C, 0x4F, 0xC9, 0x81, 0x2B, 0xDB, 0x1F, + 0xEA, 0x7F, 0x61, 0x78, 0x66, 0xDA, 0xDB, 0x31, 0xE6, 0xE7, 0xBD, 0x74, + 0xCE, 0x87, 0x9A, 0x72, 0xE7, 0x25, 0x90, 0xA8, 0xDE, 0x0D, 0x3B, 0x43, + 0xF9, 0x45, 0x7D, 0x43, 0x09, 0x63, 0xF2, 0x74, 0x9B, 0x90, 0x64, 0x8C, + 0xC1, 0x0A, 0x1C, 0x8D, 0x5D, 0xE7 }, ///< Pointer to the data buffer + 0x385B ///< Expected CRC result + } }, + { .test_object = "Case 21 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x4D ///< Expected CRC result + } }, + { .test_object = "Case 22 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x4E }, ///< Pointer to the data buffer + 0x59 ///< Expected CRC result + } }, + { .test_object = "Case 23 - CRC8 - SAE - J1850", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1D, ///< The polynominal to calculate CRC + 0xFF, ///< The initial value to calculate CRC + 0xFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0xB2, 0x7A }, ///< Pointer to the data buffer + 0xA5 ///< Expected CRC result + } }, + { .test_object = "Case 24 - CRC8 - ITU", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x55, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x3C, 0xE5 }, ///< Pointer to the data buffer + 0xE5 ///< Expected CRC result + } }, + { .test_object = "Case 25 - CRC8 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x6A, ///< The polynominal to calculate CRC + 0xD8, ///< The initial value to calculate CRC + 0x0F, ///< The final xor value to calculate CRC + 19, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x6C, 0xC7, 0x85, 0x25, 0x2E, 0xCE, 0x6C, 0xF3, 0x2A, + 0x25, 0x31, 0xBF, 0x85, 0x2E, 0xCA, 0xED, 0x98, 0x59, 0x12 }, ///< Pointer to the data buffer + 0x2D ///< Expected CRC result + } }, + { .test_object = "Case 26 - CRC8 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7E, ///< The polynominal to calculate CRC + 0xB4, ///< The initial value to calculate CRC + 0x19, ///< The final xor value to calculate CRC + 29, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0xA3, 0xF2, 0x34, 0x5C, 0xB9, 0x81, 0xF8, 0x0E, 0x54, + 0xC1, 0xDD, 0x01, 0x70, 0xFF, 0x5F, 0xEB, 0x2E, 0x74, 0xCE, + 0x31, 0x65, 0xD0, 0xA4, 0xE3, 0x1F, 0xAD, 0x97, 0x3A, 0x46 }, ///< Pointer to the data buffer + 0x57 ///< Expected CRC result + } }, + { .test_object = "Case 27 - CRC8 - Random 03", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC2, ///< The polynominal to calculate CRC + 0x5A, ///< The initial value to calculate CRC + 0x8F, ///< The final xor value to calculate CRC + 911, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x00, 0x4A, 0xD2, 0xFE, 0x95, 0xB6, 0x4F, 0xA5, 0xC0, 0x6B, 0x0C, + 0xF6, 0xD6, 0xA8, 0xDC, 0x3C, 0x9B, 0xED, 0x3C, 0xEB, 0xB9, 0x03, 0x05, 0x41, + 0x32, 0xF5, 0x91, 0x66, 0xD2, 0x7E, 0x65, 0xD1, 0x09, 0x19, 0x3C, 0xD9, 0xE3, + 0x58, 0x7B, 0x24, 0xCD, 0xD8, 0xB9, 0xC2, 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0x5A, 0x92, + 0x0F, 0x58, 0x00, 0x8E, 0xF6, 0xAB, 0xFA, 0x3A, 0x6A, 0x3B, 0x2D, 0xE9, 0x62, + 0x60, 0x57, 0x08, 0xB4, 0xBF, 0x6A, 0xA2, 0x97, 0xCF, 0x45, 0x81, 0x6B, 0x1F, + 0x40, 0xAD, 0x8A, 0xE5, 0xCE, 0x08, 0x30, 0x74, 0x19, 0x67, 0x2C, 0x42, 0x80, + 0x22, 0xDF, 0x18, 0x46, 0x5D, 0xAB, 0xF1, 0xB5, 0x5D, 0xB7, 0xAE, 0xB6, 0x41, + 0xFD, 0xA2, 0x9C, 0x30, 0x31, 0x13, 0xE8, 0x31, 0x96, 0x30, 0x7C, 0xF0, 0x14, + 0xF5, 0x51, 0x1A, 0xD8, 0xFD, 0x6F, 0x7A, 0xC1, 0x00, 0xFD, 0x83, 0x87, 0xF5, + 0x44, 0x1A, 0xAA, 0x6F, 0x80, 0xED, 0x28, 0x3F, 0x6B, 0x9E, 0xAF, 0xEF, 0x1C, + 0xD0, 0xA3, 0xAB, 0xE4, 0xDA, 0xC7, 0x19, 0x0B, 0x76, 0x6C, 0x49, 0x28, 0xB7, + 0xE5, 0x58, 0xDE, 0xCF, 0x2D, 0x69, 0x37, 0x0D, 0xFE, 0x22, 0xC3, 0xA7, 0xF7, + 0x35, 0xEB, 0x35, 0xBD, 0x1F, 0x55, 0x65, 0x44, 0x98, 0x74, 0xF8, 0x15, 0xFF, + 0xA3, 0xE5, 0x61, 0x4E, 0x96, 0x27, 0xCB, 0x0E, 0x30, 0x40, 0x00, 0xDB, 0x46, + 0x43, 0x90, 0x59, 0x37 }, ///< Pointer to the data buffer + 0xC9 ///< Expected CRC result + } } +}; /***** Functions *****/ -void DMA0_IRQHandler(void) +void run_demo_crc(int asynchronous) { - MXC_DMA_Handler(); - MXC_DMA_ReleaseChannel(0); - wait = 0; -} + int total_cases = sizeof(test_cases_crc) / sizeof(test_case_mxc_crc_full_req_t); + int i = 0; + int j = 0; + mxc_crc_full_req_t tmp_full_req; -void Test_CRC(int asynchronous) -{ - uint32_t array[101]; - int i; + printf("Demo MAXIM CRC-32 Accelerator, total = %d cases\n", total_cases); - printf(asynchronous ? "TEST CRC ASYNC\n" : "TEST CRC SYNC\n"); + printf(asynchronous ? "TEST CRC ASYNC ****************\n" : + "TEST CRC SYNC *****************\n"); - for (i = 0; i < 100; i++) { - array[i] = i; - } + for (i = 0; i < total_cases; i++) { + printf("%s:\n", test_cases_crc[i].test_object); - mxc_crc_req_t crc_req = { array, 100, 0 }; + if (test_cases_crc[i].test_req->inputReflected == CRC_REFLECTED) { + printf(" Input reflected: YES\n"); + } else { + printf(" Input reflected: NO\n"); + } - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + if (test_cases_crc[i].test_req->resultReflected == CRC_REFLECTED) { + printf(" Result reflected: YES\n"); + } else { + printf(" Result reflected: NO\n"); + } - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + printf(" Polynomial: 0x%08X\n", test_cases_crc[i].test_req->polynominal); + printf(" Initial Value: 0x%08X\n", test_cases_crc[i].test_req->initialValue); + printf(" Final Xor Value: 0x%08X\n", test_cases_crc[i].test_req->finalXorValue); + printf(" Length: %d byte(s)\n", test_cases_crc[i].test_req->dataLen); + printf( + " Begin Address: %p\n", + (void *)&( + test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress])); - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Input Data:", test_cases_crc[i].test_req->dataLen); + for (j = 0; j < test_cases_crc[i].test_req->dataLen; j++) { + printf(" 0x%02X", + test_cases_crc[i] + .test_req->dataBuffer[j + test_cases_crc[i].test_req->beginAddress]); + } + printf("\n"); - printf("\nCRC Poly Result: %x", crc_req.resultCRC); + printf(" Expected CRC Result: 0x%08X (From internet web ...)\n", + test_cases_crc[i].test_req->expectedResultCRC); - array[100] = ~(crc_req.resultCRC); + tmp_full_req.inputReflected = test_cases_crc[i].test_req->inputReflected; + tmp_full_req.resultReflected = test_cases_crc[i].test_req->resultReflected; + tmp_full_req.polynominal = test_cases_crc[i].test_req->polynominal; + tmp_full_req.initialValue = test_cases_crc[i].test_req->initialValue; + tmp_full_req.finalXorValue = test_cases_crc[i].test_req->finalXorValue; + tmp_full_req.dataLen = test_cases_crc[i].test_req->dataLen; + tmp_full_req.dataBuffer = + &(test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress]); - crc_req.dataLen = 101; + MXC_CRC_Init(); - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + if (asynchronous == 0) { + MXC_CRC_Calculate(&tmp_full_req); + } else { + MXC_CRC_CalculateAsync(&tmp_full_req); - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + while (tmp_full_req.req_state == CRC_NOT_DONE) {} + } - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Actual CRC Result: 0x%08X ", tmp_full_req.resultCRC); + if (test_cases_crc[i].test_req->expectedResultCRC == tmp_full_req.resultCRC) { + printf("PASSED!\n"); + } else { + printf("FAILED!\n"); + } - printf("\nCRC Check Result: %x", crc_req.resultCRC); + MXC_CRC_Shutdown(); - if (CHECK != crc_req.resultCRC) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); + printf("\n"); } +} - MXC_CRC_Shutdown(); +void DMA0_IRQHandler(void) +{ + MXC_DMA_Handler(); } // ***************************************************************************** int main(void) { - printf("\nCRC Sync and Async Example\n\n"); - - Test_CRC(0); - - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); + MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); // TBD NVIC_EnableIRQ(DMA0_IRQn); - Test_CRC(1); - if (fail != 0) { - printf("\nExample Failed\n"); - return E_FAIL; - } + run_demo_crc(0); + run_demo_crc(1); + + while (1) {} - printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32670/CRC/project.mk b/Examples/MAX32670/CRC/project.mk index d296a156a11..ecb7a81e77a 100644 --- a/Examples/MAX32670/CRC/project.mk +++ b/Examples/MAX32670/CRC/project.mk @@ -1,6 +1,6 @@ ############################################################################### # - # Copyright (C) 2024 Analog Devices, Inc. + # Copyright (C) 2024-2025 Analog Devices, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,3 +29,5 @@ # ********************************************************** # Add your config here! + + diff --git a/Examples/MAX32675/CRC/main.c b/Examples/MAX32675/CRC/main.c index d0b9a44fe52..a72e6d2969b 100644 --- a/Examples/MAX32675/CRC/main.c +++ b/Examples/MAX32675/CRC/main.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,97 +35,520 @@ #include "dma.h" /***** Definitions *****/ -#define POLY 0xEDB88320 -#define CHECK 0xDEBB20E3 +typedef struct _test_data_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint32_t dataLen; ///< Length of the data + uint32_t beginAddress; ///< Begin address of the data + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t expectedResultCRC; ///< Expected CRC result +} test_data_t; + +typedef struct _test_case_mxc_crc_full_req_t { + char *test_object; + test_data_t *test_req; +} test_case_mxc_crc_full_req_t; /***** Globals *****/ -volatile int wait; -volatile int callback_result; -volatile int counter; -volatile int fail = 0; +test_case_mxc_crc_full_req_t test_cases_crc[] = { + { .test_object = "Case 01 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x9DDD1DDF ///< Expected CRC result + } }, + { .test_object = "Case 02 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x07 }, ///< Pointer to the data + 0x4C667A2E ///< Expected CRC result + } }, + { .test_object = "Case 03 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x4E, 0xB2 }, ///< Pointer to the data + 0x0A4CA2D4 ///< Expected CRC result + } }, + { .test_object = "Case 04 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x89, 0x3D }, ///< Pointer to the data + 0xF3F07DEC ///< Expected CRC result + } }, + { .test_object = "Case 05 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 5, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0xD4, 0x6A, 0x1E, 0xB9, 0x03 }, ///< Pointer to the data + 0x547AF3D2 ///< Expected CRC result + } }, + { .test_object = "Case 06 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x5FC812A7, ///< The polynominal to calculate CRC + 0x3AE17FC4, ///< The initial value to calculate CRC + 0x760DA8F1, ///< The final xor value to calculate CRC + 23, ///< Length of the data + 1, ///< Begin address of the data + ( + uint8_t[]){ 0x00, 0x4D, 0x10, 0xDD, 0x70, 0xB9, 0x43, 0xFE, + 0xC1, 0x94, 0x1B, 0x09, 0xA0, 0x9C, 0xE8, 0x8D, + 0xF6, 0x04, 0x85, 0x9D, 0xCD, 0xE8, 0x69, 0x95 }, ///< Pointer to the data + 0x27823A8C ///< Expected CRC result + } }, + { .test_object = "Case 07 - CRC32 - Extra test Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x2CF7813E, ///< The polynominal to calculate CRC + 0xE358A17B, ///< The initial value to calculate CRC + 0x6DB42A90, ///< The final xor value to calculate CRC + 17, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x75, 0xDC, 0x92, 0xEB, 0xF6, 0x9D, 0x71, 0xF8, 0x7D, 0x1B, + 0x70, 0x86, 0xAC, 0x14, 0xF2, 0xF0, 0x8E }, ///< Pointer to the data + 0x0D346433 ///< Expected CRC result + } }, + { .test_object = "Case 08 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA53CE719, ///< The polynominal to calculate CRC + 0x4AD26F88, ///< The initial value to calculate CRC + 0xF936B02E, ///< The final xor value to calculate CRC + 13, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x8B, 0x1E, 0xD2, 0x7D, 0x7C, 0x8C, 0xA5, 0xAA, 0x06, + 0x8E, 0xCA, 0xCD, 0x4E }, ///< Pointer to the data + 0xDAA1D40B ///< Expected CRC result + } }, + { .test_object = "Case 09 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC72FA218, ///< The polynominal to calculate CRC + 0x7EC359A0, ///< The initial value to calculate CRC + 0xD81CF467, ///< The final xor value to calculate CRC + 79, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x3B, 0xAA, 0x9B, 0xAD, 0xBF, 0x8E, 0x73, 0x2A, 0x95, 0x00, 0x96, + 0xAF, 0xD0, 0xE4, 0x4D, 0xAB, 0x64, 0xB5, 0xAD, 0x76, 0x9C, 0x38, 0xEE, + 0xB3, 0xD6, 0x6D, 0x68, 0x43, 0xCB, 0xD9, 0x27, 0xFE, 0x95, 0x9A, 0xAD, + 0x01, 0x94, 0x84, 0xA8, 0x49, 0xAD, 0xC9, 0x3B, 0x0B, 0x3B, 0x5A, 0x55, + 0x99, 0xDE, 0xB4, 0x50, 0xAF, 0xE6, 0x85, 0xB4, 0x49, 0x1B, 0xB5, 0x45, + 0x94, 0x83, 0xAD, 0x68, 0x5D, 0x51, 0x43, 0xAB, 0x6B, 0xCC, 0xCB, 0xB4, + 0xD3, 0x6D, 0xCD, 0x03, 0x9D, 0x62, 0x1E, 0xAA }, ///< Pointer to the data + 0x8412B11F ///< Expected CRC result + } }, + { .test_object = "Case 0A - CRC32 - Extra test: Popular Example CRC-32/AUTOSAR", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xF4ACFB13, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 47, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x2E, 0x23, 0x58, 0xC9, 0x34, 0x9C, 0x57, 0xCB, 0x41, 0x77, 0xC2, + 0x4D, 0x66, 0xAB, 0x16, 0xDC, 0x96, 0xA8, 0x3D, 0xE4, 0x65, 0x10, 0x07, 0x33, + 0x1B, 0x85, 0x25, 0xED, 0xD3, 0x23, 0x70, 0xBA, 0xE3, 0xF9, 0x73, 0xDA, 0x5D, + 0x01, 0x90, 0x25, 0x82, 0x73, 0x73, 0x21, 0x9A, 0xD1, 0x7B }, ///< Pointer to the data + 0xF99AAB41 ///< Expected CRC result + } }, + { .test_object = "Case 11 - CRC16 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x6A }, ///< Pointer to the data buffer + 0xD07F ///< Expected CRC result + } }, + { .test_object = "Case 12 - CRC16 - AUG - CCITT", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1021, ///< The polynominal to calculate CRC + 0x1D0F, ///< The initial value to calculate CRC + 0x0, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xD4 }, ///< Pointer to the data buffer + 0x4765 ///< Expected CRC result + } }, + { .test_object = "Case 13 - CRC16 - USB", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0xFFFF, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x3F, 0xA6 }, ///< Pointer to the data buffer + 0xC56F ///< Expected CRC result + } }, + { .test_object = "Case 14 - CRC16 - TELEDISK", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA097, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xE9, 0x4C }, ///< Pointer to the data buffer + 0x5794 ///< Expected CRC result + } }, + { .test_object = "Case 15 - CRC16 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xB17E, ///< The polynominal to calculate CRC + 0x4FC0, ///< The initial value to calculate CRC + 0xA25B, ///< The final xor value to calculate CRC + 7, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x3C, 0xE7, 0xA9, 0x52, 0x1D, 0xB6, + 0x80 }, ///< Pointer to the data buffer + 0xE1FF ///< Expected CRC result + } }, + { .test_object = "Case 16 - CRC16 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x3AF7, ///< The polynominal to calculate CRC + 0x9C21, ///< The initial value to calculate CRC + 0x6ED4, ///< The final xor value to calculate CRC + 89, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xDD, 0xF1, 0xCB, 0xFB, 0xE8, 0x83, 0x9B, 0x1C, 0xB7, 0xE3, 0x5B, + 0xDB, 0x91, 0x4E, 0x3B, 0x05, 0xF3, 0x64, 0x4F, 0x42, 0x70, 0x1B, 0x98, + 0x2F, 0x71, 0xDF, 0xF2, 0x35, 0xD3, 0xE3, 0x22, 0x3D, 0xD7, 0x34, 0xD1, + 0x67, 0x49, 0x59, 0x2D, 0x35, 0x8C, 0x4F, 0xC9, 0x81, 0x2B, 0xDB, 0x1F, + 0xEA, 0x7F, 0x61, 0x78, 0x66, 0xDA, 0xDB, 0x31, 0xE6, 0xE7, 0xBD, 0x74, + 0xCE, 0x87, 0x9A, 0x72, 0xE7, 0x25, 0x90, 0xA8, 0xDE, 0x0D, 0x3B, 0x43, + 0xF9, 0x45, 0x7D, 0x43, 0x09, 0x63, 0xF2, 0x74, 0x9B, 0x90, 0x64, 0x8C, + 0xC1, 0x0A, 0x1C, 0x8D, 0x5D, 0xE7 }, ///< Pointer to the data buffer + 0x385B ///< Expected CRC result + } }, + { .test_object = "Case 21 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x4D ///< Expected CRC result + } }, + { .test_object = "Case 22 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x4E }, ///< Pointer to the data buffer + 0x59 ///< Expected CRC result + } }, + { .test_object = "Case 23 - CRC8 - SAE - J1850", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1D, ///< The polynominal to calculate CRC + 0xFF, ///< The initial value to calculate CRC + 0xFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0xB2, 0x7A }, ///< Pointer to the data buffer + 0xA5 ///< Expected CRC result + } }, + { .test_object = "Case 24 - CRC8 - ITU", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x55, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x3C, 0xE5 }, ///< Pointer to the data buffer + 0xE5 ///< Expected CRC result + } }, + { .test_object = "Case 25 - CRC8 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x6A, ///< The polynominal to calculate CRC + 0xD8, ///< The initial value to calculate CRC + 0x0F, ///< The final xor value to calculate CRC + 19, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x6C, 0xC7, 0x85, 0x25, 0x2E, 0xCE, 0x6C, 0xF3, 0x2A, + 0x25, 0x31, 0xBF, 0x85, 0x2E, 0xCA, 0xED, 0x98, 0x59, 0x12 }, ///< Pointer to the data buffer + 0x2D ///< Expected CRC result + } }, + { .test_object = "Case 26 - CRC8 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7E, ///< The polynominal to calculate CRC + 0xB4, ///< The initial value to calculate CRC + 0x19, ///< The final xor value to calculate CRC + 29, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0xA3, 0xF2, 0x34, 0x5C, 0xB9, 0x81, 0xF8, 0x0E, 0x54, + 0xC1, 0xDD, 0x01, 0x70, 0xFF, 0x5F, 0xEB, 0x2E, 0x74, 0xCE, + 0x31, 0x65, 0xD0, 0xA4, 0xE3, 0x1F, 0xAD, 0x97, 0x3A, 0x46 }, ///< Pointer to the data buffer + 0x57 ///< Expected CRC result + } }, + { .test_object = "Case 27 - CRC8 - Random 03", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC2, ///< The polynominal to calculate CRC + 0x5A, ///< The initial value to calculate CRC + 0x8F, ///< The final xor value to calculate CRC + 911, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x00, 0x4A, 0xD2, 0xFE, 0x95, 0xB6, 0x4F, 0xA5, 0xC0, 0x6B, 0x0C, + 0xF6, 0xD6, 0xA8, 0xDC, 0x3C, 0x9B, 0xED, 0x3C, 0xEB, 0xB9, 0x03, 0x05, 0x41, + 0x32, 0xF5, 0x91, 0x66, 0xD2, 0x7E, 0x65, 0xD1, 0x09, 0x19, 0x3C, 0xD9, 0xE3, + 0x58, 0x7B, 0x24, 0xCD, 0xD8, 0xB9, 0xC2, 0x5F, 0xF0, 0xE3, 0xF2, 0x68, 0x37, + 0xDC, 0xDC, 0xFA, 0x0C, 0x02, 0x2C, 0x7B, 0xC9, 0x60, 0x7F, 0x1E, 0x8F, 0x98, + 0x41, 0x00, 0x22, 0x66, 0x2C, 0xA8, 0x61, 0x5A, 0x2F, 0xCD, 0x52, 0x01, 0xB3, + 0xDC, 0xD6, 0x2B, 0x54, 0x3D, 0xA4, 0x86, 0xDE, 0xEB, 0xD8, 0x71, 0xC1, 0x7C, + 0xDE, 0x36, 0x16, 0x13, 0x29, 0xE9, 0xB7, 0x50, 0x7F, 0x78, 0x08, 0xCF, 0x07, + 0x7A, 0xF2, 0xAD, 0x36, 0x3A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x30, 0x7C, 0xF0, 0x14, + 0xF5, 0x51, 0x1A, 0xD8, 0xFD, 0x6F, 0x7A, 0xC1, 0x00, 0xFD, 0x83, 0x87, 0xF5, + 0x44, 0x1A, 0xAA, 0x6F, 0x80, 0xED, 0x28, 0x3F, 0x6B, 0x9E, 0xAF, 0xEF, 0x1C, + 0xD0, 0xA3, 0xAB, 0xE4, 0xDA, 0xC7, 0x19, 0x0B, 0x76, 0x6C, 0x49, 0x28, 0xB7, + 0xE5, 0x58, 0xDE, 0xCF, 0x2D, 0x69, 0x37, 0x0D, 0xFE, 0x22, 0xC3, 0xA7, 0xF7, + 0x35, 0xEB, 0x35, 0xBD, 0x1F, 0x55, 0x65, 0x44, 0x98, 0x74, 0xF8, 0x15, 0xFF, + 0xA3, 0xE5, 0x61, 0x4E, 0x96, 0x27, 0xCB, 0x0E, 0x30, 0x40, 0x00, 0xDB, 0x46, + 0x43, 0x90, 0x59, 0x37 }, ///< Pointer to the data buffer + 0xC9 ///< Expected CRC result + } } +}; /***** Functions *****/ -void DMA0_IRQHandler(void) +void run_demo_crc(int asynchronous) { - MXC_DMA_Handler(); - MXC_DMA_ReleaseChannel(0); - wait = 0; -} + int total_cases = sizeof(test_cases_crc) / sizeof(test_case_mxc_crc_full_req_t); + int i = 0; + int j = 0; + mxc_crc_full_req_t tmp_full_req; -void Test_CRC(int asynchronous) -{ - uint32_t array[101]; - int i; + printf("Demo MAXIM CRC-32 Accelerator, total = %d cases\n", total_cases); - printf(asynchronous ? "TEST CRC ASYNC\n" : "TEST CRC SYNC\n"); + printf(asynchronous ? "TEST CRC ASYNC ****************\n" : + "TEST CRC SYNC *****************\n"); - for (i = 0; i < 100; i++) { - array[i] = i; - } + for (i = 0; i < total_cases; i++) { + printf("%s:\n", test_cases_crc[i].test_object); - mxc_crc_req_t crc_req = { array, 100, 0 }; + if (test_cases_crc[i].test_req->inputReflected == CRC_REFLECTED) { + printf(" Input reflected: YES\n"); + } else { + printf(" Input reflected: NO\n"); + } - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + if (test_cases_crc[i].test_req->resultReflected == CRC_REFLECTED) { + printf(" Result reflected: YES\n"); + } else { + printf(" Result reflected: NO\n"); + } - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + printf(" Polynomial: 0x%08X\n", test_cases_crc[i].test_req->polynominal); + printf(" Initial Value: 0x%08X\n", test_cases_crc[i].test_req->initialValue); + printf(" Final Xor Value: 0x%08X\n", test_cases_crc[i].test_req->finalXorValue); + printf(" Length: %d byte(s)\n", test_cases_crc[i].test_req->dataLen); + printf( + " Begin Address: %p\n", + (void *)&( + test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress])); - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Input Data:", test_cases_crc[i].test_req->dataLen); + for (j = 0; j < test_cases_crc[i].test_req->dataLen; j++) { + printf(" 0x%02X", + test_cases_crc[i] + .test_req->dataBuffer[j + test_cases_crc[i].test_req->beginAddress]); + } + printf("\n"); - printf("\nCRC Poly Result: %x", crc_req.resultCRC); + printf(" Expected CRC Result: 0x%08X (From internet web ...)\n", + test_cases_crc[i].test_req->expectedResultCRC); - array[100] = ~(crc_req.resultCRC); + tmp_full_req.inputReflected = test_cases_crc[i].test_req->inputReflected; + tmp_full_req.resultReflected = test_cases_crc[i].test_req->resultReflected; + tmp_full_req.polynominal = test_cases_crc[i].test_req->polynominal; + tmp_full_req.initialValue = test_cases_crc[i].test_req->initialValue; + tmp_full_req.finalXorValue = test_cases_crc[i].test_req->finalXorValue; + tmp_full_req.dataLen = test_cases_crc[i].test_req->dataLen; + tmp_full_req.dataBuffer = + &(test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress]); - crc_req.dataLen = 101; + MXC_CRC_Init(); - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + if (asynchronous == 0) { + MXC_CRC_Calculate(&tmp_full_req); + } else { + MXC_CRC_CalculateAsync(&tmp_full_req); - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + while (tmp_full_req.req_state == CRC_NOT_DONE) {} + } - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Actual CRC Result: 0x%08X ", tmp_full_req.resultCRC); + if (test_cases_crc[i].test_req->expectedResultCRC == tmp_full_req.resultCRC) { + printf("PASSED!\n"); + } else { + printf("FAILED!\n"); + } - printf("\nCRC Check Result: %x", crc_req.resultCRC); + MXC_CRC_Shutdown(); - if (CHECK != crc_req.resultCRC) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); + printf("\n"); } +} - MXC_CRC_Shutdown(); +void DMA0_IRQHandler(void) +{ + MXC_DMA_Handler(); } // ***************************************************************************** int main(void) { - printf("\nCRC Sync and Async Example\n\n"); - - Test_CRC(0); - - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); + MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); // TBD NVIC_EnableIRQ(DMA0_IRQn); - Test_CRC(1); - if (fail != 0) { - printf("\nExample Failed\n"); - return E_FAIL; - } + run_demo_crc(0); + run_demo_crc(1); + + while (1) {} - printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX32675/CRC/project.mk b/Examples/MAX32675/CRC/project.mk index df25f6eb71c..d1d491f7bac 100644 --- a/Examples/MAX32675/CRC/project.mk +++ b/Examples/MAX32675/CRC/project.mk @@ -1,6 +1,6 @@ ############################################################################### # - # Copyright (C) 2024 Analog Devices, Inc. + # Copyright (C) 2024-2025 Analog Devices, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,3 +25,4 @@ # ********************************************************** # Add your config here! + diff --git a/Examples/MAX78000/CRC/main.c b/Examples/MAX78000/CRC/main.c index a7c0547a69e..a7f3c091539 100644 --- a/Examples/MAX78000/CRC/main.c +++ b/Examples/MAX78000/CRC/main.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,12 +20,13 @@ /** * @file main.c - * @brief Example showing how to use the CRC module. Covers 32-bit CRC. + * @brief Example showing how to use the CRC module. Covers 16 and 32-bit CRC. */ /***** Includes *****/ #include #include +#include #include "mxc_device.h" #include "nvic_table.h" #include "board.h" @@ -33,107 +34,520 @@ #include "dma.h" /***** Definitions *****/ -#define POLY 0xEDB88320 -#define CHECK 0xDEBB20E3 +typedef struct _test_data_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint32_t dataLen; ///< Length of the data + uint32_t beginAddress; ///< Begin address of the data + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t expectedResultCRC; ///< Expected CRC result +} test_data_t; -#define SYNC 0 -#define ASYNC 1 - -#define DATA_LENGTH 100 +typedef struct _test_case_mxc_crc_full_req_t { + char *test_object; + test_data_t *test_req; +} test_case_mxc_crc_full_req_t; /***** Globals *****/ -volatile int wait; -int fail = 0; +test_case_mxc_crc_full_req_t test_cases_crc[] = { + { .test_object = "Case 01 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x9DDD1DDF ///< Expected CRC result + } }, + { .test_object = "Case 02 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x07 }, ///< Pointer to the data + 0x4C667A2E ///< Expected CRC result + } }, + { .test_object = "Case 03 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x4E, 0xB2 }, ///< Pointer to the data + 0x0A4CA2D4 ///< Expected CRC result + } }, + { .test_object = "Case 04 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x89, 0x3D }, ///< Pointer to the data + 0xF3F07DEC ///< Expected CRC result + } }, + { .test_object = "Case 05 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 5, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0xD4, 0x6A, 0x1E, 0xB9, 0x03 }, ///< Pointer to the data + 0x547AF3D2 ///< Expected CRC result + } }, + { .test_object = "Case 06 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x5FC812A7, ///< The polynominal to calculate CRC + 0x3AE17FC4, ///< The initial value to calculate CRC + 0x760DA8F1, ///< The final xor value to calculate CRC + 23, ///< Length of the data + 1, ///< Begin address of the data + ( + uint8_t[]){ 0x00, 0x4D, 0x10, 0xDD, 0x70, 0xB9, 0x43, 0xFE, + 0xC1, 0x94, 0x1B, 0x09, 0xA0, 0x9C, 0xE8, 0x8D, + 0xF6, 0x04, 0x85, 0x9D, 0xCD, 0xE8, 0x69, 0x95 }, ///< Pointer to the data + 0x27823A8C ///< Expected CRC result + } }, + { .test_object = "Case 07 - CRC32 - Extra test Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x2CF7813E, ///< The polynominal to calculate CRC + 0xE358A17B, ///< The initial value to calculate CRC + 0x6DB42A90, ///< The final xor value to calculate CRC + 17, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x75, 0xDC, 0x92, 0xEB, 0xF6, 0x9D, 0x71, 0xF8, 0x7D, 0x1B, + 0x70, 0x86, 0xAC, 0x14, 0xF2, 0xF0, 0x8E }, ///< Pointer to the data + 0x0D346433 ///< Expected CRC result + } }, + { .test_object = "Case 08 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA53CE719, ///< The polynominal to calculate CRC + 0x4AD26F88, ///< The initial value to calculate CRC + 0xF936B02E, ///< The final xor value to calculate CRC + 13, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x8B, 0x1E, 0xD2, 0x7D, 0x7C, 0x8C, 0xA5, 0xAA, 0x06, + 0x8E, 0xCA, 0xCD, 0x4E }, ///< Pointer to the data + 0xDAA1D40B ///< Expected CRC result + } }, + { .test_object = "Case 09 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC72FA218, ///< The polynominal to calculate CRC + 0x7EC359A0, ///< The initial value to calculate CRC + 0xD81CF467, ///< The final xor value to calculate CRC + 79, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x3B, 0xAA, 0x9B, 0xAD, 0xBF, 0x8E, 0x73, 0x2A, 0x95, 0x00, 0x96, + 0xAF, 0xD0, 0xE4, 0x4D, 0xAB, 0x64, 0xB5, 0xAD, 0x76, 0x9C, 0x38, 0xEE, + 0xB3, 0xD6, 0x6D, 0x68, 0x43, 0xCB, 0xD9, 0x27, 0xFE, 0x95, 0x9A, 0xAD, + 0x01, 0x94, 0x84, 0xA8, 0x49, 0xAD, 0xC9, 0x3B, 0x0B, 0x3B, 0x5A, 0x55, + 0x99, 0xDE, 0xB4, 0x50, 0xAF, 0xE6, 0x85, 0xB4, 0x49, 0x1B, 0xB5, 0x45, + 0x94, 0x83, 0xAD, 0x68, 0x5D, 0x51, 0x43, 0xAB, 0x6B, 0xCC, 0xCB, 0xB4, + 0xD3, 0x6D, 0xCD, 0x03, 0x9D, 0x62, 0x1E, 0xAA }, ///< Pointer to the data + 0x8412B11F ///< Expected CRC result + } }, + { .test_object = "Case 0A - CRC32 - Extra test: Popular Example CRC-32/AUTOSAR", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xF4ACFB13, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 47, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x2E, 0x23, 0x58, 0xC9, 0x34, 0x9C, 0x57, 0xCB, 0x41, 0x77, 0xC2, + 0x4D, 0x66, 0xAB, 0x16, 0xDC, 0x96, 0xA8, 0x3D, 0xE4, 0x65, 0x10, 0x07, 0x33, + 0x1B, 0x85, 0x25, 0xED, 0xD3, 0x23, 0x70, 0xBA, 0xE3, 0xF9, 0x73, 0xDA, 0x5D, + 0x01, 0x90, 0x25, 0x82, 0x73, 0x73, 0x21, 0x9A, 0xD1, 0x7B }, ///< Pointer to the data + 0xF99AAB41 ///< Expected CRC result + } }, + { .test_object = "Case 11 - CRC16 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x6A }, ///< Pointer to the data buffer + 0xD07F ///< Expected CRC result + } }, + { .test_object = "Case 12 - CRC16 - AUG - CCITT", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1021, ///< The polynominal to calculate CRC + 0x1D0F, ///< The initial value to calculate CRC + 0x0, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xD4 }, ///< Pointer to the data buffer + 0x4765 ///< Expected CRC result + } }, + { .test_object = "Case 13 - CRC16 - USB", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0xFFFF, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x3F, 0xA6 }, ///< Pointer to the data buffer + 0xC56F ///< Expected CRC result + } }, + { .test_object = "Case 14 - CRC16 - TELEDISK", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA097, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xE9, 0x4C }, ///< Pointer to the data buffer + 0x5794 ///< Expected CRC result + } }, + { .test_object = "Case 15 - CRC16 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xB17E, ///< The polynominal to calculate CRC + 0x4FC0, ///< The initial value to calculate CRC + 0xA25B, ///< The final xor value to calculate CRC + 7, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x3C, 0xE7, 0xA9, 0x52, 0x1D, 0xB6, + 0x80 }, ///< Pointer to the data buffer + 0xE1FF ///< Expected CRC result + } }, + { .test_object = "Case 16 - CRC16 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x3AF7, ///< The polynominal to calculate CRC + 0x9C21, ///< The initial value to calculate CRC + 0x6ED4, ///< The final xor value to calculate CRC + 89, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xDD, 0xF1, 0xCB, 0xFB, 0xE8, 0x83, 0x9B, 0x1C, 0xB7, 0xE3, 0x5B, + 0xDB, 0x91, 0x4E, 0x3B, 0x05, 0xF3, 0x64, 0x4F, 0x42, 0x70, 0x1B, 0x98, + 0x2F, 0x71, 0xDF, 0xF2, 0x35, 0xD3, 0xE3, 0x22, 0x3D, 0xD7, 0x34, 0xD1, + 0x67, 0x49, 0x59, 0x2D, 0x35, 0x8C, 0x4F, 0xC9, 0x81, 0x2B, 0xDB, 0x1F, + 0xEA, 0x7F, 0x61, 0x78, 0x66, 0xDA, 0xDB, 0x31, 0xE6, 0xE7, 0xBD, 0x74, + 0xCE, 0x87, 0x9A, 0x72, 0xE7, 0x25, 0x90, 0xA8, 0xDE, 0x0D, 0x3B, 0x43, + 0xF9, 0x45, 0x7D, 0x43, 0x09, 0x63, 0xF2, 0x74, 0x9B, 0x90, 0x64, 0x8C, + 0xC1, 0x0A, 0x1C, 0x8D, 0x5D, 0xE7 }, ///< Pointer to the data buffer + 0x385B ///< Expected CRC result + } }, + { .test_object = "Case 21 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x4D ///< Expected CRC result + } }, + { .test_object = "Case 22 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x4E }, ///< Pointer to the data buffer + 0x59 ///< Expected CRC result + } }, + { .test_object = "Case 23 - CRC8 - SAE - J1850", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1D, ///< The polynominal to calculate CRC + 0xFF, ///< The initial value to calculate CRC + 0xFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0xB2, 0x7A }, ///< Pointer to the data buffer + 0xA5 ///< Expected CRC result + } }, + { .test_object = "Case 24 - CRC8 - ITU", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x55, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x3C, 0xE5 }, ///< Pointer to the data buffer + 0xE5 ///< Expected CRC result + } }, + { .test_object = "Case 25 - CRC8 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x6A, ///< The polynominal to calculate CRC + 0xD8, ///< The initial value to calculate CRC + 0x0F, ///< The final xor value to calculate CRC + 19, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x6C, 0xC7, 0x85, 0x25, 0x2E, 0xCE, 0x6C, 0xF3, 0x2A, + 0x25, 0x31, 0xBF, 0x85, 0x2E, 0xCA, 0xED, 0x98, 0x59, 0x12 }, ///< Pointer to the data buffer + 0x2D ///< Expected CRC result + } }, + { .test_object = "Case 26 - CRC8 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7E, ///< The polynominal to calculate CRC + 0xB4, ///< The initial value to calculate CRC + 0x19, ///< The final xor value to calculate CRC + 29, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0xA3, 0xF2, 0x34, 0x5C, 0xB9, 0x81, 0xF8, 0x0E, 0x54, + 0xC1, 0xDD, 0x01, 0x70, 0xFF, 0x5F, 0xEB, 0x2E, 0x74, 0xCE, + 0x31, 0x65, 0xD0, 0xA4, 0xE3, 0x1F, 0xAD, 0x97, 0x3A, 0x46 }, ///< Pointer to the data buffer + 0x57 ///< Expected CRC result + } }, + { .test_object = "Case 27 - CRC8 - Random 03", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC2, ///< The polynominal to calculate CRC + 0x5A, ///< The initial value to calculate CRC + 0x8F, ///< The final xor value to calculate CRC + 911, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x00, 0x4A, 0xD2, 0xFE, 0x95, 0xB6, 0x4F, 0xA5, 0xC0, 0x6B, 0x0C, + 0xF6, 0xD6, 0xA8, 0xDC, 0x3C, 0x9B, 0xED, 0x3C, 0xEB, 0xB9, 0x03, 0x05, 0x41, + 0x32, 0xF5, 0x91, 0x66, 0xD2, 0x7E, 0x65, 0xD1, 0x09, 0x19, 0x3C, 0xD9, 0xE3, + 0x58, 0x7B, 0x24, 0xCD, 0xD8, 0xB9, 0xC2, 0x5F, 0xF0, 0xE3, 0xF2, 0x68, 0x37, + 0xDC, 0xDC, 0xFA, 0x0C, 0x02, 0x2C, 0x7B, 0xC9, 0x60, 0x7F, 0x1E, 0x8F, 0x98, + 0x41, 0x00, 0x22, 0x66, 0x2C, 0xA8, 0x61, 0x5A, 0x2F, 0xCD, 0x52, 0x01, 0xB3, + 0xDC, 0xD6, 0x2B, 0x54, 0x3D, 0xA4, 0x86, 0xDE, 0xEB, 0xD8, 0x71, 0xC1, 0x7C, + 0xDE, 0x36, 0x16, 0x13, 0x29, 0xE9, 0xB7, 0x50, 0x7F, 0x78, 0x08, 0xCF, 0x07, + 0x7A, 0xF2, 0xAD, 0x36, 0x3A, 0x8E, 0x4A, 0x0C, 0xB0, 0x6C, 0xD2, 0x28, 0xD4, + 0xE9, 0x09, 0x85, 0x3E, 0xB5, 0x3E, 0x9C, 0x40, 0xE4, 0x38, 0xAE, 0x7B, 0x63, + 0xE5, 0xF7, 0xE9, 0x47, 0x94, 0xB6, 0x4D, 0x2E, 0xF9, 0x5C, 0x9B, 0xCF, 0xE0, + 0x16, 0x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0x19, 0x0B, 0x76, 0x6C, 0x49, 0x28, 0xB7, + 0xE5, 0x58, 0xDE, 0xCF, 0x2D, 0x69, 0x37, 0x0D, 0xFE, 0x22, 0xC3, 0xA7, 0xF7, + 0x35, 0xEB, 0x35, 0xBD, 0x1F, 0x55, 0x65, 0x44, 0x98, 0x74, 0xF8, 0x15, 0xFF, + 0xA3, 0xE5, 0x61, 0x4E, 0x96, 0x27, 0xCB, 0x0E, 0x30, 0x40, 0x00, 0xDB, 0x46, + 0x43, 0x90, 0x59, 0x37 }, ///< Pointer to the data buffer + 0xC9 ///< Expected CRC result + } } +}; /***** Functions *****/ -void DMA0_IRQHandler(void) +void run_demo_crc(int asynchronous) { - MXC_DMA_Handler(); - MXC_DMA_ReleaseChannel(0); - wait = 0; -} + int total_cases = sizeof(test_cases_crc) / sizeof(test_case_mxc_crc_full_req_t); + int i = 0; + int j = 0; + mxc_crc_full_req_t tmp_full_req; -void Test_CRC(int asynchronous) -{ - uint32_t array[101]; - int i; + printf("Demo MAXIM CRC-32 Accelerator, total = %d cases\n", total_cases); - printf(asynchronous ? "TEST CRC ASYNC\n" : "TEST CRC SYNC\n"); + printf(asynchronous ? "TEST CRC ASYNC ****************\n" : + "TEST CRC SYNC *****************\n"); - for (i = 0; i < DATA_LENGTH; i++) { - array[i] = i; - } + for (i = 0; i < total_cases; i++) { + printf("%s:\n", test_cases_crc[i].test_object); - // define the CRC parameters - mxc_crc_req_t crc_req = { - array, // pointer to data - DATA_LENGTH, // length of data - 0 // initial crc result - }; + if (test_cases_crc[i].test_req->inputReflected == CRC_REFLECTED) { + printf(" Input reflected: YES\n"); + } else { + printf(" Input reflected: NO\n"); + } - MXC_CRC_Init(); + if (test_cases_crc[i].test_req->resultReflected == CRC_REFLECTED) { + printf(" Result reflected: YES\n"); + } else { + printf(" Result reflected: NO\n"); + } - MXC_CRC_SetPoly(POLY); + printf(" Polynomial: 0x%08X\n", test_cases_crc[i].test_req->polynominal); + printf(" Initial Value: 0x%08X\n", test_cases_crc[i].test_req->initialValue); + printf(" Final Xor Value: 0x%08X\n", test_cases_crc[i].test_req->finalXorValue); + printf(" Length: %d byte(s)\n", test_cases_crc[i].test_req->dataLen); + printf( + " Begin Address: %p\n", + (void *)&( + test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress])); - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + printf(" Input Data:", test_cases_crc[i].test_req->dataLen); + for (j = 0; j < test_cases_crc[i].test_req->dataLen; j++) { + printf(" 0x%02X", + test_cases_crc[i] + .test_req->dataBuffer[j + test_cases_crc[i].test_req->beginAddress]); + } + printf("\n"); - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Expected CRC Result: 0x%08X (From internet web ...)\n", + test_cases_crc[i].test_req->expectedResultCRC); - printf("\nComputed CRC: %x", crc_req.resultCRC); + tmp_full_req.inputReflected = test_cases_crc[i].test_req->inputReflected; + tmp_full_req.resultReflected = test_cases_crc[i].test_req->resultReflected; + tmp_full_req.polynominal = test_cases_crc[i].test_req->polynominal; + tmp_full_req.initialValue = test_cases_crc[i].test_req->initialValue; + tmp_full_req.finalXorValue = test_cases_crc[i].test_req->finalXorValue; + tmp_full_req.dataLen = test_cases_crc[i].test_req->dataLen; + tmp_full_req.dataBuffer = + &(test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress]); - array[DATA_LENGTH] = ~crc_req.resultCRC; + MXC_CRC_Init(); - crc_req.dataLen = DATA_LENGTH + 1; + if (asynchronous == 0) { + MXC_CRC_Calculate(&tmp_full_req); + } else { + MXC_CRC_CalculateAsync(&tmp_full_req); - MXC_CRC_Init(); + while (tmp_full_req.req_state == CRC_NOT_DONE) {} + } - MXC_CRC_SetPoly(POLY); + printf(" Actual CRC Result: 0x%08X ", tmp_full_req.resultCRC); + if (test_cases_crc[i].test_req->expectedResultCRC == tmp_full_req.resultCRC) { + printf("PASSED!\n"); + } else { + printf("FAILED!\n"); + } - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + MXC_CRC_Shutdown(); - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); + printf("\n"); } +} - printf("\nCRC Check Result: %x", crc_req.resultCRC); - - MXC_CRC_Shutdown(); - - if (CHECK != crc_req.resultCRC) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); - } +void DMA0_IRQHandler(void) +{ + MXC_DMA_Handler(); } // ***************************************************************************** int main(void) { - printf("\n***** CRC Example *****\n\n"); - - Test_CRC(SYNC); - - //Release DMA Channel 0 to use it for CRC transaction (Any DMA channel can be used) - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); + MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); // TBD NVIC_EnableIRQ(DMA0_IRQn); - __enable_irq(); - Test_CRC(ASYNC); - if (fail != 0) { - printf("\nExample Failed\n"); - return E_FAIL; - } + run_demo_crc(0); + run_demo_crc(1); + + while (1) {} - printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX78000/CRC/project.mk b/Examples/MAX78000/CRC/project.mk index 3499393b3bb..93bce18cd3b 100644 --- a/Examples/MAX78000/CRC/project.mk +++ b/Examples/MAX78000/CRC/project.mk @@ -1,6 +1,6 @@ ############################################################################### # - # Copyright (C) 2024 Analog Devices, Inc. + # Copyright (C) 2024-2025 Analog Devices, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,13 +22,10 @@ # For instructions on how to use this system, see # https://analogdevicesinc.github.io/msdk/USERGUIDE/#build-system -#MXC_OPTIMIZE_CFLAGS = -Og -# ^ For example, you can uncomment this line to -# optimize the project for debugging - # ********************************************************** # Add your config here! + diff --git a/Examples/MAX78002/CRC/main.c b/Examples/MAX78002/CRC/main.c index f509ab3b66a..a7f3c091539 100644 --- a/Examples/MAX78002/CRC/main.c +++ b/Examples/MAX78002/CRC/main.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,97 +34,520 @@ #include "dma.h" /***** Definitions *****/ -#define POLY 0xEDB88320 -#define CHECK 0xDEBB20E3 +typedef struct _test_data_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint32_t dataLen; ///< Length of the data + uint32_t beginAddress; ///< Begin address of the data + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t expectedResultCRC; ///< Expected CRC result +} test_data_t; + +typedef struct _test_case_mxc_crc_full_req_t { + char *test_object; + test_data_t *test_req; +} test_case_mxc_crc_full_req_t; /***** Globals *****/ -volatile int wait; -volatile int callback_result; -volatile int counter; -volatile int fail = 0; +test_case_mxc_crc_full_req_t test_cases_crc[] = { + { .test_object = "Case 01 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x9DDD1DDF ///< Expected CRC result + } }, + { .test_object = "Case 02 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x07 }, ///< Pointer to the data + 0x4C667A2E ///< Expected CRC result + } }, + { .test_object = "Case 03 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x4E, 0xB2 }, ///< Pointer to the data + 0x0A4CA2D4 ///< Expected CRC result + } }, + { .test_object = "Case 04 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x89, 0x3D }, ///< Pointer to the data + 0xF3F07DEC ///< Expected CRC result + } }, + { .test_object = "Case 05 - CRC32 - Test original JIRA issue (Customer claim)", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x4C11DB7, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 5, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0xD4, 0x6A, 0x1E, 0xB9, 0x03 }, ///< Pointer to the data + 0x547AF3D2 ///< Expected CRC result + } }, + { .test_object = "Case 06 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x5FC812A7, ///< The polynominal to calculate CRC + 0x3AE17FC4, ///< The initial value to calculate CRC + 0x760DA8F1, ///< The final xor value to calculate CRC + 23, ///< Length of the data + 1, ///< Begin address of the data + ( + uint8_t[]){ 0x00, 0x4D, 0x10, 0xDD, 0x70, 0xB9, 0x43, 0xFE, + 0xC1, 0x94, 0x1B, 0x09, 0xA0, 0x9C, 0xE8, 0x8D, + 0xF6, 0x04, 0x85, 0x9D, 0xCD, 0xE8, 0x69, 0x95 }, ///< Pointer to the data + 0x27823A8C ///< Expected CRC result + } }, + { .test_object = "Case 07 - CRC32 - Extra test Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x2CF7813E, ///< The polynominal to calculate CRC + 0xE358A17B, ///< The initial value to calculate CRC + 0x6DB42A90, ///< The final xor value to calculate CRC + 17, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x75, 0xDC, 0x92, 0xEB, 0xF6, 0x9D, 0x71, 0xF8, 0x7D, 0x1B, + 0x70, 0x86, 0xAC, 0x14, 0xF2, 0xF0, 0x8E }, ///< Pointer to the data + 0x0D346433 ///< Expected CRC result + } }, + { .test_object = "Case 08 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA53CE719, ///< The polynominal to calculate CRC + 0x4AD26F88, ///< The initial value to calculate CRC + 0xF936B02E, ///< The final xor value to calculate CRC + 13, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x8B, 0x1E, 0xD2, 0x7D, 0x7C, 0x8C, 0xA5, 0xAA, 0x06, + 0x8E, 0xCA, 0xCD, 0x4E }, ///< Pointer to the data + 0xDAA1D40B ///< Expected CRC result + } }, + { .test_object = "Case 09 - CRC32 - Extra test: Random complicated test data", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC72FA218, ///< The polynominal to calculate CRC + 0x7EC359A0, ///< The initial value to calculate CRC + 0xD81CF467, ///< The final xor value to calculate CRC + 79, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x3B, 0xAA, 0x9B, 0xAD, 0xBF, 0x8E, 0x73, 0x2A, 0x95, 0x00, 0x96, + 0xAF, 0xD0, 0xE4, 0x4D, 0xAB, 0x64, 0xB5, 0xAD, 0x76, 0x9C, 0x38, 0xEE, + 0xB3, 0xD6, 0x6D, 0x68, 0x43, 0xCB, 0xD9, 0x27, 0xFE, 0x95, 0x9A, 0xAD, + 0x01, 0x94, 0x84, 0xA8, 0x49, 0xAD, 0xC9, 0x3B, 0x0B, 0x3B, 0x5A, 0x55, + 0x99, 0xDE, 0xB4, 0x50, 0xAF, 0xE6, 0x85, 0xB4, 0x49, 0x1B, 0xB5, 0x45, + 0x94, 0x83, 0xAD, 0x68, 0x5D, 0x51, 0x43, 0xAB, 0x6B, 0xCC, 0xCB, 0xB4, + 0xD3, 0x6D, 0xCD, 0x03, 0x9D, 0x62, 0x1E, 0xAA }, ///< Pointer to the data + 0x8412B11F ///< Expected CRC result + } }, + { .test_object = "Case 0A - CRC32 - Extra test: Popular Example CRC-32/AUTOSAR", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xF4ACFB13, ///< The polynominal to calculate CRC + 0xFFFFFFFF, ///< The initial value to calculate CRC + 0xFFFFFFFF, ///< The final xor value to calculate CRC + 47, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x2E, 0x23, 0x58, 0xC9, 0x34, 0x9C, 0x57, 0xCB, 0x41, 0x77, 0xC2, + 0x4D, 0x66, 0xAB, 0x16, 0xDC, 0x96, 0xA8, 0x3D, 0xE4, 0x65, 0x10, 0x07, 0x33, + 0x1B, 0x85, 0x25, 0xED, 0xD3, 0x23, 0x70, 0xBA, 0xE3, 0xF9, 0x73, 0xDA, 0x5D, + 0x01, 0x90, 0x25, 0x82, 0x73, 0x73, 0x21, 0x9A, 0xD1, 0x7B }, ///< Pointer to the data + 0xF99AAB41 ///< Expected CRC result + } }, + { .test_object = "Case 11 - CRC16 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x6A }, ///< Pointer to the data buffer + 0xD07F ///< Expected CRC result + } }, + { .test_object = "Case 12 - CRC16 - AUG - CCITT", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1021, ///< The polynominal to calculate CRC + 0x1D0F, ///< The initial value to calculate CRC + 0x0, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xD4 }, ///< Pointer to the data buffer + 0x4765 ///< Expected CRC result + } }, + { .test_object = "Case 13 - CRC16 - USB", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x8005, ///< The polynominal to calculate CRC + 0xFFFF, ///< The initial value to calculate CRC + 0xFFFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0x3F, 0xA6 }, ///< Pointer to the data buffer + 0xC56F ///< Expected CRC result + } }, + { .test_object = "Case 14 - CRC16 - TELEDISK", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xA097, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xE9, 0x4C }, ///< Pointer to the data buffer + 0x5794 ///< Expected CRC result + } }, + { .test_object = "Case 15 - CRC16 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0xB17E, ///< The polynominal to calculate CRC + 0x4FC0, ///< The initial value to calculate CRC + 0xA25B, ///< The final xor value to calculate CRC + 7, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x3C, 0xE7, 0xA9, 0x52, 0x1D, 0xB6, + 0x80 }, ///< Pointer to the data buffer + 0xE1FF ///< Expected CRC result + } }, + { .test_object = "Case 16 - CRC16 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x3AF7, ///< The polynominal to calculate CRC + 0x9C21, ///< The initial value to calculate CRC + 0x6ED4, ///< The final xor value to calculate CRC + 89, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0xDD, 0xF1, 0xCB, 0xFB, 0xE8, 0x83, 0x9B, 0x1C, 0xB7, 0xE3, 0x5B, + 0xDB, 0x91, 0x4E, 0x3B, 0x05, 0xF3, 0x64, 0x4F, 0x42, 0x70, 0x1B, 0x98, + 0x2F, 0x71, 0xDF, 0xF2, 0x35, 0xD3, 0xE3, 0x22, 0x3D, 0xD7, 0x34, 0xD1, + 0x67, 0x49, 0x59, 0x2D, 0x35, 0x8C, 0x4F, 0xC9, 0x81, 0x2B, 0xDB, 0x1F, + 0xEA, 0x7F, 0x61, 0x78, 0x66, 0xDA, 0xDB, 0x31, 0xE6, 0xE7, 0xBD, 0x74, + 0xCE, 0x87, 0x9A, 0x72, 0xE7, 0x25, 0x90, 0xA8, 0xDE, 0x0D, 0x3B, 0x43, + 0xF9, 0x45, 0x7D, 0x43, 0x09, 0x63, 0xF2, 0x74, 0x9B, 0x90, 0x64, 0x8C, + 0xC1, 0x0A, 0x1C, 0x8D, 0x5D, 0xE7 }, ///< Pointer to the data buffer + 0x385B ///< Expected CRC result + } }, + { .test_object = "Case 21 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0xA3 }, ///< Pointer to the data buffer + 0x4D ///< Expected CRC result + } }, + { .test_object = "Case 22 - CRC8 - MAXIM", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x31, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x00, ///< The final xor value to calculate CRC + 1, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x4E }, ///< Pointer to the data buffer + 0x59 ///< Expected CRC result + } }, + { .test_object = "Case 23 - CRC8 - SAE - J1850", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x1D, ///< The polynominal to calculate CRC + 0xFF, ///< The initial value to calculate CRC + 0xFF, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 3, ///< Begin address of the data + (uint8_t[]){ 0x00, 0x00, 0x00, 0xB2, 0x7A }, ///< Pointer to the data buffer + 0xA5 ///< Expected CRC result + } }, + { .test_object = "Case 24 - CRC8 - ITU", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7, ///< The polynominal to calculate CRC + 0x00, ///< The initial value to calculate CRC + 0x55, ///< The final xor value to calculate CRC + 2, ///< Length of the data + 0, ///< Begin address of the data + (uint8_t[]){ 0x3C, 0xE5 }, ///< Pointer to the data buffer + 0xE5 ///< Expected CRC result + } }, + { .test_object = "Case 25 - CRC8 - Random 01", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_REFLECTED, ///< Result reflected or not + 0x6A, ///< The polynominal to calculate CRC + 0xD8, ///< The initial value to calculate CRC + 0x0F, ///< The final xor value to calculate CRC + 19, ///< Length of the data + 2, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0x00, 0x6C, 0xC7, 0x85, 0x25, 0x2E, 0xCE, 0x6C, 0xF3, 0x2A, + 0x25, 0x31, 0xBF, 0x85, 0x2E, 0xCA, 0xED, 0x98, 0x59, 0x12 }, ///< Pointer to the data buffer + 0x2D ///< Expected CRC result + } }, + { .test_object = "Case 26 - CRC8 - Random 02", + .test_req = + (test_data_t[]){ + CRC_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0x7E, ///< The polynominal to calculate CRC + 0xB4, ///< The initial value to calculate CRC + 0x19, ///< The final xor value to calculate CRC + 29, ///< Length of the data + 1, ///< Begin address of the data + (uint8_t[]){ + 0x00, 0xA3, 0xF2, 0x34, 0x5C, 0xB9, 0x81, 0xF8, 0x0E, 0x54, + 0xC1, 0xDD, 0x01, 0x70, 0xFF, 0x5F, 0xEB, 0x2E, 0x74, 0xCE, + 0x31, 0x65, 0xD0, 0xA4, 0xE3, 0x1F, 0xAD, 0x97, 0x3A, 0x46 }, ///< Pointer to the data buffer + 0x57 ///< Expected CRC result + } }, + { .test_object = "Case 27 - CRC8 - Random 03", + .test_req = + (test_data_t[]){ + CRC_NOT_REFLECTED, ///< Input reflected or not + CRC_NOT_REFLECTED, ///< Result reflected or not + 0xC2, ///< The polynominal to calculate CRC + 0x5A, ///< The initial value to calculate CRC + 0x8F, ///< The final xor value to calculate CRC + 911, ///< Length of the data + 3, ///< Begin address of the data + (uint8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3, 0xE5, 0x61, 0x4E, 0x96, 0x27, 0xCB, 0x0E, 0x30, 0x40, 0x00, 0xDB, 0x46, + 0x43, 0x90, 0x59, 0x37 }, ///< Pointer to the data buffer + 0xC9 ///< Expected CRC result + } } +}; /***** Functions *****/ -void DMA0_IRQHandler(void) +void run_demo_crc(int asynchronous) { - MXC_DMA_Handler(); - MXC_DMA_ReleaseChannel(0); - wait = 0; -} + int total_cases = sizeof(test_cases_crc) / sizeof(test_case_mxc_crc_full_req_t); + int i = 0; + int j = 0; + mxc_crc_full_req_t tmp_full_req; -void Test_CRC(int asynchronous) -{ - uint32_t array[101]; - int i; + printf("Demo MAXIM CRC-32 Accelerator, total = %d cases\n", total_cases); - printf(asynchronous ? "TEST CRC ASYNC\n" : "TEST CRC SYNC\n"); + printf(asynchronous ? "TEST CRC ASYNC ****************\n" : + "TEST CRC SYNC *****************\n"); - for (i = 0; i < 100; i++) { - array[i] = i; - } - - mxc_crc_req_t crc_req = { array, 100, 0 }; + for (i = 0; i < total_cases; i++) { + printf("%s:\n", test_cases_crc[i].test_object); - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + if (test_cases_crc[i].test_req->inputReflected == CRC_REFLECTED) { + printf(" Input reflected: YES\n"); + } else { + printf(" Input reflected: NO\n"); + } - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + if (test_cases_crc[i].test_req->resultReflected == CRC_REFLECTED) { + printf(" Result reflected: YES\n"); + } else { + printf(" Result reflected: NO\n"); + } - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + printf(" Polynomial: 0x%08X\n", test_cases_crc[i].test_req->polynominal); + printf(" Initial Value: 0x%08X\n", test_cases_crc[i].test_req->initialValue); + printf(" Final Xor Value: 0x%08X\n", test_cases_crc[i].test_req->finalXorValue); + printf(" Length: %d byte(s)\n", test_cases_crc[i].test_req->dataLen); + printf( + " Begin Address: %p\n", + (void *)&( + test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress])); - printf("\nCRC Poly Result: %x", crc_req.resultCRC); + printf(" Input Data:", test_cases_crc[i].test_req->dataLen); + for (j = 0; j < test_cases_crc[i].test_req->dataLen; j++) { + printf(" 0x%02X", + test_cases_crc[i] + .test_req->dataBuffer[j + test_cases_crc[i].test_req->beginAddress]); + } + printf("\n"); - array[100] = ~(crc_req.resultCRC); + printf(" Expected CRC Result: 0x%08X (From internet web ...)\n", + test_cases_crc[i].test_req->expectedResultCRC); - crc_req.dataLen = 101; + tmp_full_req.inputReflected = test_cases_crc[i].test_req->inputReflected; + tmp_full_req.resultReflected = test_cases_crc[i].test_req->resultReflected; + tmp_full_req.polynominal = test_cases_crc[i].test_req->polynominal; + tmp_full_req.initialValue = test_cases_crc[i].test_req->initialValue; + tmp_full_req.finalXorValue = test_cases_crc[i].test_req->finalXorValue; + tmp_full_req.dataLen = test_cases_crc[i].test_req->dataLen; + tmp_full_req.dataBuffer = + &(test_cases_crc[i].test_req->dataBuffer[test_cases_crc[i].test_req->beginAddress]); - MXC_CRC_Init(); - // Load CRC polynomial into crc polynomial register - MXC_CRC_SetPoly(POLY); + MXC_CRC_Init(); - if (asynchronous) { - wait = 1; - MXC_CRC_ComputeAsync(&crc_req); + if (asynchronous == 0) { + MXC_CRC_Calculate(&tmp_full_req); + } else { + MXC_CRC_CalculateAsync(&tmp_full_req); - while (wait) {} - } else { - MXC_CRC_Compute(&crc_req); - } + while (tmp_full_req.req_state == CRC_NOT_DONE) {} + } - printf("\nCRC Check Result: %x", crc_req.resultCRC); + printf(" Actual CRC Result: 0x%08X ", tmp_full_req.resultCRC); + if (test_cases_crc[i].test_req->expectedResultCRC == tmp_full_req.resultCRC) { + printf("PASSED!\n"); + } else { + printf("FAILED!\n"); + } - MXC_CRC_Shutdown(); + MXC_CRC_Shutdown(); - if (CHECK != crc_req.resultCRC) { - printf(" \n**Test Failed**\n\n"); - fail++; - } else { - printf(" \n**Test Passed**\n\n"); + printf("\n"); } } +void DMA0_IRQHandler(void) +{ + MXC_DMA_Handler(); +} + // ***************************************************************************** int main(void) { - printf("\nCRC Sync and Async Example\n\n"); - - Test_CRC(0); - - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); + MXC_NVIC_SetVector(DMA0_IRQn, DMA0_IRQHandler); // TBD NVIC_EnableIRQ(DMA0_IRQn); - Test_CRC(1); - if (fail != 0) { - printf("\nExample Failed\n"); - return E_FAIL; - } + run_demo_crc(0); + run_demo_crc(1); + + while (1) {} - printf("\nExample Succeeded\n"); return E_NO_ERROR; } diff --git a/Examples/MAX78002/CRC/project.mk b/Examples/MAX78002/CRC/project.mk index 3499393b3bb..5590f1b8fe5 100644 --- a/Examples/MAX78002/CRC/project.mk +++ b/Examples/MAX78002/CRC/project.mk @@ -1,6 +1,6 @@ ############################################################################### # - # Copyright (C) 2024 Analog Devices, Inc. + # Copyright (C) 2024-2025 Analog Devices, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,3 +32,4 @@ + diff --git a/Libraries/PeriphDrivers/Include/MAX32655/crc.h b/Libraries/PeriphDrivers/Include/MAX32655/crc.h index c8fa4390550..713ff717352 100644 --- a/Libraries/PeriphDrivers/Include/MAX32655/crc.h +++ b/Libraries/PeriphDrivers/Include/MAX32655/crc.h @@ -7,7 +7,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,46 @@ typedef struct _mxc_crc_req_t { */ typedef enum { CRC_LSB_FIRST, CRC_MSB_FIRST } mxc_crc_bitorder_t; +/** + * @brief CRC data byte order + * + */ +typedef enum { CRC_LSBYTE_FIRST, CRC_MSBYTE_FIRST } mxc_crc_byteorder_t; + +/** + * @brief CRC reflected + * + */ +typedef enum { CRC_REFLECTED, CRC_NOT_REFLECTED } mxc_crc_reflected_t; + +/** + * @brief CRC request state DONE or NOT + * + */ +typedef enum { CRC_NOT_DONE, CRC_DONE } mxc_crc_req_state_t; + +/** + * @brief Structure used to set up Full CRC request + * + */ +typedef struct _mxc_crc_full_req_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t dataLen; ///< Length of the data + + volatile mxc_crc_reflected_t manual_reflected_input_required; + volatile uint8_t dmaChannel; + volatile uint32_t nextPosDMA; + volatile mxc_crc_req_state_t req_state; + + volatile uint32_t resultCRC; ///< Calculated CRC value + volatile int error; +} mxc_crc_full_req_t; + /***** Function Prototypes *****/ /* ************************************************************************* */ @@ -85,6 +125,14 @@ int MXC_CRC_Shutdown(void); */ void MXC_CRC_Handler(int ch, int error); +/** + * @brief This function should be called from the CRC ISR Handler + * when using Async functions for full request + * @param ch DMA channel + * @param error error + */ +void MXC_CRC_Full_Req_Handler(int ch, int error); + /** * @brief Set the bit-order of CRC calculation * @@ -161,6 +209,28 @@ int MXC_CRC_Compute(mxc_crc_req_t *req); */ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req); +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_Calculate(mxc_crc_full_req_t *req); + +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req); + #ifdef __cplusplus } #endif diff --git a/Libraries/PeriphDrivers/Include/MAX32670/crc.h b/Libraries/PeriphDrivers/Include/MAX32670/crc.h index b419a0fcfd5..ab63eb3526f 100644 --- a/Libraries/PeriphDrivers/Include/MAX32670/crc.h +++ b/Libraries/PeriphDrivers/Include/MAX32670/crc.h @@ -7,7 +7,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,46 @@ typedef struct _mxc_crc_req_t { */ typedef enum { CRC_LSB_FIRST, CRC_MSB_FIRST } mxc_crc_bitorder_t; +/** + * @brief CRC data byte order + * + */ +typedef enum { CRC_LSBYTE_FIRST, CRC_MSBYTE_FIRST } mxc_crc_byteorder_t; + +/** + * @brief CRC reflected + * + */ +typedef enum { CRC_REFLECTED, CRC_NOT_REFLECTED } mxc_crc_reflected_t; + +/** + * @brief CRC request state DONE or NOT + * + */ +typedef enum { CRC_NOT_DONE, CRC_DONE } mxc_crc_req_state_t; + +/** + * @brief Structure used to set up Full CRC request + * + */ +typedef struct _mxc_crc_full_req_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t dataLen; ///< Length of the data + + volatile mxc_crc_reflected_t manual_reflected_input_required; + volatile uint8_t dmaChannel; + volatile uint32_t nextPosDMA; + volatile mxc_crc_req_state_t req_state; + + volatile uint32_t resultCRC; ///< Calculated CRC value + volatile int error; +} mxc_crc_full_req_t; + /***** Function Prototypes *****/ /* ************************************************************************* */ @@ -85,6 +125,14 @@ int MXC_CRC_Shutdown(void); */ void MXC_CRC_Handler(int ch, int error); +/** + * @brief This function should be called from the CRC ISR Handler + * when using Async functions for full request + * @param ch DMA channel + * @param error error + */ +void MXC_CRC_Full_Req_Handler(int ch, int error); + /** * @brief Set the bit-order of CRC calculation * @@ -161,6 +209,28 @@ int MXC_CRC_Compute(mxc_crc_req_t *req); */ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req); +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_Calculate(mxc_crc_full_req_t *req); + +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req); + #ifdef __cplusplus } #endif diff --git a/Libraries/PeriphDrivers/Include/MAX32675/crc.h b/Libraries/PeriphDrivers/Include/MAX32675/crc.h index 5d0c64b5eac..eeb87b07602 100644 --- a/Libraries/PeriphDrivers/Include/MAX32675/crc.h +++ b/Libraries/PeriphDrivers/Include/MAX32675/crc.h @@ -7,7 +7,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,46 @@ typedef struct _mxc_crc_req_t { */ typedef enum { CRC_LSB_FIRST, CRC_MSB_FIRST } mxc_crc_bitorder_t; +/** + * @brief CRC data byte order + * + */ +typedef enum { CRC_LSBYTE_FIRST, CRC_MSBYTE_FIRST } mxc_crc_byteorder_t; + +/** + * @brief CRC reflected + * + */ +typedef enum { CRC_REFLECTED, CRC_NOT_REFLECTED } mxc_crc_reflected_t; + +/** + * @brief CRC request state DONE or NOT + * + */ +typedef enum { CRC_NOT_DONE, CRC_DONE } mxc_crc_req_state_t; + +/** + * @brief Structure used to set up Full CRC request + * + */ +typedef struct _mxc_crc_full_req_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t dataLen; ///< Length of the data + + volatile mxc_crc_reflected_t manual_reflected_input_required; + volatile uint8_t dmaChannel; + volatile uint32_t nextPosDMA; + volatile mxc_crc_req_state_t req_state; + + volatile uint32_t resultCRC; ///< Calculated CRC value + volatile int error; +} mxc_crc_full_req_t; + /***** Function Prototypes *****/ /* ************************************************************************* */ @@ -85,6 +125,14 @@ int MXC_CRC_Shutdown(void); */ void MXC_CRC_Handler(int ch, int error); +/** + * @brief This function should be called from the CRC ISR Handler + * when using Async functions for full request + * @param ch DMA channel + * @param error error + */ +void MXC_CRC_Full_Req_Handler(int ch, int error); + /** * @brief Set the bit-order of CRC calculation * @@ -161,6 +209,28 @@ int MXC_CRC_Compute(mxc_crc_req_t *req); */ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req); +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_Calculate(mxc_crc_full_req_t *req); + +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req); + #ifdef __cplusplus } #endif diff --git a/Libraries/PeriphDrivers/Include/MAX78000/crc.h b/Libraries/PeriphDrivers/Include/MAX78000/crc.h index fb9a86d55ef..b4428655aad 100644 --- a/Libraries/PeriphDrivers/Include/MAX78000/crc.h +++ b/Libraries/PeriphDrivers/Include/MAX78000/crc.h @@ -7,7 +7,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,46 @@ typedef struct _mxc_crc_req_t { */ typedef enum { CRC_LSB_FIRST, CRC_MSB_FIRST } mxc_crc_bitorder_t; +/** + * @brief CRC data byte order + * + */ +typedef enum { CRC_LSBYTE_FIRST, CRC_MSBYTE_FIRST } mxc_crc_byteorder_t; + +/** + * @brief CRC reflected + * + */ +typedef enum { CRC_REFLECTED, CRC_NOT_REFLECTED } mxc_crc_reflected_t; + +/** + * @brief CRC request state DONE or NOT + * + */ +typedef enum { CRC_NOT_DONE, CRC_DONE } mxc_crc_req_state_t; + +/** + * @brief Structure used to set up Full CRC request + * + */ +typedef struct _mxc_crc_full_req_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t dataLen; ///< Length of the data + + volatile mxc_crc_reflected_t manual_reflected_input_required; + volatile uint8_t dmaChannel; + volatile uint32_t nextPosDMA; + volatile mxc_crc_req_state_t req_state; + + volatile uint32_t resultCRC; ///< Calculated CRC value + volatile int error; +} mxc_crc_full_req_t; + /***** Function Prototypes *****/ /* ************************************************************************* */ @@ -85,6 +125,14 @@ int MXC_CRC_Shutdown(void); */ void MXC_CRC_Handler(int ch, int error); +/** + * @brief This function should be called from the CRC ISR Handler + * when using Async functions for full request + * @param ch DMA channel + * @param error error + */ +void MXC_CRC_Full_Req_Handler(int ch, int error); + /** * @brief Set the bit-order of CRC calculation * @@ -161,6 +209,28 @@ int MXC_CRC_Compute(mxc_crc_req_t *req); */ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req); +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_Calculate(mxc_crc_full_req_t *req); + +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req); + #ifdef __cplusplus } #endif diff --git a/Libraries/PeriphDrivers/Include/MAX78002/crc.h b/Libraries/PeriphDrivers/Include/MAX78002/crc.h index b795417e64a..20baca1d605 100644 --- a/Libraries/PeriphDrivers/Include/MAX78002/crc.h +++ b/Libraries/PeriphDrivers/Include/MAX78002/crc.h @@ -7,7 +7,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,6 +56,46 @@ typedef struct _mxc_crc_req_t { */ typedef enum { CRC_LSB_FIRST, CRC_MSB_FIRST } mxc_crc_bitorder_t; +/** + * @brief CRC data byte order + * + */ +typedef enum { CRC_LSBYTE_FIRST, CRC_MSBYTE_FIRST } mxc_crc_byteorder_t; + +/** + * @brief CRC reflected + * + */ +typedef enum { CRC_REFLECTED, CRC_NOT_REFLECTED } mxc_crc_reflected_t; + +/** + * @brief CRC request state DONE or NOT + * + */ +typedef enum { CRC_NOT_DONE, CRC_DONE } mxc_crc_req_state_t; + +/** + * @brief Structure used to set up Full CRC request + * + */ +typedef struct _mxc_crc_full_req_t { + mxc_crc_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t dataLen; ///< Length of the data + + volatile mxc_crc_reflected_t manual_reflected_input_required; + volatile uint8_t dmaChannel; + volatile uint32_t nextPosDMA; + volatile mxc_crc_req_state_t req_state; + + volatile uint32_t resultCRC; ///< Calculated CRC value + volatile int error; +} mxc_crc_full_req_t; + /***** Function Prototypes *****/ /* ************************************************************************* */ @@ -82,12 +122,17 @@ int MXC_CRC_Shutdown(void); * when using Async functions * @param ch DMA channel * @param error error - * - * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. */ -// AI87-TODO: Changed because of redundancy in MXC_CRC_RevA_Handler? void MXC_CRC_Handler(int ch, int error); +/** + * @brief This function should be called from the CRC ISR Handler + * when using Async functions for full request + * @param ch DMA channel + * @param error error + */ +void MXC_CRC_Full_Req_Handler(int ch, int error); + /** * @brief Set the bit-order of CRC calculation * @@ -164,6 +209,28 @@ int MXC_CRC_Compute(mxc_crc_req_t *req); */ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req); +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_Calculate(mxc_crc_full_req_t *req); + +/** + * @brief Perform a CRC calculation + * @note The result of the CRC calculation will be placed in the + * mxc_crc_full_req_t structure + * + * @param req Structure containing the CRC detailed parameters and data for calculation + * + * @return see \ref MXC_Error_Codes for a list of return codes. + */ +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req); + #ifdef __cplusplus } #endif diff --git a/Libraries/PeriphDrivers/Source/CRC/crc_ai87.c b/Libraries/PeriphDrivers/Source/CRC/crc_ai87.c index e75000fe5fc..57d2a92746e 100644 --- a/Libraries/PeriphDrivers/Source/CRC/crc_ai87.c +++ b/Libraries/PeriphDrivers/Source/CRC/crc_ai87.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,11 @@ void MXC_CRC_Handler(int ch, int error) MXC_CRC_RevA_Handler(ch, error); } +void MXC_CRC_Full_Req_Handler(int ch, int error) +{ + MXC_CRC_RevA_Full_Req_Handler(ch, error); +} + void MXC_CRC_SetDirection(mxc_crc_bitorder_t bitOrder) { MXC_CRC_RevA_SetDirection((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_bitorder_t)bitOrder); @@ -99,3 +104,14 @@ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req) { return MXC_CRC_RevA_ComputeAsync((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_req_t *)req); } + +int MXC_CRC_Calculate(mxc_crc_full_req_t *req) +{ + return MXC_CRC_RevA_Calculate((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_full_req_t *)req); +} + +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req) +{ + return MXC_CRC_RevA_CalculateAsync((mxc_crc_reva_regs_t *)MXC_CRC, + (mxc_crc_reva_full_req_t *)req); +} diff --git a/Libraries/PeriphDrivers/Source/CRC/crc_me15.c b/Libraries/PeriphDrivers/Source/CRC/crc_me15.c index e75000fe5fc..57d2a92746e 100644 --- a/Libraries/PeriphDrivers/Source/CRC/crc_me15.c +++ b/Libraries/PeriphDrivers/Source/CRC/crc_me15.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,11 @@ void MXC_CRC_Handler(int ch, int error) MXC_CRC_RevA_Handler(ch, error); } +void MXC_CRC_Full_Req_Handler(int ch, int error) +{ + MXC_CRC_RevA_Full_Req_Handler(ch, error); +} + void MXC_CRC_SetDirection(mxc_crc_bitorder_t bitOrder) { MXC_CRC_RevA_SetDirection((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_bitorder_t)bitOrder); @@ -99,3 +104,14 @@ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req) { return MXC_CRC_RevA_ComputeAsync((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_req_t *)req); } + +int MXC_CRC_Calculate(mxc_crc_full_req_t *req) +{ + return MXC_CRC_RevA_Calculate((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_full_req_t *)req); +} + +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req) +{ + return MXC_CRC_RevA_CalculateAsync((mxc_crc_reva_regs_t *)MXC_CRC, + (mxc_crc_reva_full_req_t *)req); +} diff --git a/Libraries/PeriphDrivers/Source/CRC/crc_me17.c b/Libraries/PeriphDrivers/Source/CRC/crc_me17.c index e75000fe5fc..57d2a92746e 100644 --- a/Libraries/PeriphDrivers/Source/CRC/crc_me17.c +++ b/Libraries/PeriphDrivers/Source/CRC/crc_me17.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,11 @@ void MXC_CRC_Handler(int ch, int error) MXC_CRC_RevA_Handler(ch, error); } +void MXC_CRC_Full_Req_Handler(int ch, int error) +{ + MXC_CRC_RevA_Full_Req_Handler(ch, error); +} + void MXC_CRC_SetDirection(mxc_crc_bitorder_t bitOrder) { MXC_CRC_RevA_SetDirection((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_bitorder_t)bitOrder); @@ -99,3 +104,14 @@ int MXC_CRC_ComputeAsync(mxc_crc_req_t *req) { return MXC_CRC_RevA_ComputeAsync((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_req_t *)req); } + +int MXC_CRC_Calculate(mxc_crc_full_req_t *req) +{ + return MXC_CRC_RevA_Calculate((mxc_crc_reva_regs_t *)MXC_CRC, (mxc_crc_reva_full_req_t *)req); +} + +int MXC_CRC_CalculateAsync(mxc_crc_full_req_t *req) +{ + return MXC_CRC_RevA_CalculateAsync((mxc_crc_reva_regs_t *)MXC_CRC, + (mxc_crc_reva_full_req_t *)req); +} diff --git a/Libraries/PeriphDrivers/Source/CRC/crc_reva.c b/Libraries/PeriphDrivers/Source/CRC/crc_reva.c index a84b553ab89..b67ce969a95 100644 --- a/Libraries/PeriphDrivers/Source/CRC/crc_reva.c +++ b/Libraries/PeriphDrivers/Source/CRC/crc_reva.c @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,36 @@ #include "crc_reva.h" /***** Global Variables *****/ -static mxc_crc_reva_req_t *CRCreq; +static mxc_crc_reva_regs_t *CRCregs; static mxc_dma_regs_t *CRCdma; +static mxc_crc_reva_req_t *CRCreq; +static mxc_crc_reva_full_req_t *CRCfullreq; + +static uint8_t reflect_8bit[256] = { + 0x00,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 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, + 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, + 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, + 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, + 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF +}; + +#define MIN_DMA_LENGTH 16 + +#define MAX_SIZE_REFLECTED_INPUT_BUFFER 256 +static uint8_t reflected_input_buffer[MAX_SIZE_REFLECTED_INPUT_BUFFER]; + /* ************************************************************************* */ /* Global Control/Configuration functions */ /* ************************************************************************* */ @@ -42,9 +69,11 @@ static mxc_dma_regs_t *CRCdma; int MXC_CRC_RevA_Init(mxc_crc_reva_regs_t *crc, mxc_dma_regs_t *dma) { CRCdma = dma; + CRCregs = crc; crc->ctrl = 0x00; crc->val = 0xFFFFFFFF; + return E_NO_ERROR; } @@ -62,6 +91,234 @@ int MXC_CRC_RevA_Handler(int ch, int error) return error; } +static uint32_t reflect_32bit(uint32_t value) +{ + uint32_t result = 0; + + for (int i = 0; i < 32; i++) { + uint32_t bit = (value >> i) & 1; + + result |= bit << (31 - i); + } + + return result; +} + +static void prepare_temp_reflected_8bit_buffer(uint8_t *dst, uint8_t *src, uint32_t len) +{ + for (int i = 0; i < len; i++) { + dst[i] = reflect_8bit[src[i]]; + } +} + +static uint32_t reflect_8bit_4bytes(uint32_t value) +{ + uint32_t result = 0; + uint8_t *in_ptr = (uint8_t *)&value; + uint8_t *out_ptr = (uint8_t *)&result; + + out_ptr[0] = reflect_8bit[in_ptr[0]]; + out_ptr[1] = reflect_8bit[in_ptr[1]]; + out_ptr[2] = reflect_8bit[in_ptr[2]]; + out_ptr[3] = reflect_8bit[in_ptr[3]]; + + return result; +} + +static int setup_crc_hardware(mxc_crc_reva_regs_t *crc, mxc_crc_reva_full_req_t *req) +{ + uint32_t tmp_value = 0; + + // Setup the CRC detailed parameters: + if ((req->polynominal & 0xFFFF0000) == 0) { + MXC_SETFIELD(crc->ctrl, MXC_F_CRC_REVA_CTRL_MSB, 0 << MXC_F_CRC_REVA_CTRL_MSB_POS); + } else { + MXC_SETFIELD(crc->ctrl, MXC_F_CRC_REVA_CTRL_MSB, + req->inputReflected << MXC_F_CRC_REVA_CTRL_MSB_POS); + } + + // Note: + // Not found any protocol which requires calculating CRC + // from the end of the byte sequence to the beginning + // Setup Input byte order (By Hardware) + MXC_SETFIELD(crc->ctrl, MXC_F_CRC_REVA_CTRL_BYTE_SWAP_IN, + CRC_REVA_LSBYTE_FIRST << MXC_F_CRC_REVA_CTRL_BYTE_SWAP_IN_POS); + + // Setup Result byte order (By Hardware) + MXC_SETFIELD(crc->ctrl, MXC_F_CRC_REVA_CTRL_BYTE_SWAP_OUT, + CRC_REVA_LSBYTE_FIRST << MXC_F_CRC_REVA_CTRL_BYTE_SWAP_OUT_POS); + + // Setup polynominal (Convert to MAXIM IP format) + tmp_value = req->polynominal; + if (((req->polynominal & 0xFFFF0000) == 0) || (req->inputReflected == CRC_REVA_REFLECTED)) { + tmp_value = reflect_32bit(tmp_value); + + if ((req->polynominal & 0xFFFFFF00) == 0) { + tmp_value = tmp_value >> 24; // CRC8 request + } else if ((req->polynominal & 0xFFFF0000) == 0) { + tmp_value = tmp_value >> 16; // CRC16 request + } else { + // CRC32 ==> Do nothing + } + } + crc->poly = tmp_value; + + // Setup initial value (Convert to MAXIM IP format) + tmp_value = req->initialValue; + if (((req->polynominal & 0xFFFF0000) == 0) || (req->inputReflected == CRC_REVA_REFLECTED)) { + tmp_value = reflect_32bit(tmp_value); + + if ((req->polynominal & 0xFFFFFF00) == 0) { + tmp_value = tmp_value >> 24; // CRC8 request + } else if ((req->polynominal & 0xFFFF0000) == 0) { + tmp_value = tmp_value >> 16; // CRC16 request + } else { + // CRC32 ==> Do nothing + } + } + crc->val = tmp_value; + + // For the case CRC_REVA_NOT_REFLECTED, + // For CRC8 and CRC16 only (CRC32 hardware supported) + // ==> Manual input reflected + if ((req->inputReflected != CRC_REVA_REFLECTED) && ((req->polynominal & 0xFFFF0000) == 0)) { + req->manual_reflected_input_required = CRC_REVA_REFLECTED; + } else { + req->manual_reflected_input_required = CRC_REVA_NOT_REFLECTED; + } + + return E_NO_ERROR; +} + +static int post_process_crc_result(mxc_crc_reva_regs_t *crc, mxc_crc_reva_full_req_t *req) +{ + uint32_t tmp_crc_result = 0; + + // Calculate CRC result reflected if needed + tmp_crc_result = crc->val; + if (((req->inputReflected == CRC_REVA_REFLECTED) && + (req->resultReflected != CRC_REVA_REFLECTED)) || + ((req->inputReflected != CRC_REVA_REFLECTED) && + (((req->resultReflected == CRC_REVA_REFLECTED) && (req->polynominal & 0xFFFF0000) != 0) || + ((req->resultReflected != CRC_REVA_REFLECTED) && (req->polynominal & 0xFFFF0000) == 0)))) { + tmp_crc_result = reflect_32bit(tmp_crc_result); + + if ((req->polynominal & 0xFFFFFF00) == 0) { + tmp_crc_result = tmp_crc_result >> 24; // CRC8 request + } else if ((req->polynominal & 0xFFFF0000) == 0) { + tmp_crc_result = tmp_crc_result >> 16; // CRC16 request + } else { + // CRC32 ==> Do nothing + } + } + + // Calculate Final Xor Value + tmp_crc_result = tmp_crc_result ^ req->finalXorValue; + if ((req->polynominal & 0xFFFFFF00) == 0) { + tmp_crc_result = tmp_crc_result & 0x000000FF; // CRC8 request + } else if ((req->polynominal & 0xFFFF0000) == 0) { + tmp_crc_result = tmp_crc_result & 0x0000FFFF; // CRC16 request + } else { + // CRC32 ==> Do nothing + } + req->resultCRC = tmp_crc_result; + + // Shutdown the CRC module to save power + CRCregs->ctrl &= ~MXC_F_CRC_REVA_CTRL_EN; + + return E_NO_ERROR; +} + +int MXC_CRC_RevA_Full_Req_Handler(int ch, int error) +{ + mxc_dma_config_t config; + mxc_dma_srcdst_t srcdst; + + MXC_DMA_ReleaseChannel(ch); + + if (error == E_NO_ERROR) { + if (CRCfullreq->nextPosDMA >= CRCfullreq->dataLen) { + post_process_crc_result(CRCregs, CRCfullreq); + + CRCregs->ctrl &= ~MXC_F_CRC_CTRL_DMA_EN; + + CRCfullreq->req_state = CRC_REV_DONE; + } else { + // In this case Manual Reflect Input is required + if ((CRCfullreq->dataLen - CRCfullreq->nextPosDMA) > MAX_SIZE_REFLECTED_INPUT_BUFFER) { + prepare_temp_reflected_8bit_buffer( + reflected_input_buffer, &(CRCfullreq->dataBuffer[CRCfullreq->nextPosDMA]), + MAX_SIZE_REFLECTED_INPUT_BUFFER); + + srcdst.len = MAX_SIZE_REFLECTED_INPUT_BUFFER; + } else { + prepare_temp_reflected_8bit_buffer( + reflected_input_buffer, &(CRCfullreq->dataBuffer[CRCfullreq->nextPosDMA]), + CRCfullreq->dataLen - CRCfullreq->nextPosDMA); + + srcdst.len = CRCfullreq->dataLen - CRCfullreq->nextPosDMA; + } + CRCfullreq->nextPosDMA += srcdst.len; + + // For too short request, do it manually instead of DMA + if (srcdst.len < MIN_DMA_LENGTH) { + for (int i = 0; i < srcdst.len; i++) { + CRCregs->datain8[0] = reflected_input_buffer[i]; + while (CRCregs->ctrl & MXC_F_CRC_CTRL_BUSY) {} + } + + post_process_crc_result(CRCregs, CRCfullreq); + + CRCregs->ctrl &= ~MXC_F_CRC_CTRL_DMA_EN; + + CRCfullreq->req_state = CRC_REV_DONE; + } else { + // Continue to trigger another DMA transfer +#if (TARGET_NUM == 32657) + MXC_DMA_Init(CRCdma); + CRCfullreq->channel = MXC_DMA_AcquireChannel(CRCdma); +#else + MXC_DMA_Init(); + CRCfullreq->dmaChannel = MXC_DMA_AcquireChannel(); +#endif + config.reqsel = MXC_DMA_REQUEST_CRCTX; + config.ch = CRCfullreq->dmaChannel; + config.srcwd = MXC_DMA_WIDTH_BYTE; + config.dstwd = MXC_DMA_WIDTH_BYTE; + config.srcinc_en = 1; + config.dstinc_en = 0; + + srcdst.ch = CRCfullreq->dmaChannel; + + srcdst.source = reflected_input_buffer; + + MXC_DMA_ConfigChannel(config, srcdst); + MXC_DMA_SetCallback(CRCfullreq->dmaChannel, MXC_CRC_Full_Req_Handler); + +#if (TARGET_NUM == 32657) + MXC_DMA_EnableInt(CRCdma, CRCfullreq->dmaChannel); +#else + MXC_DMA_EnableInt(CRCfullreq->dmaChannel); +#endif + + MXC_DMA_SetChannelInterruptEn(CRCfullreq->dmaChannel, 0, 1); + MXC_DMA_Start(CRCfullreq->dmaChannel); + } + } + } else { + // Shutdown the CRC module to save power + CRCregs->ctrl &= ~MXC_F_CRC_REVA_CTRL_EN; + CRCregs->ctrl &= ~MXC_F_CRC_CTRL_DMA_EN; + + CRCfullreq->resultCRC = 0; + CRCfullreq->req_state = CRC_REV_DONE; + } + + CRCfullreq->error = error; + + return error; +} + /* ************************************************************************* */ /* Cyclic Redundancy Check(CRC) functions */ /* ************************************************************************* */ @@ -205,3 +462,172 @@ int MXC_CRC_RevA_ComputeAsync(mxc_crc_reva_regs_t *crc, mxc_crc_reva_req_t *req) return E_NO_ERROR; } + +int MXC_CRC_RevA_Calculate(mxc_crc_reva_regs_t *crc, mxc_crc_reva_full_req_t *req) +{ + int i = 0; + uint8_t *ptr8_tail = 0; + uint32_t *ptr32 = 0; + volatile int head_bytes_counter = 0; + volatile int tail_bytes_counter = 0; + volatile int uint32_counter = 0; + + if (req == NULL) { + return E_NULL_PTR; + } + + if (req->dataBuffer == NULL) { + return E_NULL_PTR; + } + + if (req->dataLen == 0) { + return E_INVALID; + } + + setup_crc_hardware(crc, req); + + crc->ctrl |= MXC_F_CRC_CTRL_EN; + + head_bytes_counter = (4 - (((uintptr_t)req->dataBuffer) % 4)) % 4; + + if (req->dataLen > head_bytes_counter) { + tail_bytes_counter = (((uintptr_t)req->dataBuffer) + req->dataLen) % 4; + ptr8_tail = &(req->dataBuffer[req->dataLen - tail_bytes_counter]); + } else { + head_bytes_counter = req->dataLen; + tail_bytes_counter = 0; + } + + if (req->dataLen > (head_bytes_counter + tail_bytes_counter)) { + uint32_counter = (req->dataLen - (head_bytes_counter + tail_bytes_counter)) / 4; + ptr32 = (uint32_t *)(&(req->dataBuffer[head_bytes_counter])); + } else { + uint32_counter = 0; + } + + i = 0; + while (head_bytes_counter--) { + crc->datain8[0] = (req->manual_reflected_input_required == CRC_REVA_REFLECTED) ? + reflect_8bit[req->dataBuffer[i++]] : + req->dataBuffer[i++]; + while (crc->ctrl & MXC_F_CRC_CTRL_BUSY) {} + } + + i = 0; + while (uint32_counter--) { + crc->datain32 = (req->manual_reflected_input_required == CRC_REVA_REFLECTED) ? + reflect_8bit_4bytes(ptr32[i++]) : + ptr32[i++]; + while (crc->ctrl & MXC_F_CRC_CTRL_BUSY) {} + } + + i = 0; + while (tail_bytes_counter--) { + crc->datain8[0] = (req->manual_reflected_input_required == CRC_REVA_REFLECTED) ? + reflect_8bit[ptr8_tail[i++]] : + ptr8_tail[i++]; + while (crc->ctrl & MXC_F_CRC_CTRL_BUSY) {} + } + + post_process_crc_result(crc, req); + + return E_NO_ERROR; +} + +int MXC_CRC_RevA_CalculateAsync(mxc_crc_reva_regs_t *crc, mxc_crc_reva_full_req_t *req) +{ + mxc_dma_config_t config; + mxc_dma_srcdst_t srcdst; + uint8_t *ptr_input_source = 0; + + if (req == NULL) { + return E_NULL_PTR; + } + + if (req->dataBuffer == NULL) { + return E_NULL_PTR; + } + + if (req->dataLen == 0) { + return E_INVALID; + } + + CRCregs = crc; + CRCfullreq = req; + + CRCfullreq->req_state = CRC_NOT_DONE; + CRCfullreq->nextPosDMA = 0; + + setup_crc_hardware(CRCregs, CRCfullreq); + + if (req->manual_reflected_input_required == CRC_REVA_REFLECTED) { + ptr_input_source = reflected_input_buffer; + + if (CRCfullreq->dataLen < MAX_SIZE_REFLECTED_INPUT_BUFFER) { + prepare_temp_reflected_8bit_buffer(reflected_input_buffer, CRCfullreq->dataBuffer, + CRCfullreq->dataLen); + + srcdst.len = CRCfullreq->dataLen; + } else { + prepare_temp_reflected_8bit_buffer(reflected_input_buffer, CRCfullreq->dataBuffer, + MAX_SIZE_REFLECTED_INPUT_BUFFER); + + srcdst.len = MAX_SIZE_REFLECTED_INPUT_BUFFER; + } + } else { + ptr_input_source = CRCfullreq->dataBuffer; + srcdst.len = CRCfullreq->dataLen; + } + CRCfullreq->nextPosDMA += srcdst.len; + + // For too short request, do it manually instead of DMA + if (srcdst.len < MIN_DMA_LENGTH) { + CRCregs->ctrl |= MXC_F_CRC_CTRL_EN; + + for (int i = 0; i < srcdst.len; i++) { + CRCregs->datain8[0] = ptr_input_source[i]; + while (CRCregs->ctrl & MXC_F_CRC_CTRL_BUSY) {} + } + + post_process_crc_result(CRCregs, CRCfullreq); + + CRCfullreq->req_state = CRC_REV_DONE; + } else { +#if (TARGET_NUM == 32657) + MXC_DMA_Init(CRCdma); + CRCfullreq->channel = MXC_DMA_AcquireChannel(CRCdma); +#else + MXC_DMA_Init(); + CRCfullreq->dmaChannel = MXC_DMA_AcquireChannel(); +#endif + + config.reqsel = MXC_DMA_REQUEST_CRCTX; + config.ch = CRCfullreq->dmaChannel; + config.srcwd = MXC_DMA_WIDTH_BYTE; + config.dstwd = MXC_DMA_WIDTH_BYTE; + config.srcinc_en = 1; + config.dstinc_en = 0; + + srcdst.ch = CRCfullreq->dmaChannel; + + srcdst.source = ptr_input_source; + + MXC_DMA_ConfigChannel(config, srcdst); + MXC_DMA_SetCallback(CRCfullreq->dmaChannel, MXC_CRC_Full_Req_Handler); + +#if (TARGET_NUM == 32657) + MXC_DMA_EnableInt(CRCdma, CRCfullreq->dmaChannel); +#else + MXC_DMA_EnableInt(CRCfullreq->dmaChannel); +#endif + + MXC_DMA_SetChannelInterruptEn(CRCfullreq->dmaChannel, 0, 1); + + CRCregs->ctrl |= MXC_F_CRC_CTRL_DMA_EN; + CRCregs->ctrl |= MXC_F_CRC_CTRL_EN; + + MXC_DMA_Start(CRCfullreq->dmaChannel); + } + + return E_NO_ERROR; +} diff --git a/Libraries/PeriphDrivers/Source/CRC/crc_reva.h b/Libraries/PeriphDrivers/Source/CRC/crc_reva.h index 8e2c46f9b34..aa39a5c9706 100644 --- a/Libraries/PeriphDrivers/Source/CRC/crc_reva.h +++ b/Libraries/PeriphDrivers/Source/CRC/crc_reva.h @@ -2,7 +2,7 @@ * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), - * Copyright (C) 2023-2024 Analog Devices, Inc. + * Copyright (C) 2023-2025 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,9 +42,50 @@ typedef struct _mxc_crc_reva_req_t { */ typedef enum { CRC_REVA_LSB_FIRST, CRC_REVA_MSB_FIRST } mxc_crc_reva_bitorder_t; +/** + * @brief CRC data byte order + * + */ +typedef enum { CRC_REVA_LSBYTE_FIRST, CRC_REVA_MSBYTE_FIRST } mxc_crc_reva_byteorder_t; + +/** + * @brief CRC reflected + * + */ +typedef enum { CRC_REVA_REFLECTED, CRC_REVA_NOT_REFLECTED } mxc_crc_reva_reflected_t; + +/** + * @brief CRC request state DONE or NOT + * + */ +typedef enum { CRC_REV_NOT_DONE, CRC_REV_DONE } mxc_crc_rev_req_state_t; + +/** + * @brief Structure used to set up Full CRC request + * + */ +typedef struct _mxc_crc_reva_full_req_t { + mxc_crc_reva_reflected_t inputReflected; ///< Input reflected or not + mxc_crc_reva_reflected_t resultReflected; ///< Result reflected or not + uint32_t polynominal; ///< The polynominal to calculate CRC + uint32_t initialValue; ///< The initial value to calculate CRC + uint32_t finalXorValue; ///< The final xor value to calculate CRC + uint8_t *dataBuffer; ///< Pointer to the data + uint32_t dataLen; ///< Length of the data + + volatile mxc_crc_reva_reflected_t manual_reflected_input_required; + volatile uint8_t dmaChannel; + volatile uint32_t nextPosDMA; + volatile mxc_crc_rev_req_state_t req_state; + + volatile uint32_t resultCRC; ///< Calculated CRC value + volatile int error; +} mxc_crc_reva_full_req_t; + int MXC_CRC_RevA_Init(mxc_crc_reva_regs_t *crc, mxc_dma_regs_t *dma); int MXC_CRC_RevA_Shutdown(mxc_crc_reva_regs_t *crc); int MXC_CRC_RevA_Handler(int ch, int error); +int MXC_CRC_RevA_Full_Req_Handler(int ch, int error); void MXC_CRC_RevA_SetDirection(mxc_crc_reva_regs_t *crc, mxc_crc_reva_bitorder_t bitOrder); mxc_crc_bitorder_t MXC_CRC_RevA_GetDirection(mxc_crc_reva_regs_t *crc); void MXC_CRC_RevA_SwapDataIn(mxc_crc_reva_regs_t *crc, mxc_crc_reva_bitorder_t bitOrder); @@ -55,4 +96,7 @@ uint32_t MXC_CRC_RevA_GetResult(mxc_crc_reva_regs_t *crc); int MXC_CRC_RevA_Compute(mxc_crc_reva_regs_t *crc, mxc_crc_reva_req_t *req); int MXC_CRC_RevA_ComputeAsync(mxc_crc_reva_regs_t *crc, mxc_crc_reva_req_t *req); +int MXC_CRC_RevA_Calculate(mxc_crc_reva_regs_t *crc, mxc_crc_reva_full_req_t *req); +int MXC_CRC_RevA_CalculateAsync(mxc_crc_reva_regs_t *crc, mxc_crc_reva_full_req_t *req); + #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_CRC_CRC_REVA_H_