/*!
* @file     Dio.h
*
* @version  1.0.0
*
* @brief    AUTOSAR Dio Driver header file
*
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_01-Otc-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

#ifndef DIO_H
#define DIO_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Dio_Cfg.h"

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup DIO_Driver
  @{
*/

/** @defgroup DIO_Macros
  @{
*/
/*******************************************************************************
                    VENDOR ID & AUTOSAR VERSION INFO
*******************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define DIO_H_VENDOR_ID                              0x00C1U
/* Module ID of this module, as defined in the BSW Module List. */
#define DIO_H_MODULE_ID                              0x0065U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define DIO_H_AR_RELEASE_MAJOR_VERSION               0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define DIO_H_AR_RELEASE_MINOR_VERSION               0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define DIO_H_AR_RELEASE_REVISION_VERSION            0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */ 
#define DIO_H_SW_MAJOR_VERSION                       0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define DIO_H_SW_MINOR_VERSION                       0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define DIO_H_SW_PATCH_VERSION                       0x00U

/*******************************************************************************
                                ERROR CODES
*******************************************************************************/
/** API service called with Invalid channel ID */
#define DIO_E_PARAM_INVALID_CHANNEL_ID          ((uint8)0x0AU)

/** API service called with Invalid port ID */
#define DIO_E_PARAM_INVALID_PORT_ID             ((uint8)0x14U)

/** API service called with Invalid ChannelGroup ID */
#define DIO_E_PARAM_INVALID_GROUP_ID            ((uint8)0x1FU)

/** API service called with a NULL pointer , the API service shall return immediately without any further action,
   beside reporting this development error.*/
#define DIO_E_PARAM_POINTER                     ((uint8)0x20U)

/** API service called with invalid channel level value,the API service shall return immediately without any further
    action, beside reporting this development error. */
#define DIO_E_PARAM_LEVEL                       ((uint8)0x21U)

/*******************************************************************************
                            API Service ID List
*******************************************************************************/
/** Instance ID for Dio driver */
#define DIO_INSTANCE_ID                         ((uint8)0x00U)

/** Service ID for Dio_ReadChannel */
#define DIO_READCHANNEL_ID                      ((uint8)0x00U)

/** Service ID for Dio_WriteChannel */
#define DIO_WRITECHANNEL_ID                     ((uint8)0x01U)

/** Service ID for Dio_FlipChannel */
#define DIO_FLIPCHANNEL_ID                      ((uint8)0x11U)

/** Service ID for Dio_ReadPort */
#define DIO_READPORT_ID                         ((uint8)0x02U)

/** Service ID for Dio_WritePort */
#define DIO_WRITEPORT_ID                        ((uint8)0x03U)

/** Service ID for Dio_ReadChannelGroup */
#define DIO_READCHANNELGROUP_ID                 ((uint8)0x04U)

/** Service ID for Dio_WriteChannelGroup */
#define DIO_WRITECHANNELGROUP_ID                ((uint8)0x05U)

/** Service ID for Dio_GetVersionInfo */
#define DIO_GETVERSIONINFO_ID                   ((uint8)0x12U)

/**@} end of group DIO_Macros */
/*******************************************************************************
                                OTHER TYPE DEFINITION
*******************************************************************************/
/** @defgroup DIO_Typedef
  @{
*/

/**
 * @brief   The type of the numeric id of a DIO channel
 */
typedef uint16 Dio_ChannelType;

/**
 * @brief   The type of a DIO port level
 */
typedef uint32 Dio_PortLevelType;

/**
 *  @brief  The type of the numeric id of a DIO port
 */
typedef uint8 Dio_PortType;

/**@} end of group DIO_Typedef */


/** @defgroup DIO_Enumerations
  @{
*/

/**
 * @brief   The type of a DIO channel level
 */
typedef enum
{
    DIO_STD_LOW = 0,
    DIO_STD_HIGH = 1
} Dio_LevelType;

/**@} end of group DIO_Enumerations */

/** @defgroup DIO_Structure
  @{
*/

/**
 * @brief   Type for the definition of a channel group, which consists of several adjoining channels within a port
 */
typedef struct
{
    /* This shall be the port on which the Channel group is defined.*/
    VAR(Dio_PortType, AUTOMATIC)      port;
    /* This element shall be the position of the Channel Group on the port, counted from the LSB. */
    VAR(uint8, AUTOMATIC)             offset; 
    /* This element mask which defines the positions of the channel group. */
    VAR(Dio_PortLevelType, AUTOMATIC) mask;        
} Dio_ChannelGroupType;

/**
 * @brief   The type of the DIO configuration structure.
 */
typedef struct
{   
    /* The count of the channel groups */
    VAR(uint8, AUTOMATIC) channelGroupsCount; 
    /* The pointer of the list of channel groups */
    P2CONST(Dio_ChannelGroupType, AUTOMATIC, DIO_APPL_CONST) channelGroupListPtr;  
} Dio_ConfigType;

/**@} end of group DIO_Structure */
/*******************************************************************************
                             GLOBAL DECLARATION
*******************************************************************************/
#define DIO_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "Dio_MemMap.h"

/** @defgroup DIO_Variable
  @{
*/

extern CONST(Dio_ChannelType, DIO_CONST) g_DioAllPortChannel[DIO_CHANNLE_MAX];
extern CONST(Dio_PortType, DIO_CONST) g_DioAllPort[DIO_PORT_MAX];
extern CONST(Dio_ChannelGroupType, DIO_CONST) g_DioConfigChannelGroupList[DIO_CHANNEL_GROUP_NUM];
/** the local Variable used for storing the generated Dio configuration */
extern CONST(Dio_ConfigType, DIO_CONST) g_dioConfig;

/**@} end of group DIO_Variable */

#define DIO_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "Dio_MemMap.h"
/*******************************************************************************
                            FUNCTION DECLARATIONS
*******************************************************************************/
#define DIO_START_SEC_CODE
#include "Dio_MemMap.h"

/** @defgroup DIO_Fuctions
  @{
*/

FUNC(Dio_LevelType, DIO_CODE) Dio_ReadChannel(CONST(Dio_ChannelType, AUTOMATIC) ChannelId);
FUNC(void, DIO_CODE) Dio_WriteChannel(CONST(Dio_ChannelType, AUTOMATIC) ChannelId, 
                                      CONST(Dio_LevelType, AUTOMATIC) Level);
#if (DIO_FLIP_CHANNEL_API == STD_ON)
FUNC(Dio_LevelType, DIO_CODE) Dio_FlipChannel(CONST(Dio_ChannelType, AUTOMATIC) ChannelId);
#endif
FUNC(Dio_PortLevelType, DIO_CODE) Dio_ReadPort(CONST(Dio_PortType, AUTOMATIC) PortId);
FUNC(void, DIO_CODE) Dio_WritePort(CONST(Dio_PortType, AUTOMATIC) PortId, 
                                   CONST(Dio_PortLevelType, AUTOMATIC) Level);
FUNC(Dio_PortLevelType, DIO_CODE) Dio_ReadChannelGroup(P2CONST(Dio_ChannelGroupType, AUTOMATIC, DIO_APPL_CONST) ChannelGroupIdPtr);
FUNC(void, DIO_CODE) Dio_WriteChannelGroup(P2CONST(Dio_ChannelGroupType, AUTOMATIC, DIO_APPL_CONST) ChannelGroupIdPtr,
                                                        CONST(Dio_PortLevelType, AUTOMATIC) Level);
#if (DIO_VERINFO_API == STD_ON)
FUNC(void, MCU_CODE) Dio_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, MCU_APPL_DATA) VersionInfo);
#endif

/**@} end of group DIO_Fuctions */

#define DIO_STOP_SEC_CODE
#include "Dio_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif

/**@} end of group DIO_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
