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

#ifndef DIAG_GPIO_SHARED_H
#define	DIAG_GPIO_SHARED_H

#ifdef	__cplusplus
extern "C" {
#endif

/*Function headers*/
#include "xc.h"
#include "diag.h"
/* Macros and definitions to be used by all GPIO Diagnostic functions */

#define DIAG_GPIO_LAT_OFFSET    1U
#define DIAG_GPIO_PORT_OFFSET 0U

/* Each register corresponding to a port can hold upto 16 pins 
 * (0 to 15).  So, the Maximum pin number should not exceed 15 */
#define     DIAG_GPIO_MAX_PIN_NUMBER  15U
    
#define DIAG_GPIO_CNREG_OFFSET 4U
#define IOIM_SFR_ADDRESS_SPACE 3U
#define NUM_IOIM_INSTANCES 4U
#define DIAG_GPIO_IOIMCON_REG 0U
#define DIAG_GPIO_IOIMBLK_REG 1U
#define DIAG_GPIO_IOIMSTAT_REG 2U
#define DIAG_GPIO_IOIM_ENABLE 0x00008000UL
#define DIAG_GPIO_IOIM_DISABLE 0xFFFF7FFFUL
#define DIAG_GPIO_IOIM_BLKTIME 100U
#define DIAG_GPIO_ATEST_FLT 0x02000000UL
#define DIAG_GPIO_IOIMCON_FLAG_CLR 0xF3FFFFFFUL
#define DIAG_GPIO_IOIM_FLTINJ 0x08000000UL
#define DIAG_GPIO_ATEST_OK 0x03000000UL
#define DIAG_GPIO_IOIM_OKINJ 0x04000000UL
#define DIAG_GPIO_IOIM_TIMEOUT 200U 
#define DIAG_GPIO_IOIM_INTR_FLAG &IFS8
#define DIAG_GPIO_IOIM_INTR_ENB &IEC8
#define DIAG_GPIO_IOIM_INTR_OFFSET 12U
#define DIAG_GPIO_IOIMCON_CLR 0xF0FF7FFFUL
#define DIAG_GPIO_IOIM_FLTINJ_FLAG 0x00000002UL
#define DIAG_GPIO_IOIM_OKINJ_FLAG 0x00000001UL
#define DIAG_GPIO_PORTS_REG 4U
#define DIAG_GPIO_INTR_REG 1U
    
typedef volatile uint32_t (*ioimRegAddr_t)[IOIM_SFR_ADDRESS_SPACE];
typedef volatile uint32_t (*gpioPortRegAddr_t)[DIAG_GPIO_PORTS_REG];
typedef volatile uint32_t (*intrFlagRegAddr_t)[DIAG_GPIO_INTR_REG];
typedef volatile uint32_t (*intrEnbRegAddr_t)[DIAG_GPIO_INTR_REG];


void DIAG_GPIO_SetRetValue(uint32_t returnValue);
uint32_t DIAG_GPIO_GetRetValue(void);

void DIAG_GPIO_CompareOutputInputPorts(uint32_t* outputPort, uint16_t outputPinNum,
                                uint32_t* inputPort, uint16_t inputPinNum);
    
#ifdef	__cplusplus
}
#endif

#endif	/* DIAG_GPIO_SHARED_H */

