/*!
* @file     Lin_PBCfg.c
*
* @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.
*/

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

#include "Std_Types.h"
#include "Lin.h"
#include "Lin_Hw.h"

#if (STD_OFF == LIN_DEM_REP_ERR_DIS)
#include "Dem.h"
#endif /* {if (STD_OFF == LIN_DEM_REP_ERR_DIS)} */
/** @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_PBCFG_VENDOR_ID                      0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_PBCFG_AR_RELEASE_MAJOR_VERSION       0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_PBCFG_AR_RELEASE_MINOR_VERSION       0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define LIN_PBCFG_AR_RELEASE_REVISION_VERSION    0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_PBCFG_SW_MAJOR_VERSION               0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_PBCFG_SW_MINOR_VERSION               0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define LIN_PBCFG_SW_PATCH_VERSION               0x00U
/**@} end of group LIN_Macros */
/**********************************************************************************************************************           
                                      VERSION INFOMATION VERIFICATION
***********************************************************************************************************************/

#if (LIN_PBCFG_VENDOR_ID != LIN_H_VENDOR_ID)
    #error "Vendor ids mismatch between Lin_Cfg.c and Lin.h"
#endif  /* {if (LIN_PBCFG_VENDOR_ID != LIN_H_VENDOR_ID)} */

/* Make sure the AUTOSAR major version number is the same between Lin_Cfg.c and Lin.h */
#if (LIN_PBCFG_AR_RELEASE_MAJOR_VERSION    != LIN_H_AR_RELEASE_MAJOR_VERSION)
#error "AUTOSAR major Version Numbers mismatch between Lin_Cfg.c and Lin.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Lin_Cfg.c and Lin.h */
#if (LIN_PBCFG_AR_RELEASE_MINOR_VERSION    != LIN_H_AR_RELEASE_MINOR_VERSION)
#error "AUTOSAR minor Version Numbers mismatch between Lin_Cfg.c and Lin.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Lin_Cfg.c and Lin.h */
#if (LIN_PBCFG_AR_RELEASE_REVISION_VERSION != LIN_H_AR_RELEASE_REVISION_VERSION)
#error "AUTOSAR revision Version Numbers mismatch between Lin_Cfg.c and Lin.h"
#endif

/* Make sure the software major version number is the same between Lin_Cfg.c and Lin.h */
#if (LIN_PBCFG_SW_MAJOR_VERSION != LIN_H_SW_MAJOR_VERSION)
#error "Software major Version Numbers mismatch between Lin_Cfg.c and Lin.h"
#endif
/* Make sure the software minor version number is the same between Lin_Cfg.c and Lin.h */
#if (LIN_PBCFG_SW_MINOR_VERSION != LIN_H_SW_MINOR_VERSION)
#error "Software minor Version Numbers mismatch between Lin_Cfg.c and Lin.h"
#endif
/* Make sure the software patch version number is the same between Lin_Cfg.c and Lin.h */
#if (LIN_PBCFG_SW_PATCH_VERSION != LIN_H_SW_PATCH_VERSION)
#error "Software patch Version Numbers mismatch between Lin_Cfg.c and Lin.h"
#endif

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Lin_Cfg.c and Std_Types.h */
    #if (LIN_PBCFG_AR_RELEASE_MAJOR_VERSION != STD_TYPES_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR minor Version Numbers mismatch between Lin_Cfg.c and Std_Types.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Lin_Cfg.c and Std_Types.h */
    #if (LIN_PBCFG_AR_RELEASE_MINOR_VERSION != STD_TYPES_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR revision Version Numbers mismatch between Lin_Cfg.c and Std_Types.h"
    #endif

    #if (STD_OFF == LIN_DEM_REP_ERR_DIS)
    /* Make sure the AUTOSAR major version number is the same between Lin_Cfg.c and Dem.h */
    #if (LIN_PBCFG_AR_RELEASE_MAJOR_VERSION != DEM_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR major Version Numbers mismatch between Lin_Cfg.c and Dem.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Lin_Cfg.c and Dem.h */
    #if (LIN_PBCFG_AR_RELEASE_MINOR_VERSION != DEM_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR minor Version Numbers mismatch between Lin_Cfg.c and Dem.h"
    #endif
    #endif /* {if (STD_OFF == LIN_DEM_REP_ERR_DIS)} */

#endif  /* ifdef ENABLE_INTERMODULE_MCAL_CHECK */
/**********************************************************************************************************************
                                             GLOBAL VARIABLE
***********************************************************************************************************************/
/** @defgroup LIN_Variable
  @{
*/
#define LIN_START_SEC_CONST_UNSPECIFIED
#include "Lin_MemMap.h"

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

static CONST(Lin_ChStaticConfigType,LIN_CONST) g_staticLinChannel_0Config =
{
    (uint8)0U, LIN_USART2, (uint8)STD_ON, MASTER,
    /* Wakeup Source transmitted to the Ecu State Manager (used only when the Wakeup Support is enabled) */
    (EcuM_WakeupSourceType)((uint32)1U<<(uint32)0U) 
};

static CONST(Lin_ChStaticConfigType,LIN_CONST) g_staticLinChannel_1Config =
{
    (uint8)1U, LIN_USART2, (uint8)STD_ON, SLAVE,
    /* Wakeup Source transmitted to the Ecu State Manager (used only when the Wakeup Support is enabled) */
    (EcuM_WakeupSourceType)((uint32)1U<<(uint32)0U) 
};

/** The configuration of the Lin Channel 0 */
static CONST(Lin_ChConfigType,LIN_CONST) g_LinChannel_0Config =
{
    &g_staticLinChannel_0Config, 19200U
};

/** The configuration of the Lin Channel 1 */
static CONST(Lin_ChConfigType,LIN_CONST) g_LinChannel_1Config =
{
    &g_staticLinChannel_1Config, 19200U
};

CONST(Lin_ConfigType,LIN_CONST)  g_linConfig =
{
    {
        /* The configuration of the Lin Channel 0. */
        &g_LinChannel_0Config,
        /* The configuration of the Lin Channel 1. */
        &g_LinChannel_1Config
    }
};

#define LIN_STOP_SEC_CONST_UNSPECIFIED
#include "Lin_MemMap.h"

#define LIN_START_SEC_VAR_INIT_8
#include "Lin_MemMap.h"

VAR(uint8, LIN_VAR) g_sendBufConfig[3][LIN_SDU_MAX_LEN] =
{
    {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
    {0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18},
    {0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28}
};

#define LIN_STOP_SEC_VAR_INIT_8
#include "Lin_MemMap.h"

/*******************************************************************************
                              GLOBAL VARIABLE
*******************************************************************************/
#define LIN_START_SEC_CONST_32
#include "Lin_MemMap.h"

#ifdef LIN_SLAVE_NODECFG
/** Lin message configured table for Slave node. */
const Lin_MsgType g_linMsgCfgTable[] = 
{
    {LIN_APP_ID_SLAVE_PUBLISH,PARITY_FIELD(LIN_APP_ID_SLAVE_PUBLISH), 8,SLAVE_TO_MASTER},
    
    {LIN_APP_ID_MASTER_PUBLISH,PARITY_FIELD(LIN_APP_ID_MASTER_PUBLISH), 8,MASTER_TO_SLAVE}, 

    {LIN_DIAG_ID_MASTER_REQUEST,PARITY_FIELD(LIN_DIAG_ID_MASTER_REQUEST), 8,MASTER_TO_SLAVE}
};

const uint8_t g_linMsgTblLen = sizeof(g_linMsgCfgTable)/sizeof(g_linMsgCfgTable[0]);

#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"

#ifdef LIN_SLAVE_NODECFG

FUNC (void, LIN_CODE) Lin_PidReceivedNotification(VAR(uint8, AUTOMATIC) Pid, VAR(uint8, AUTOMATIC) FrameIndex)
{
    (void)Pid;
    (void)FrameIndex;
}

FUNC (uint16, LIN_CODE) Lin_GetCurrentSensorValue(void)
{
    return 0;
}

/*!
* @brief         Application layer callback function used to assemble and send data from the node
*
* @param[in]     FrameIdx: Slave message Information List Identification Number
*
* @param[in]     DataBuffer: point to data buffer
*
* @retval        void
*
* @note          None
*/
/*  */
FUNC (void, LIN_CODE) Lin_GetTxDataNotification(VAR(uint8, AUTOMATIC) FrameIdx, P2VAR(uint8, AUTOMATIC, LIN_APPL_DATA) DataBuffer)
{
    VAR(uint16, AUTOMATIC) sensorVal = 0;
    VAR(uint8, AUTOMATIC) i = 0;
    /* 1. Basic logic: look up table and copy data */
    if(FrameIdx < (sizeof(g_sendBufConfig)/sizeof(g_sendBufConfig[0])))
    {
        for(i = 0u; i < 8u; i++)
        {
            DataBuffer[i] = g_sendBufConfig[FrameIdx][i];
        }
    }
    else
    {
        /* nothing */
    }
    /* 2. Extension logic: dynamic data override for specific IDs */
    /* Assume that the frame with FrameIdx equal to 2 is a sensor data frame */
    if (FrameIdx == 3u) 
    {
        sensorVal = Lin_GetCurrentSensorValue();
        /* Dynamically fill the low byte */
        DataBuffer[0] = (uint8)(sensorVal & 0xFFu);
        /* Dynamically fill the high byte */
        DataBuffer[1] = (uint8)((sensorVal >> 8u) & 0xFFu);
    }
    else
    {
        /* nothing */
    }
}
#endif

#define LIN_STOP_SEC_CODE
#include "Lin_MemMap.h"

/**@} end of group LIN_Fuctions */

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