/**
 * @file    Port.h
 * @version
 *
 * @brief   AUTOSAR Port module interface
 * @details API implementation for PORT driver
 *
 * @addtogroup PORT_MODULE
 * @{
 */
/*==================================================================================================
 *   Project              : YTMicro AUTOSAR 4.4.0 MCAL
 *   Platform             : ARM
 *   Peripheral           : Port
 *   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 PORT_H
#define PORT_H

#ifdef __cplusplus
extern "C"
{
#endif


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

/*==================================================================================================
 *                               SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define PORT_VENDOR_ID                      (180)
#define PORT_AR_RELEASE_MAJOR_VERSION       (4)
#define PORT_AR_RELEASE_MINOR_VERSION       (4)
#define PORT_AR_RELEASE_REVISION_VERSION    (0)
#define PORT_SW_MAJOR_VERSION               (0)
#define PORT_SW_MINOR_VERSION               (8)
#define PORT_SW_PATCH_VERSION               (0)

/*==================================================================================================
 *                                     FILE VERSION CHECKS
==================================================================================================*/

/* Check if source file and PORT configuration header file are of the same vendor */
#if (PORT_VENDOR_ID != PORT_TYPES_VENDOR_ID)
#error "Port.h and Port_Types.h have different vendor ids"
#endif

/* Check if source file and PORT configuration header file are of the same Autosar version */
#if ((PORT_AR_RELEASE_MAJOR_VERSION != PORT_TYPES_AR_RELEASE_MAJOR_VERSION) || \
     (PORT_AR_RELEASE_MINOR_VERSION != PORT_TYPES_AR_RELEASE_MINOR_VERSION) || \
     (PORT_AR_RELEASE_REVISION_VERSION != PORT_TYPES_AR_RELEASE_REVISION_VERSION))
#error "AutoSar Version Numbers of Port.h and Port_Types.h are different"
#endif

/* Check if source file and PORT configuration header file are of the same software version */
#if ((PORT_SW_MAJOR_VERSION != PORT_TYPES_SW_MAJOR_VERSION) || \
     (PORT_SW_MINOR_VERSION != PORT_TYPES_SW_MINOR_VERSION) || \
     (PORT_SW_PATCH_VERSION != PORT_TYPES_SW_PATCH_VERSION))
#error "Software Version Numbers of Port.h and Port_Types.h are different"
#endif

/*==================================================================================================
 *                                       DEFINES AND MACROS
==================================================================================================*/
/** @brief PORT MODULE INSTANCE ID */
#define PORT_INSTANCE_ID                    ((uint8)0U)

/** @brief PORT MODULE ID */
#define PORT_MODULE_ID                      (124U)

#if (PORT_DEV_ERROR_DETECT == STD_ON)
/**
 * @defgroup        PORT_DEV_ERROR
 * @brief           PORT development errors
 * @{
 */
/** @brief Invalid Port Pin ID requested */
#define PORT_E_PARAM_PIN                    ((uint8)0x0A)
/** @brief Port Pin not configured as changeable */
#define PORT_E_DIRECTION_UNCHANGEABLE       ((uint8)0x0B)
/** @brief API Port_Init service called with wrong parameter */
#define PORT_E_PARAM_CONFIG                 ((uint8)0x0C)
/** @brief API Port_SetPinMode service called when paramater invalid mode */
#define PORT_E_PARAM_INVALID_MODE           ((uint8)0x0D)
/** @brief API Port_SetPinMode service called when mode unchangeable */
#define PORT_E_MODE_UNCHANGEABLE            ((uint8)0x0E)
/** @brief API service called without module initialization */
#define PORT_E_UNINIT                       ((uint8)0x0F)
/** @brief APIs called with a Null Pointer */
#define PORT_E_PARAM_POINTER                ((uint8)0x10)
/** @} */

/**
 * @defgroup        PORT_SID
 * @brief           Service ID number for all PORT driver services
 */
/** @{ */
/** @brief API Service ID for Port_GetVersionInfo */
#define PORT_SID_GET_VERSION_INFO           (0x03U)
/** @brief API Service ID for Port_Init */
#define PORT_SID_INIT                       (0x00U)
/** @brief API Service ID for Port_RefreshPortDirection */
#define PORT_SID_REFRESH_PORT_SID_DIRECTION (0x02U)
/** @brief API Service ID for Port_SetPinDirection */
#define PORT_SID_SET_PIN_DIRECTION          (0x01U)
/** @brief API Service ID for Port_SetPinMode */
#define PORT_SID_SET_PIN_MODE               (0x04U)
/** @} */
#endif

/**
 @brief Pin masked(available) define.
 */
#define PORT_PIN_NOT_MASKED     ((uint32)0U) /**< Port Pin is available in the hardware */
#define PORT_PIN_MASKED         ((uint32)1U) /**< Port Pin is not available in the hardware */


/**
 @brief Port ID and Pin ID masked(available) define.
 */
#define PORT_HW_ID_PIN_MASK ((Port_PinType)0x00FF)  /**< Port ID mask: Highest 8 bit of half word */
#define PORT_HW_ID_PORT_MASK ((Port_PinType)0xFF00) /**< Port ID mask: Lowest 8 bit of half word */
#define PORT_HW_PIN(Pin) ((Port_HwPinType)Pin)

/**
 * @defgroup PORT_HW_ID
 * @brief Hardware Port ID define.
 */
/** @{ */
#define PORT_HW_PORT_A ((Port_HwPortType)0) /**< Hardware PORT A ID */
#define PORT_HW_PORT_B ((Port_HwPortType)1) /**< Hardware PORT B ID */
#define PORT_HW_PORT_C ((Port_HwPortType)2) /**< Hardware PORT C ID */
#define PORT_HW_PORT_D ((Port_HwPortType)3) /**< Hardware PORT D ID */
#define PORT_HW_PORT_E ((Port_HwPortType)4) /**< Hardware PORT E ID */
/** @} */

/** @brief Port Pin Mode Type Nums */

#if defined (CPU_YTM32B1HA0)
#define PORT_PIN_MODE_NUMS             ((uint8)16U)
#else
#define PORT_PIN_MODE_NUMS             ((uint8)8U)
#endif


/**
 * @brief Hardware Port pin ID define
 */
#define PORT_HW_PORT_PIN(Port, Pin) (((Port_PinType)Port << 8) + ((Port_PinType)Pin))
/*==================================================================================================
 *                                             ENUMS
==================================================================================================*/

/*==================================================================================================
 *                                        EXTERNAL CONSTANTS
==================================================================================================*/
/** @brief Declaration of port post build configuration */
#if (PORT_FIXED_PB_CONFIG == STD_ON)
extern const Port_ConfigType Port_PinsConfig[];
#endif

/*==================================================================================================
 *                                         GLOBAL FUNCTIONS
==================================================================================================*/
/**
 * @brief         Initializes the Port Driver module.
 * @autosar       SWS_Port_00140
 *
 * @details       Service ID: 0x00
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Port.h
 *
 * @param[in] ConfigPtr: Pointer to configuration set
 * @return void
*/
void Port_Init(const Port_ConfigType *ConfigPtr);

/**
 * @brief         Refreshes port direction
 * @autosar       SWS_Port_00142
 *
 * @details       Service ID: 0x02
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Port.h
 *
 * @return void
*/
void Port_RefreshPortDirection(void);

#if (PORT_SET_PIN_DIRECTION_API == STD_ON)
/**
 * @brief         Sets the port pin direction
 * @autosar       SWS_Port_00141
 *
 * @details       Service ID: 0x01
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Port.h
 *
 * @param[in] Pin:  Port Pin ID number
 * @param[in] Direction: Port Pin Direction
 * @return void
*/
void Port_SetPinDirection(Port_PinType Pin, Port_PinDirectionType Direction);
#endif

#if (PORT_SET_PIN_MODE_API == STD_ON)
/**
 * @brief         Sets the port pin mode
 * @autosar       N/A
 *
 * @details       Service ID: 0x04
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Port.h
 *
 * @param[in] Pin:  Port Pin ID number
 * @param[in] Mode: New Port Pin mode to be set on port pin
 * @return void
*/
void Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode);
#endif

#if (PORT_VERSION_INFO_API == STD_ON)
/**
 * @brief         Returns the version information of this module
 * @autosar       SWS_Port_00143
 *
 * @details       Service ID: 0x03
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Port.h
 *
 * @param[out] VersionInfo: Pointer to where to store the version information of this module
 * @return void
*/
void Port_GetVersionInfo(Std_VersionInfoType *VersionInfo);
#endif

#ifdef __cplusplus
}
#endif

#endif /* PORT_H */

/** @} */

