/**
*   @copyright       © 2026 Microchip Technology Inc.
    Microchip Technology Inc. and its subsidiaries. You may use this
    software and any derivatives exclusively with Microchip products.

    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
    WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
    PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
    WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
    BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
    FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
    ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
    THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
    TERMS. 
*
*************************************************************************/

/*************************************************************************
 *  @file           diag_crc.h
 *  @version       	1.0
 *  @brief     		This file has the declarations for the CRC diagnostic 
 *					functions.
 *************************************************************************/

/**
 * @defgroup functions Functions
 * @defgroup errorcodes ErrorCodes
 * @defgroup macros Macros
 */
#ifndef DIAG_CRC_H
#define DIAG_CRC_H
    
// ==============================================================================
// File Inclusions
// ==============================================================================
    
#include <xc.h>
#include <stdint.h>
#include <stddef.h>
#include "diag.h"
    
// ==============================================================================
// Error Codes
// ==============================================================================
    
/**
 @ingroup macros
 @def DIAG_CRC_DATAWIDTH
 Specifies the width of data used
 */
    #define DIAG_CRC_DATAWIDTH			8U
    
/**
 @ingroup macros
 @def DIAG_CRC_DATALENGTH
 Specifies the length of data or number of bytes of data used
 */
    #define DIAG_CRC_DATALENGTH			8U
/**
 @ingroup macros
 @def DIAG_CRC_DATA_ARRAY_SIZE
 Specifies the size of data array
 */
    #define DIAG_CRC_DATA_ARRAY_SIZE	8U
    
/**
 @ingroup macros
 @def DIAG_CRC_NUM_OF_POLYNOMIALS
 Specifies the loop count for CRC diagnostics
 */    
    #define DIAG_CRC_NUM_OF_POLYNOMIALS 33U
/**
 @ingroup macros
 @def DIAG_CRC_STRUCT_SIZE
 Specifies the size of structure array for defining polynomials and expected values
 */
    #define DIAG_CRC_STRUCT_SIZE        32U

/**
 @struct DIAG_CRC_POLY_EXPECTED_VALUES
 * This structure defines the polynomials and the corresponding expected values
 * for each polynomial width from 1-32
 * @var DIAG_CRC_POLY_EXPECTED_VALUES::poly
 * Polynomial value
 * @var DIAG_CRC_POLY_EXPECTED_VALUES::expectedVal1
 * Expected CRC value of first polynomial
 * @var DIAG_CRC_POLY_EXPECTED_VALUES::expectedVal2
 * Expected CRC value of second polynomial 
 * (second polynomial obtained by ~polynomial1)
 */
    typedef struct
{
	uint32_t	poly;
	uint64_t	expectedVal1;
	uint64_t	expectedVal2;
} DIAG_CRC_POLY_EXPECTED_VALUES;

/**
 @ingroup functions
 @brief **Software Requirement Reference ID : SW_CRC_FUNCTIONAL_TEST_01**\n
 This diagnostic API performs CRC hardware functional test by checking the CRC results
 for each CRC type starting from polynomial width of 1 till 32 in a loop. For each 
 polynomial width, two polynomials are used one starting from zero and one starting with one.
 For example: for CRC-8 polynomial1 = 0x55 and polynomial2 = 0xAA. For each of the 
 polynomial, CRC is computed and compared against the corresponding expected value.
 The return value is a PASS/FAIL where pass indicates that all the CRC types have 
 passed the test while fail indicates that one or more have failed the test.
 On diagnostic fail, DIAG_CRC_FunctionalTest_GetStatus() API may be used to check which
 CRC test has failed during the most recent execution.
 @param void
 @return @ref DIAG_PASS \n
 @return @ref DIAG_FAIL \n
 @par Code Snippet
 @code
 volatile uint32_t DIAG_CRC_retValue = DIAG_FAIL;

 DIAG_CRC_retValue = DIAG_CRC_FunctionalTest();
 
 @endcode
 @par
Imageref DIAG_CRC_FunctionalTest_UML.svg "CRC Functional Test Sequence Diagram"
Imageref DIAG_CRC_FunctionalTest_ClassDiagram.svg "CRC Functional Test Class Diagram"
*/
uint32_t	DIAG_CRC_FunctionalTest(void);

/**
 @ingroup functions
 @brief **Software Requirement Reference ID : SW_CRC_FUNCTIONAL_TEST_01**\n
 This API function returns a 32-bit unsigned integer which indicates which 
 CRC test has failed during the most recent execution. 
 Refer DIAG_CRC_FunctionalTest().
 @param void
 @return Variable containing individual PASS/FAIL flags for all the CRC tests. \n
 @code
 volatile uint32_t DIAG_CRC_retValue = DIAG_FAIL;
 volatile uint32_t DIAG_CRC_FunctionalTest_StatusFlag = 0x00000000;															   

 DIAG_CRC_retValue = DIAG_CRC_FunctionalTest();
 if (DIAG_CRC_retValue == DIAG_FAIL)
 {
    DIAG_CRC_FunctionalTest_StatusFlag = DIAG_CRC_FunctionalTest_GetStatus();
 }
 @endcode
*/
uint32_t	DIAG_CRC_FunctionalTest_GetStatus(void);

#endif /* DIAG_CRC_H */
