/**
*   @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.h
 *  @version   	1.0
 *  @brief  	This file has the common macros for all modules.
 * 
 *************************************************************************/
#ifndef _DIAG_H_
#define _DIAG_H_

#include <stdint.h>
#include <xc.h>



/**
@defgroup macros Macros
*/

/**
 @ingroup macros
 @def DIAG_PASS
 Indicates diagnostic PASS
 */
 #define 	DIAG_PASS		(uint32_t)(0x50415353) /*ASCII value of PASS*/

/**
 @ingroup macros
 @def DIAG_FAIL
 Indicates diagnostic FAIL
 */ 
#define 	DIAG_FAIL		(uint32_t)(0x4641494C)/*ASCII value of FAIL*/

/**
 @ingroup macros
 @def DIAG_INVALID_PARAM
 Indicates invalid parameters given to diagnostic API
 */
#define 	DIAG_INVALID_PARAM	(uint32_t)(0x4E564C44) /*ASCII value of NVLD*/
/**
 @ingroup macros
 @def DIAG_SET_CPU_IPL
 Macro to set CPU priority level to ipl.
 */
#define DIAG_SET_CPU_IPL(ipl) {       \
  DISIIPLbits.DISIIPL = ipl;              \
  __builtin_nop();               \
} (void) 0
/**
 @ingroup macros
 @def DIAG_SET_AND_SAVE_CPU_IPL
 Macro to set and save CPU priority level.
 */
#define DIAG_SET_AND_SAVE_CPU_IPL(save_to, ipl){ \
  save_to = DISIIPLbits.DISIIPL; \
  DIAG_SET_CPU_IPL(ipl); } (void) 0;
/**
 @ingroup macros
 @def DIAG_RESTORE_CPU_IPL
 Macro to restore CPU priority level.
 */
#define DIAG_RESTORE_CPU_IPL(saved_to) DIAG_SET_CPU_IPL(saved_to)
/**
 @ingroup macros
 @def DIAG_INTERRUPT_PROTECT
 Macro to handle critical section.
 */
#define DIAG_INTERRUPT_PROTECT(x) { \
char saved_ipl; \
\
DIAG_SET_AND_SAVE_CPU_IPL(saved_ipl,7); \
x; \
DIAG_RESTORE_CPU_IPL(saved_ipl); } (void) 0;




#endif /* _DIAG_H_ */
