/**
*   @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_timer.h
 *  @version       	1.0
 *  @brief     		This file has the declarations for the TIMER diagnostic 
 *					functions.
 *************************************************************************/

/**
 * @defgroup functions Functions
 * @defgroup macros Macros
 * @defgroup errorcodes ErrorCodes
 * @defgroup enums Enums
*/
 
#ifndef DIAG_TIMER_H
#define DIAG_TIMER_H

/*Section: Included Files*/
#include <xc.h>
#include "diag.h"
#include "diag_utility_timer.h"

/* Enumerations */
/**
 @ingroup enums
 @enum DIAG_TIMER_FUNCTIONAL_RESULTS
 Defines the functional diagnostic results.
 @var  DIAG_TIMER_FUNCTIONAL_RESULTS::DIAG_TIMER_RESULT_NONE
 @var  DIAG_TIMER_FUNCTIONAL_RESULTS::DIAG_TIMER_RESULT_NORMAL
 @var  DIAG_TIMER_FUNCTIONAL_RESULTS::DIAG_TIMER_RESULT_FAST
 @var  DIAG_TIMER_FUNCTIONAL_RESULTS::DIAG_TIMER_RESULT_SLOW
*/
typedef enum
{
    DIAG_TIMER_RESULT_NONE,
    DIAG_TIMER_RESULT_NORMAL,
    DIAG_TIMER_RESULT_FAST,
    DIAG_TIMER_RESULT_SLOW
}DIAG_TIMER_FUNCTIONAL_RESULTS;

/* Function Declarations */
/**
 @ingroup functions
 @brief **Software Requirement Reference ID : SW_TIMER_FUNCTIONAL_TEST_02**\n
 Implements the Timer functional diagnostic to check the operation of a given
 timer instance.  The diagnostic indicates when the Timer runs at a frequency
 different from the one intended and when timer interrupts are not received
 @param tmrId - Timer instance used by the timer diagnostic
 @param tolerance - tolerance value to determine the band within which the timer
 interrupt count must fall for the test to pass. The value represents by how 
 many counts, the timer is allowed to deviate.
 @return @ref DIAG_PASS \n
 @return @ref DIAG_FAIL \n
 @return @ref DIAG_INVALID_PARAM \n


 @par
Imageref DIAG_TIMER_FunctionalTest_UML.svg "TIMER Functional Test"
Imageref DIAG_TIMER_FunctionalTest_ClassDiagram.svg "TIMER Functional Test Class Diagram"
*/
uint32_t DIAG_TIMER_FunctionalTest(DIAG_UTILITY_TIMER_INSTANCE tmrId,
									uint32_t tolerance);

/**
 @ingroup functions
 @brief **Software Requirement Reference ID : SW_TIMER_LINEARITY_TEST_01**\n
 Inaccuracies, if any, in the TMRx count register are diagnosed by this 
 function.  The previously recorded TMRx difference value is used as a 
 reference to check if any errors have crept into the Timer period base.
 @param tmrId - Timer instance used by the timer diagnostic
 @param tolerance - Tolerance is in counts which specifies, maximum allowable 
 deviation between two measured timer counts during a diagnostic test.
 @return @ref DIAG_PASS \n
 @return @ref DIAG_FAIL \n
 @return @ref DIAG_INVALID_PARAM \n

 @par
Imageref DIAG_TIMER_LinearityTest_UML.svg "TIMER Linearity Test"
Imageref DIAG_TIMER_LinearityTest_ClassDiagram.svg "TIMER Linearity Test Class Diagram"
 */
uint32_t DIAG_TIMER_LinearityTest(DIAG_UTILITY_TIMER_INSTANCE tmrId,
                                    uint32_t tolerance);

/**
 @ingroup functions
 @brief **Software Requirement Reference ID : SW_TIMER_FUNCTIONAL_TEST_02**\n
 The function returns the result of the timer functional diagnostics.
 @param Nil
 @return @ref DIAG_TIMER_FUNCTIONAL_RESULTS
 */
DIAG_TIMER_FUNCTIONAL_RESULTS DIAG_TIMER_GetResults(void);

#endif /* DIAG_TIMER_H */
