/**
 *   @file    Dio.h
 *   @version
 *
 *   @brief   AUTOSAR Dio module interface
 *   @details API implementation for DIO driver
 *
 *   @addtogroup DIO_MODULE
 *   @{
 */
/*==================================================================================================
*   Project              : YTMicro AUTOSAR 4.4.0 MCAL
*   Platform             : ARM
*   Peripheral           : Dio
*   Dependencies         : none
*
*   Autosar Version      : V4.4.0
*   Autosar Revision     : ASR_REL_4_4_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : V0.8.0
*
*
*   (c) Copyright 2020-2026 Yuntu Microelectronics co.,ltd.
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef DIO_H
#define DIO_H

/**
*   @file Dio.h
*   @implements Dio.h_Artifact
*
*   @defgroup DIO
*   @{
*/

#ifdef __cplusplus
extern "C"
{
#endif


/*=================================================================================================
*                                        INCLUDE FILES
=================================================================================================*/
#include "Dio_Types.h"

/*==================================================================================================
*                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/**
 * @file     Dio.h
 */
#define DIO_VENDOR_ID                      (180)
#define DIO_AR_RELEASE_MAJOR_VERSION       (4)
#define DIO_AR_RELEASE_MINOR_VERSION       (4)
#define DIO_AR_RELEASE_REVISION_VERSION    (0)
#define DIO_SW_MAJOR_VERSION               (0)
#define DIO_SW_MINOR_VERSION               (8)
#define DIO_SW_PATCH_VERSION               (0)

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/**
 * @file     Dio.h
 */

/* Check if source file and Dio_Types.h are of the same vendor */
#if (DIO_VENDOR_ID != DIO_TYPES_VENDOR_ID)
#error "Dio.h and Dio_Types.h have different vendor ids"
#endif

/* Check if source file and Dio_Types.h are of the same Autosar version */
#if ((DIO_AR_RELEASE_MAJOR_VERSION != DIO_TYPES_AR_RELEASE_MAJOR_VERSION) || \
     (DIO_AR_RELEASE_MINOR_VERSION != DIO_TYPES_AR_RELEASE_MINOR_VERSION) || \
     (DIO_AR_RELEASE_REVISION_VERSION != DIO_TYPES_AR_RELEASE_REVISION_VERSION))
#error "AutoSar Version Numbers of Dio.h and Dio_Types.h are different"
#endif

/* Check if source file and Dio_Types.h are of the same software version */
#if ((DIO_SW_MAJOR_VERSION != DIO_TYPES_SW_MAJOR_VERSION) || \
     (DIO_SW_MINOR_VERSION != DIO_TYPES_SW_MINOR_VERSION) || \
     (DIO_SW_PATCH_VERSION != DIO_TYPES_SW_PATCH_VERSION))
#error "Software Version Numbers of Dio.h and Dio_Types.h are different"
#endif
/*==================================================================================================
*                                       DEFINES AND MACROS
==================================================================================================*/

/** @brief DIO MODULE INSTANCE ID */
#define DIO_INSTANCE_ID ((uint8)0U)

/** @brief DIO MODULE ID */
#define DIO_MODULE_ID (120U)

#if (DIO_DEV_ERROR_DETECT == STD_ON)
/**
 * @defgroup Dio_DEV_ERROR
 * @brief DIO development errors
 */
/** @{ */
/** @brief Invalid channel name requested */
#define DIO_E_PARAM_INVALID_CHANNEL_ID (0x0AU)
/** @brief Invalid port name requested */
#define DIO_E_PARAM_INVALID_PORT_ID (0x14U)
/** @brief Invalid ChannelGroup passed */
#define DIO_E_PARAM_INVALID_GROUP (0x1FU)
/** @brief API service called with a NULL pointer */
#define DIO_E_PARAM_POINTER (0x20U)
/** @brief Invalid channel level */
/** @} */
#endif

/**
 * @defgroup Dio_SID
 * @brief Service ID number for all DIO driver services
 */
/** @{ */
/** @brief API Service ID for Dio_ReadChannel */
#define DIO_SID_READ_CHANNEL ((uint8)0x00)
/** @brief API Service ID for Dio_WriteChannel */
#define DIO_SID_WRITE_CHANNEL ((uint8)0x01)
/** @brief API Service ID for Dio_ReadPort */
#define DIO_SID_READ_PORT ((uint8)0x02)
/** @brief API Service ID for Dio_WritePort */
#define DIO_SID_WRITE_PORT ((uint8)0x03)
/** @brief API Service ID for Dio_ReadChannelGroup */
#define DIO_SID_READ_CHANNEL_GROUP ((uint8)0x04)
/** @brief API Service ID for Dio_WriteChannelGroup */
#define DIO_SID_WRITE_CHANNEL_GROUP ((uint8)0x05)
/** @brief API Service ID for Dio_MaskedWritePort */
#define DIO_SID_MASKED_WRITE_PORT ((uint8)0x13)
/** @brief API Service ID for Dio_GetVersionInfo */
#define DIO_SID_GET_VERSION_INFO  ((uint8)0x12)
/** @brief API Service ID for Dio_FlipChannel */
#define DIO_SID_FLIP_CHANNEL ((uint8)0x11)
/** @} */

/** @brief DIO channel unmasked/unavailable */
#define DIO_PIN_NOT_MASKED ((uint32)0U)

/** @brief DIO channel masked/available */
/*#define DIO_PIN_MASKED ((uint32)1U)*/

/** @brief Total number of ports in the MCU */
#define DIO_PORT_TOTAL_NUMBER (5U)

/** @brief Total number of pins in a port */
#define DIO_PORT_PIN_TOTAL_NUMBER (32U)

#if (DIO_CHANNELID_CONTINUITY == STD_ON)

/** @brief Get the pin number of a DIO channel */
#define DIO_CHANNEL_PIN_NUM(x)   ((Dio_ChannelType)(x)%DIO_PORT_PIN_TOTAL_NUMBER)
/** @brief Get the port number of a DIO channel */
#define DIO_CHANNEL_PORT_NUM(x)  ((Dio_ChannelType)(x)/DIO_PORT_PIN_TOTAL_NUMBER)

#else   /* DIO_CHANNELID_CONTINUITY == STD_OFF */

/** @brief Get the pin number of a DIO channel */
#define DIO_CHANNEL_PIN_NUM(x)   ((Dio_ChannelType)((x)&0x00FFU))
/** @brief Get the port number of a DIO channel */
#define DIO_CHANNEL_PORT_NUM(x)  ((Dio_ChannelType)((x)&0xFF00U)>>8U)

#endif /* DIO_CHANNELID_CONTINUITY == STD_ON */


/*==================================================================================================
*                                             ENUMS
==================================================================================================*/


/*==================================================================================================
*                                         EXTERNAL CONSTANTS
==================================================================================================*/
#if (DIO_CHANNEL_GROUP_NUMBER != 0)
extern  const Dio_ChannelGroupType Dio_ChannelGroupConfig[DIO_CHANNEL_GROUP_NUMBER];
#endif

/*==================================================================================================
                                       GLOBAL FUNCTIONS
==================================================================================================*/

/**
 * @brief         Service to flip the level of a channel and return the level of the channel after flip.
 * @autosar       SWS_Dio_00190
 *
 * @details       Service ID: 0x11
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] ChannelId: ID of DIO channel
 * @return Dio_LevelType STD_HIGH: The physical level of the corresponding Pin is STD_HIGH;
 *         STD_LOW: The physical level of the corresponding Pin is STD_LOW
*/
Dio_LevelType Dio_FlipChannel(Dio_ChannelType ChannelId);

/**
 * @brief         Returns the value of the specified DIO channel.
 * @autosar       SWS_Dio_00133
 *
 * @details       Service ID: 0x00
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] ChannelId: ID of DIO channel
 * @return Dio_LevelType STD_HIGH: The physical level of the corresponding Pin is STD_HIGH;
 *         STD_LOW: The physical level of the corresponding Pin is STD_LOW
*/
Dio_LevelType Dio_ReadChannel(Dio_ChannelType ChannelId);

#if (DIO_CHANNEL_GROUP_NUMBER != 0)
/**
 * @brief         This Service reads a subset of the adjoining bits of a port.
 * @autosar       SWS_Dio_00137
 *
 * @details       Service ID: 0x04
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] ChannelGroupIdPtr: Pointer to ChannelGroup
 * @return Dio_PortLevelType Level of a subset of the adjoining bits of a port
*/
Dio_PortLevelType Dio_ReadChannelGroup(const Dio_ChannelGroupType *ChannelGroupIdPtr);
#endif /* (DIO_CHANNEL_GROUP_NUMBER != 0) */

/**
 * @brief         Returns the level of all channels of that port.
 * @autosar       SWS_Dio_00135
 *
 * @details       Service ID: 0x02
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] PortId: ID of DIO Port
 * @return Dio_PortLevelType Level of all channels of that port
*/
Dio_PortLevelType Dio_ReadPort(Dio_PortType PortId);

/**
 * @brief         Service to set a level of a channel.
 * @autosar       SWS_Dio_00134
 *
 * @details       Service ID: 0x01
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] ChannelId: ID of DIO channel
 * @param[in] Level: Value to be written
 * @return void
*/
void Dio_WriteChannel(Dio_ChannelType ChannelId, Dio_LevelType Level);

#if (DIO_CHANNEL_GROUP_NUMBER != 0)
/**
 * @brief         Service to set a subset of the adjoining bits of a port.
 * @autosar       SWS_Dio_00138
 *
 * @details       Service ID: 0x05
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] ChannelGroupIdPtr: Pointer to ChannelGroup
 * @param[in] Level: Value to be written
 * @return void
*/
void Dio_WriteChannelGroup(const Dio_ChannelGroupType *ChannelGroupIdPtr, Dio_PortLevelType Level);
#endif /* (DIO_CHANNEL_GROUP_NUMBER != 0) */

/**
 * @brief         Service to set a value of the port.
 * @autosar       SWS_Dio_00136
 *
 * @details       Service ID: 0x03
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] PortId: ID of DIO Port
 * @param[in] Level: Value to be written
 * @return void
*/
void Dio_WritePort(Dio_PortType PortId, Dio_PortLevelType Level);

#if (DIO_MASKED_WRITE_PORT_API == STD_ON)
/**
 * @brief         Service to set the value of a given port with required mask.
 * @autosar       SWS_Dio_00300
 *
 * @details       Service ID: 0x13
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[in] PortId: ID of DIO Port
 * @param[in] Level: Value to be written
 * @param[in] Mask: Channels to be masked in the port
 * @return void
*/
void Dio_MaskedWritePort(Dio_PortType PortId, Dio_PortLevelType Level, Dio_PortLevelType Mask);
#endif /* (DIO_MASKED_WRITE_PORT_API == STD_ON) */

#if (DIO_VERSION_INFO_API == STD_ON)
/**
 * @brief         Service to get the version information of this module.
 * @autosar       SWS_Dio_00139
 *
 * @details       Service ID: 0x12
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Dio.h
 *
 * @param[out] VersionInfo: Pointer to where to store the version information of this module
 * @return void
*/
void Dio_GetVersionInfo(Std_VersionInfoType *VersionInfo);
#endif
#ifdef __cplusplus
}
#endif

#endif /* DIO_H */

/** @} */

