/*!
* @file     Lin.h
*
* @version  1.0.0
*
* @brief    AUTOSAR Lin - High level header of LIN driver.
*           This file contains declarations of the functions defined by AutoSAR.
* @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.
*/

/*
* MISRA-C:2012 compliance checks
*
*      Lin_h_MISRA_REF1
*          Breaks the required M3CM Rule-8.11 of MISRA 2012 guidelines,
*          When an array with external linkage is declared, its size should be explicitly specified.
*/

#ifndef LIN_H
#define LIN_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "Mcal.h"
#include "ComStack_Types.h"
#include "Lin_GeneralTypes.h"
#include "Lin_Cfg.h"
#include "Lin_Hw.h"
/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup LIN_Driver
  * @brief LIN driver modules
  @{
*/

/** @defgroup LIN_Macros
  @{
*/
/*******************************************************************************
                    VENDOR ID & AUTOSAR VERSION INFO
*******************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define LIN_H_VENDOR_ID                       0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define LIN_H_MODULE_ID                       0x0066U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_H_AR_RELEASE_MAJOR_VERSION        0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_H_AR_RELEASE_MINOR_VERSION        0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_H_AR_RELEASE_REVISION_VERSION     0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_H_SW_MAJOR_VERSION                0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_H_SW_MINOR_VERSION                0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_H_SW_PATCH_VERSION                0x00U
/**@} end of group LIN_Macros */
/*******************************************************************************
                             VERSION CHECK
*******************************************************************************/
/* Make sure the vendor ids are the same between Lin.h and Lin_Cfg.h */
#if (LIN_H_VENDOR_ID != LIN_CFG_H_VENDOR_ID)
    #error "Vendor ids mismatch between Lin.h and Lin_Cfg.h" 
#endif /* LIN_H_VENDOR_ID != LIN_CFG_H_VENDOR_ID */

/* Make sure the AUTOSAR major version number is the same between Lin.h and Lin_Cfg.h */
#if (LIN_H_AR_RELEASE_MAJOR_VERSION != LIN_CFG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR major Version Numbers mismatch between Lin.h and Lin_Cfg.h"
#endif /* {(LIN_H_AR_RELEASE_MAJOR_VERSION != LIN_CFG_H_AR_RELEASE_MAJOR_VERSION)} */
/* Make sure the AUTOSAR minor version number is the same between Lin.h and Lin_Cfg.h */
#if (LIN_H_AR_RELEASE_MINOR_VERSION != LIN_CFG_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR minor Version Numbers mismatch between Lin.h and Lin_Cfg.h"
#endif /* {(LIN_H_AR_RELEASE_MINOR_VERSION != LIN_CFG_H_AR_RELEASE_MINOR_VERSION)} */
/* Make sure the AUTOSAR revision version number is the same between Lin.h and Lin_Cfg.h */
#if (LIN_H_AR_RELEASE_REVISION_VERSION != LIN_CFG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR revision Version Numbers mismatch between Lin.h and Lin_Cfg.h"
#endif /* {(LIN_H_AR_RELEASE_REVISION_VERSION != LIN_CFG_H_AR_RELEASE_REVISION_VERSION)} */
  
/* Make sure the software major version number is the same between Lin.h and Lin_Cfg.h */
#if (LIN_H_SW_MAJOR_VERSION != LIN_CFG_H_SW_MAJOR_VERSION)
    #error "Software major Version Numbers mismatch between Lin.h and Lin_Cfg.h"
#endif /* {(LIN_H_SW_MAJOR_VERSION != LIN_CFG_H_SW_MAJOR_VERSION)} */
/* Make sure the software minor version number is the same between Lin.h and Lin_Cfg.h */
#if (LIN_H_SW_MINOR_VERSION != LIN_CFG_H_SW_MINOR_VERSION)
    #error "Software minor Version Numbers mismatch between Lin.h and Lin_Cfg.h"
#endif /* {(LIN_H_SW_MINOR_VERSION != LIN_CFG_H_SW_MINOR_VERSION)} */
/* Make sure the software patch version number is the same between Lin.h and Lin_Cfg.h */
#if (LIN_H_SW_PATCH_VERSION != LIN_CFG_H_SW_PATCH_VERSION)
    #error "Software patch Version Numbers mismatch between Lin.h and Lin_Cfg.h"
#endif /* {(LIN_H_SW_PATCH_VERSION != LIN_CFG_H_SW_PATCH_VERSION)} */

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Lin.h and ComStack_Types.h */
    #if (LIN_H_AR_RELEASE_MAJOR_VERSION != COM_STACK_TYPES_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR major Version Numbers mismatch between Lin.h and ComStack_Types.h"
    #endif /* {(LIN_H_AR_RELEASE_MAJOR_VERSION != COM_STACK_TYPES_H_AR_RELEASE_MAJOR_VERSION)} */
    /* Make sure the AUTOSAR minor version number is the same between Lin.h and ComStack_Types.h */
    #if (LIN_H_AR_RELEASE_MINOR_VERSION != COM_STACK_TYPES_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR minor Version Numbers mismatch between Lin.h and ComStack_Types.h"
    #endif /* {(LIN_H_AR_RELEASE_MINOR_VERSION != COM_STACK_TYPES_H_AR_RELEASE_MINOR_VERSION)} */

    /* Make sure the AUTOSAR major version number is the same between Lin.h and Mcal.h */
    #if (LIN_H_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR major Version Numbers mismatch between Lin.h and Mcal.h"
    #endif /* {(LIN_H_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)} */
      /* Make sure the AUTOSAR minor version number is the same between Lin.h and Mcal.h */
    #if (LIN_H_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR minor Version Numbers mismatch between Lin.h and Mcal.h"
    #endif /* {(LIN_H_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)} */

    /* Make sure the AUTOSAR major version number is the same between Lin.h and Lin_GeneralTypes.h */
    #if (LIN_H_AR_RELEASE_MAJOR_VERSION != LIN_GENERAL_TYPES_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR major Version Numbers mismatch between Lin.h and Lin_GeneralTypes.h"
    #endif /* {(LIN_H_AR_RELEASE_MAJOR_VERSION != LIN_GENERAL_TYPES_H_AR_RELEASE_MAJOR_VERSION)} */
     /* Make sure the AUTOSAR minor version number is the same between Lin.h and Lin_GeneralTypes.h */
    #if (LIN_H_AR_RELEASE_MINOR_VERSION != LIN_GENERAL_TYPES_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR minor Version Numbers mismatch between Lin.h and Lin_GeneralTypes.h"
    #endif /* {(LIN_H_AR_RELEASE_MINOR_VERSION != LIN_GENERAL_TYPES_H_AR_RELEASE_MINOR_VERSION)} */ 
#endif
/*******************************************************************************
                            ENUMERATION DEFINITION
*******************************************************************************/
/** @defgroup LIN_Enumerations
  @{
*/
/**
* @brief    This enum contains API functions service IDs.
*/
enum
{
    LIN_API_INIT_ID                  = (uint8)0x00U, //!< Lin_Init()ID 
    LIN_API_GETVERSIONINFO_ID        = (uint8)0x01U, //!< Lin_GetVersionInfo() ID 
    LIN_API_SENDFRAME_ID             = (uint8)0x04U, //!< Lin_SendFrame() ID 
    LIN_API_GOTOSLEEP_ID             = (uint8)0x06U, //!< Lin_GoToSleep() ID 
    LIN_API_WAKEUP_ID                = (uint8)0x07U, //!< Lin_WakeUp() ID 
    LIN_API_GETSTATUS_ID             = (uint8)0x08U, //!< Lin_GetStatus() ID 
    LIN_API_GOTOSLEEPINTERNAL_ID     = (uint8)0x09U, //!< Lin_GoToSleepInternal() ID 
    LIN_API_CHECKWAKEUP_ID           = (uint8)0x0AU, //!< Lin_CheckWakeup() ID 
    LIN_API_WAKEUPINTERNAL_ID        = (uint8)0x0BU  //!< Lin_WakeupInternal() ID 
#ifdef LIN_USE_MSC                                   
    LIN_API_MSC_INITCHANNEL_ID       = (uint8)0x0BU, //!< Msc_InitChannel() ID 
    LIN_API_MSC_DEINITCHANNEL_ID     = (uint8)0x0CU, //!< Msc_DeInitChannel() ID 
    LIN_API_MSC_GETSTATUS_ID         = (uint8)0x0DU, //!< Msc_GetStatus() ID 
    LIN_API_MSC_POLLING_ID           = (uint8)0x0EU, //!< Msc_Polling() ID 
#endif
};
 
enum
{
    LIN_E_UNINIT            = ((uint8)0x00U), //!< API service used without module initialization 
    LIN_E_INVALID_CHANNEL   = ((uint8)0x02U), //!< API service used with an invalid or inactive channel parameter 
    LIN_E_INVALID_POINTER   = ((uint8)0x03U), //!< API service called with invalid configuration pointer 
    LIN_E_STATE_TRANSITION  = ((uint8)0x04U), //!< Invalid state transition for the current state 
    LIN_E_PARAM_POINTER     = ((uint8)0x05U)  //!< API service called with a NULL pointer 
#if (LIN_DEV_ERR_DETECT == STD_ON)     
    ,         
    LIN_E_TIMEOUT           = ((uint8)0x06U) //!< Timeout caused by hardware error 
#endif  /* LIN_DEV_ERR_DETECT == STD_ON */
};
  
enum
{
    LIN_UNINIT = ((uint8)0x01U), //!< The LIN module is not initialized and cannot be used 
    LIN_INIT   = ((uint8)0x02U) //!< The LIN module is initialized and can be used by every available channel 
};

enum
{
    LIN_CH_SLEEP_PENDING                 = ((uint8)0x01U), //!< go-to-sleep-command is sent to the bus until Lin_GetStatus() is called 
    LIN_CH_SLEEP_STATE                   = ((uint8)0x02U), //!< Can detect wake up pulse.LIN hardware enters low power mode(hardware support) 
    LIN_CH_OPERATIONAL                   = ((uint8)0x03U), //!< The individual channel has been initialized 
    LIN_CHANNEL_NOT_READY_STATE          = ((uint8)0x04U), //!< Individual channel are not yet ready 
    LIN_CHANNEL_READY_STATE              = ((uint8)0x05U), //!< A single channel is ready to process frames 
    LIN_CHANNEL_TX_COMPLETE_STATE        = ((uint8)0x06U), //!< LIN frame was sent; no errors 
    LIN_CHANNEL_RX_COMPLETE_STATE        = ((uint8)0x07U), //!< LIN frame was received; no errors 
    LIN_CHANNEL_RECEIVE_NOTHING_STATE    = ((uint8)0x08U), //!< The state of the LIN frame after the header is correctly sent 
    LIN_CHANNEL_RX_ONGOING_STATE         = ((uint8)0x09U), //!< LIN frame is receiving 
    LIN_CHANNEL_TX_HEADER_COMPLETE_STATE = ((uint8)0x10U)  //!< LIN header is transmission 
};

typedef enum
{
    LIN_NO_INT_ERROR                = ((uint8)0x00U), //!< No error occurred on a channel 
    LIN_BIT_INT_ERROR               = ((uint8)0x01U), //!< Bit error on channel during response field transfer and during header transmission 
    LIN_CHECKSUM_INT_ERROR          = ((uint8)0x02U), //!< Check sum error on channel 
    LIN_SYNCH_FIELD_INT_ERROR       = ((uint8)0x03U), //!< Different synchronization fields 
    LIN_BREAK_DELIMITER_INT_ERROR   = ((uint8)0x04U), //!< Break Delimiter too short 
    LIN_IDENTIFIER_PARITY_INT_ERROR = ((uint8)0x05U), //!< Parity error 
    LIN_FRAMING_INT_ERROR           = ((uint8)0x06U), //!< Invalid stop bit 
    LIN_BUFFER_OVER_RUN_INT_ERROR   = ((uint8)0x07U), //!< Received new data bytes on the channel and the buffer is full but not cleared 
    LIN_NOISE_INT_ERROR             = ((uint8)0x08U), //!< Noise detected on the received character 
    LIN_TIMEOUT_INT_ERROR           = ((uint8)0x09U), //!< Header or Response timeout detected 
    LIN_BUFFER_UNDER_RUN_INT_ERROR  = ((uint8)0x0AU)  //!< shifter is ready to load the new data from SHIFTBUF before writing to SHIFTBUF 
} Lin_InterruptErrorsType;

enum
{
    LIN_TX_MASTER_RES_COMMAND_ID     = ((uint8)0x01U), //!< Tx frame is a master frame 
    LIN_TX_SLAVE_RES_COMMAND_ID      = ((uint8)0x02U), //!< Tx frame is a slave frame 
    LIN_TX_SLEEP_COMMAND_ID          = ((uint8)0x03U), //!< Tx frame are sleep command frame 
    LIN_TX_NO_COMMAND_ID             = ((uint8)0x04U), //!< No tx master command pending 
    LIN_TX_SLAVE_TO_SLAVE_COMMAND_ID = ((uint8)0x05U)  //!< Tx frame is a slave frame 
};

typedef enum
{
    LIN_ERROR = 0,
    LIN_TX = 1,
    LIN_RX = 2
} Lin_StateType;

/**@} end of group LIN_Enumerations */
/*******************************************************************************
                           STRUCT TYPE DEFINITION
*******************************************************************************/
/** @defgroup LIN_Structure
  @{
*/
typedef struct
{
    VAR(uint8, LIN_VAR) id;
    VAR(uint8, LIN_VAR) protected_id;
    VAR(uint8, LIN_VAR) data_len;
    VAR(uint8, LIN_VAR) data_dir;
}Lin_MsgType;
/**@} end of group LIN_Structure */
/*******************************************************************************
                            GLOBAL VARIABLE
*******************************************************************************/
/** @defgroup LIN_Variable
  @{
*/
#define LIN_START_SEC_VAR_NO_INIT_8
#include "Lin_MemMap.h"
 
extern VAR(sint8,LIN_VAR)g_ChannelHWMap[LIN_MAX_HW_AVAILABLE_CH_COUNT];
extern volatile VAR(uint8,LIN_VAR)g_LinChannelFrameErrorStatus[LIN_MAX_HW_CH_COUNT];
extern VAR(uint8, LIN_VAR)g_LinTXHeaderCommand[LIN_MAX_HW_CH_COUNT];
extern volatile VAR(uint8,LIN_VAR)g_LinChannelFrameStatus[LIN_MAX_HW_CH_COUNT];
extern volatile VAR(uint8,LIN_VAR)g_LinChannelStatus[LIN_MAX_HW_CH_COUNT];

#define LIN_STOP_SEC_VAR_NO_INIT_8
#include "Lin_MemMap.h"

#define LIN_START_SEC_VAR_INIT_UNSPECIFIED
#include "Lin_MemMap.h"
 
extern P2CONST(Lin_ConfigType,LIN_VAR,LIN_APPL_CONST) g_LinPCCfgPointer;

#define LIN_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Lin_MemMap.h"

#define LIN_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Lin_MemMap.h"
 
extern P2CONST(Lin_ChConfigType,LIN_VAR,LIN_APPL_CONST)g_LinChCfgPtr[LIN_MAX_HW_CH_COUNT];

#define LIN_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Lin_MemMap.h"
 
#define LIN_START_SEC_VAR_INIT_8
#include "Lin_MemMap.h"

/** LIN driver status variable */
extern VAR(uint8,LIN_VAR)g_LinDriverStatus;
extern Lin_StateType g_linState;

#define LIN_STOP_SEC_VAR_INIT_8
#include "Lin_MemMap.h"

#define LIN_START_SEC_CONST_32
#include "Lin_MemMap.h"

#ifdef LIN_SLAVE_NODECFG
/** Lin message configured table for Slave node. */
/*** @warning Lin_h_MISRA_REF1 Array declared with unknown size. */
extern const Lin_MsgType g_linMsgCfgTable[];
extern const uint8_t g_linMsgTblLen;
#endif

#define LIN_STOP_SEC_CONST_32
#include "Lin_MemMap.h"

/**@} end of group LIN_Variable */
/*******************************************************************************
                            FUNCTION DECLARATION
*******************************************************************************/
/** @defgroup LIN_Fuctions
  @{
*/
#define LIN_START_SEC_CODE
#include "Lin_MemMap.h"

FUNC(Lin_StatusType, LIN_CODE) Lin_GetStatus(VAR(uint8, AUTOMATIC) LinChannel, \
                                  P2P2VAR(uint8, AUTOMATIC, LIN_APPL_DATA) LinSduPtr);
FUNC(Std_ReturnType, LIN_CODE) Lin_WakeupInternal(VAR(uint8, AUTOMATIC) ChannelID); 
FUNC(Std_ReturnType, LIN_CODE) Lin_Wakeup(VAR(uint8, AUTOMATIC) ChannelID);
FUNC(Std_ReturnType, LIN_CODE) Lin_GoToSleepInternal(VAR(uint8, AUTOMATIC) ChannelID);
FUNC(Std_ReturnType, LIN_CODE) Lin_GoToSleep(VAR(uint8, AUTOMATIC) LinChannel);
FUNC(Std_ReturnType, LIN_CODE) Lin_SendFrame(VAR(uint8, AUTOMATIC) ChannelID, \
                                  P2CONST(Lin_PduType, AUTOMATIC,LIN_APPL_CONST) pduInfoPtr);
FUNC(Std_ReturnType, LIN_CODE) Lin_CheckWakeup(VAR(uint8, AUTOMATIC) LinChannel);
FUNC(void, LIN_CODE) Lin_Init(P2CONST(Lin_ConfigType, AUTOMATIC, LIN_APPL_CONST) LinConfig);
#if (LIN_VERSION_INFO_API == STD_ON)
FUNC (void, LIN_CODE) Lin_GetVersionInfo (P2VAR (Std_VersionInfoType, AUTOMATIC, \
                                  LIN_APPL_DATA) linVersioninfo);
#endif /* LIN_VERSION_INFO_API == STD_ON */

#define LIN_STOP_SEC_CODE
#include "Lin_MemMap.h"

/**@} end of group LIN_Fuctions */
#ifdef __cplusplus
}
#endif 
#endif
/**@} end of group LIN_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
