/*!
* @file     Lin_Cfg.h
*
* @version  1.0.0
*
* @brief    This file includes the configuration parameters of the Lin module.
*            
* @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 LIN_CFG_H
#define LIN_CFG_H

#ifdef __cplusplus
extern "C"
{
#endif  /* ifdef __cplusplus */

#include "EcuM_Cbk.h"
#include "Mcal.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_CFG_H_VENDOR_ID                    0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define LIN_CFG_H_MODULE_ID                    0x0052U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_CFG_H_AR_RELEASE_MAJOR_VERSION     0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_CFG_H_AR_RELEASE_MINOR_VERSION     0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_CFG_H_AR_RELEASE_REVISION_VERSION  0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_CFG_H_SW_MAJOR_VERSION             0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_CFG_H_SW_MINOR_VERSION             0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_CFG_H_SW_PATCH_VERSION             0x00U
/**********************************************************************************************************************           
                                      VERSION INFOMATION VERIFICATION
***********************************************************************************************************************/
#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Lin_Cfg.h and EcuM_Cbk.h */
    #if (LIN_CFG_H_AR_RELEASE_MAJOR_VERSION != ECUM_CBK_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR major Version Numbers mismatch between Lin_Cfg.h and EcuM_Cbk.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Lin_Cfg.h and EcuM_Cbk.h */
    #if (LIN_CFG_H_AR_RELEASE_MINOR_VERSION != ECUM_CBK_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR minor Version Numbers mismatch between Lin_Cfg.h and EcuM_Cbk.h"
    #endif

    /* Make sure the AUTOSAR major version number is the same between Lin_Cfg.h and Mcal.h */
    #if (LIN_CFG_H_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR major Version Numbers mismatch between Lin_Cfg.h and Mcal.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Lin_Cfg.h and Mcal.h */
    #if (LIN_CFG_H_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR minor Version Numbers mismatch between Lin_Cfg.h and Mcal.h"
    #endif
#endif  /* ifdef ENABLE_INTERMODULE_MCAL_CHECK */

/**********************************************************************************************************************
                                            MACRO DEFINITION
***********************************************************************************************************************/
/** Config the LIN channel */
#define LIN_USART1_MASTER                       (STD_OFF)
#define LIN_USART1_SLAVE                        (STD_OFF)
#define LIN_USART2_MASTER                       (STD_OFF)
#define LIN_USART2_SLAVE                        (STD_ON)

#if ((LIN_USART1_MASTER == STD_ON) && (LIN_USART1_SLAVE == STD_ON))
  #error "USART1: MASTER and SLAVE cannot be STD_ON at the same time."
#endif

#if ((LIN_USART2_MASTER == STD_ON) && (LIN_USART2_SLAVE == STD_ON))
  #error "USART2: MASTER and SLAVE cannot be STD_ON at the same time."
#endif

/** Configuration of the LIN function for physical channel USART1 */
#if(STD_ON == LIN_USART1_MASTER)
    /** Link the Lin channels names with the usart channel ids. */
    #define LIN_USART1                          0U
    /** Config LIN_USART1 Node type, MASTER:0 , SLAVE:1 */
    #define LIN_USART1_NODETYPE                 0U
#elif(STD_ON == LIN_USART1_SLAVE)
    /** Link the Lin channels names with the usart channel ids. */
    #define LIN_USART1                          0U
    /** Config LIN_USART1 Node type, MASTER:0 , SLAVE:1 */
    #define LIN_USART1_NODETYPE                 1U
#endif

/** Configuration of the LIN function for physical channel USART2 */
 #if(STD_ON == LIN_USART2_MASTER)
    /** Link the Lin channels names with the usart channel ids. */
    #define LIN_USART2                          1U
    /** Config LIN_USART2 Node type, MASTER:0 , SLAVE:1 */
    #define LIN_USART2_NODETYPE                 0U
#elif(STD_ON == LIN_USART2_SLAVE)
    /** Link the Lin channels names with the usart channel ids. */
    #define LIN_USART2                          1U
    /** Config LIN_USART2 Node type, MASTER:0 , SLAVE:1 */
    #define LIN_USART2_NODETYPE                 1U
#endif

#if ((STD_ON == LIN_USART1_SLAVE) || (STD_ON == LIN_USART2_SLAVE))
    #define LIN_SLAVE_NODECFG
#endif

#if ((STD_ON == LIN_USART1_MASTER) || (STD_ON == LIN_USART2_MASTER))
    #define LIN_MASTER_NODECFG
#endif

/** Configuration LIN Classic Diagnostic IDs */
/** Master -> Slaves */
#define LIN_DIAG_ID_MASTER_REQUEST              0x3C
/** Slave  -> Master */
#define LIN_DIAG_ID_SLAVE_RESPONSE              0x3D
/** Configuration Application / Signal Frame IDs */
/** Designate the valid ID number required for Slave response , Slave  Tx (example) */
#define LIN_APP_ID_SLAVE_PUBLISH                0x16
/** Designate the valid ID number required for Master require , Master Tx (example) */
#define LIN_APP_ID_MASTER_PUBLISH               0x15

#define MAX_FRAME_TIMEOUT                       8   
#define MAX_IDLE_TIMEOUT                        800 

#define SLAVE_TO_MASTER                         0
#define MASTER_TO_SLAVE                         1

/** Enable/disable the Lin_GetVersionInfo() API. */
#define LIN_VERSION_INFO_API                   (STD_ON) 

/** Enable/disable the Development Error Detection and Notification */
#define LIN_DEV_ERR_DETECT                     (STD_OFF) 

/** The count of the loops before reporting LIN_E_TIMEOUT. */
#define LIN_OPERATION_TIMEOUT                  ((uint32)65535U)

/** The max data length of the LIN SDU. */
#define LIN_SDU_MAX_LEN                         8U

/** The count of the available hardware lin channels. */
#define LIN_MAX_HW_AVAILABLE_CH_COUNT           2U

/** The count of the channels configured. */
#define LIN_MAX_HW_CH_COUNT                     2U

/** The symbolic names of the configured channels. */
#define LIN_CONFIG_CHANNEL_0                    0U
#define LIN_CONFIG_CHANNEL_1                    1U

/** The max count of the available hardware USART channels.*/
#define LIN_USART_MAX_COUNT                     2U

/** Enable/disable the Production Error Detection and Notification */
#define LIN_DEM_REP_ERR_DIS                    (STD_ON)
  
/** Minimum length of wakeup pulse */
#define LIN_MINIMUM_LENGTH_WAKEUP_PULSE        ((uint32)250U)

#define LIN_CONFIGURATION_POST_BUILD \
    extern CONST(Lin_ConfigType, LIN_CONST)    g_linConfig;

/**@} end of group LIN_Macros */
/**********************************************************************************************************************
                                             ENUM TYPE DEFINITION
***********************************************************************************************************************/
/** @defgroup LIN_Enumerations
  @{
*/
/**
 * @brief     The definition of the lin node type
 */
typedef enum
{
    MASTER = 0,
    SLAVE = 1
} Lin_NodeType;
/**@} end of group LIN_Enumerations */
/**********************************************************************************************************************
                                             STRUCT TYPE DEFINITION
***********************************************************************************************************************/
/** @defgroup LIN_Structure
  @{
*/
/**
 * @brief     The definition of LIN channel configuration type structure.
 */
typedef struct
{
    VAR(uint8, LIN_VAR) linChId; //!<  The lin channel id
    VAR(uint8, LIN_VAR) linHwCh; //!< The lin hw channel id
    VAR(uint8, LIN_VAR) linChWakeupEn; //!< The wakeup enabled status
    VAR(Lin_NodeType, LIN_VAR) linChNodeType; //!< The lin channel node type
    VAR(EcuM_WakeupSourceType, LIN_VAR) linChEcuMWakeupSrc; //!< The lin wakeup source
} Lin_ChStaticConfigType; 

/**
 * @brief      The definition of LIN channel configuration type structure.
 */
typedef struct
{
    P2CONST(Lin_ChStaticConfigType, LIN_VAR, LIN_APPL_CONST) channelConfigPCPtr; //!< The pointer of precompile configuration structure
    VAR(uint32, LIN_VAR) channelBaudrate; //!< The Lin channel baudrate value
} Lin_ChConfigType;

/**
 * @brief      The definition of LIN driver configuration type structure.
 */
typedef struct
{
    CONSTP2CONST (Lin_ChConfigType,LIN_APPL_CONST,LIN_CONST) linChannelConfigArr[LIN_MAX_HW_CH_COUNT]; //!< Hardware channel configuration
} Lin_ConfigType;
/**@} end of group LIN_Structure */
/**********************************************************************************************************************
                                             GLOBAL VARIABLE
***********************************************************************************************************************/
/** @defgroup LIN_Variable
  @{
*/
#define LIN_START_SEC_CONST_UNSPECIFIED
#include "Lin_MemMap.h"

LIN_CONFIGURATION_POST_BUILD

#if (STD_OFF == LIN_DEM_REP_ERR_DIS)
extern CONST(Mcal_DemErrorType,LIN_CONST) g_linErrTimeoutConfig;
#endif /* {if (STD_OFF == LIN_DEM_REP_ERR_DIS)} */

#define LIN_STOP_SEC_CONST_UNSPECIFIED
#include "Lin_MemMap.h"

#define LIN_START_SEC_VAR_INIT_8
#include "Lin_MemMap.h"

extern VAR(uint8, LIN_VAR) g_sendBufConfig[3][LIN_SDU_MAX_LEN];

#define LIN_STOP_SEC_VAR_INIT_8
#include "Lin_MemMap.h"

/**@} end of group LIN_Variable */

/*******************************************************************************
                            FUNCTION DECLARATION
*******************************************************************************/
/** @defgroup LIN_Fuctions
  @{
*/
#define LIN_START_SEC_CODE
#include "Lin_MemMap.h"

FUNC (void, LIN_CODE) Lin_PidReceivedNotification(VAR(uint8, AUTOMATIC) Pid, VAR(uint8, AUTOMATIC) FrameIndex);
FUNC (void, LIN_CODE) Lin_GetTxDataNotification(VAR(uint8, AUTOMATIC)  FrameIdx, P2VAR(uint8, AUTOMATIC, LIN_APPL_DATA) DataBuffer);
FUNC (uint16, LIN_CODE) Lin_GetCurrentSensorValue(void);

#define LIN_STOP_SEC_CODE
#include "Lin_MemMap.h"
/**@} end of group LIN_Fuctions */

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

