/**
*   @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_interrupt_shared.h
 *  @version       	1.0
 *  @brief     		This file has the declarations for the common macros and functions
 *                  that are shared by all the interrupt module diagnostics 
 *************************************************************************/

/**
 * @defgroup functions Functions
 * @defgroup macros Macros
 * @defgroup errorcodes ErrorCodes
 * @defgroup enums Enums
 * @defgroup struct Struct
*/
 
#ifndef DIAG_INTERRUPT_SHARED_H
#define DIAG_INTERRUPT_SHARED_H

#include <stdint.h>
#include <stddef.h>
#include "diag_interrupt.h"

#define NUM_INTR_REQ_FLAG_REGS 12U

#define INTERRUPT_SFR_ADDRESS_SPACE 12U

#define IFS_REG_FLAG_RESET_TIMEOUT 50U

#define INTCON5_SOFT_FLAG_RESET_TIMEOUT 100U

#define ISR_CLEARED_CHECK_TIMEOUT 65535U

#define INTERRUPT_IFS0_REG_INDEX &IFS0

#define INTERRUPT_IEC0_REG_INDEX &IEC0 

#define INTERRUPT_CONTROL_REG_ADDR &INTCON5

#define INTERRUPT_CONTROL_STATUS_REGISTER_ADDR &INTTREG

#define INTERRUPT_CTRL_REG2_ADDR &INTCON2

#define INTERRUPT_EN_REG1_ADDR &IEC1

#define INTERRUPT_REQ_FLAGS_REG1_ADDR &IFS1



#define INTERRUPT_VECTOR_NUM_MASK 0x000001FFU

#define INTERRUPT_EXTERNAL_INTR_IFS_IER_BIT_MASK 0x00000002U


#define INTERRUPT_CONTROL_REG_SOFT_MASK 0x80000000U

#define INTR_SERV_TMP_PASS 0x55U

#define INTR_SERV_TMP_FAIL 0xAAU

#define INTERRUPT_SERVICING_TEMP_INVALID_PARAM 0xCCU

#define INTERRUPT_SERVICING_REG_BITS_INVALID 0xCCU

#define INTERRUPT_SERVICING_REG_BITS_VALID 0xAAU

#define IFS_BIT_SET 0xAAU

#define IFS_BIT_CLEAR 0x55U

#define EXTERNAL_INPUT_REG_FLAG_TIMEOUT  100U

typedef volatile uint32_t (*interruptIfsRegAddr_t)[INTERRUPT_SFR_ADDRESS_SPACE]; 
typedef volatile uint32_t (*interruptIecRegAddr_t)[INTERRUPT_SFR_ADDRESS_SPACE];

void DIAG_INTERRUPT_SetRetValue(uint32_t returnValue);

uint32_t DIAG_INTERRUPT_GetRetValue(void);

#endif //DIAG_INTERRUPT_SHARED_H
