/*!
* @file     Spi_PBcfg.c
*
* @version  1.0.0
*
* @brief    Code file of AUTOSAR SPI driver parameter configuration(Pre-compile).
*           This file contains the used configuration parameters generated by EB tresos studio 
* @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

#include "Spi.h"
#include "Spi_Reg.h"


#if (STD_ON == SPI_DMA_SUPPORT)
#include "Pdl_DmaTypes.h"
#endif

#if (STD_OFF == SPI_DEM_EVENT_ERROR_REPORT_DISABLED)
#include "Dem.h"
#endif

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup SPI_Driver
  * @brief SPI driver modules
  @{
*/

/** @defgroup SPI_Macros
  @{
*/
/**************************************************************************
                  VENDOR ID & AUTOSAR VERSION INFO
**************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define SPI_PBCFG_VENDOR_ID                        0x00C1U
/** Module ID of this module, as defined in the BSW Module List [1]. */
#define SPI_PBCFG_MODULE_ID                        0x53U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define SPI_PBCFG_AR_RELEASE_MAJOR_VERSION         0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define SPI_PBCFG_AR_RELEASE_MINOR_VERSION         0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define SPI_PBCFG_AR_RELEASE_REVISION_VERSION      0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define SPI_PBCFG_SW_MAJOR_VERSION                 0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define SPI_PBCFG_SW_MINOR_VERSION                 0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define SPI_PBCFG_SW_PATCH_VERSION                 0x00U
/**@} end of group SPI_Macros */
/**************************************************************************
                    LOCAL VARIABLE
**************************************************************************/
/** @defgroup SPI_Variable
  @{
*/
#if ((STD_ON == SPI_DMA_SUPPORT) && (LEVEL0 != SPI_LEVEL_DELIVERED))
    #define SPI_START_SEC_VAR_NO_INIT_UNSPECIFIED_NO_CACHEABLE
#else
    #define SPI_START_SEC_VAR_NO_INIT_UNSPECIFIED
#endif 
#include "Spi_MemMap.h"

/** EB channel buffers Descriptors information */
/** Config IB Channels Buffers */
static VAR(Spi_DataBufferType, SPI_VAR) TxBufferInfo_SpiChannel_0[SPI_TRANS_ONCE_LENGTH];
static VAR(Spi_DataBufferType, SPI_VAR) RxBufferInfo_SpiChannel_0[SPI_TRANS_ONCE_LENGTH];
/** Config IB Channels Buffers */
static VAR(Spi_DataBufferType, SPI_VAR) TxBufferInfo_SpiChannel_1[SPI_TRANS_ONCE_LENGTH];
static VAR(Spi_DataBufferType, SPI_VAR) RxBufferInfo_SpiChannel_1[SPI_TRANS_ONCE_LENGTH];
/** Config IB Channels Buffers */
static VAR(Spi_DataBufferType, SPI_VAR) TxBufferInfo_SpiChannel_2[SPI_TRANS_ONCE_LENGTH];
static VAR(Spi_DataBufferType, SPI_VAR) RxBufferInfo_SpiChannel_2[SPI_TRANS_ONCE_LENGTH];

#if ((STD_ON == SPI_DMA_SUPPORT) && (LEVEL0 != SPI_LEVEL_DELIVERED))  
    #define SPI_STOP_SEC_VAR_NO_INIT_UNSPECIFIED_NO_CACHEABLE
#else
    #define SPI_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#endif 
#include "Spi_MemMap.h"

#define SPI_START_SEC_VAR_INIT_UNSPECIFIED
#include "Spi_MemMap.h"

/** IB channel buffers Descriptors information */
static VAR(Spi_BufferDescriptorType, SPI_VAR) BufferInfo_SpiChannel_0 =
{
    TxBufferInfo_SpiChannel_0,
    RxBufferInfo_SpiChannel_0
}; 
static VAR(Spi_BufferDescriptorType, SPI_VAR) BufferInfo_SpiChannel_1 =
{
    TxBufferInfo_SpiChannel_1,
    RxBufferInfo_SpiChannel_1
}; 
static VAR(Spi_BufferDescriptorType, SPI_VAR) BufferInfo_SpiChannel_2 =
{
    TxBufferInfo_SpiChannel_2,
    RxBufferInfo_SpiChannel_2
}; 

/** Spi External Device Attribute Configuration of SPI */
static VAR(Spi_DeviceAttrCfgType, SPI_VAR) Spi_PBLpDevAttrCfg[1] =
{
#if (SPI_SLAVE_SUPPORT == STD_ON)
    /** SpiExternalDevice_0 Slave */
    {
        (uint32)(SPI_CTRL1_CPHA_TRAILING | 
                 SPI_CTRL1_CPOL_LOW |
                 SPI_CTRL1_MSMCFG_SLAVE |
                 SPI_CTRL1_BRSEL_64 |
                 SPI_CTRL1_SPIEN_ENABLE |
                 SPI_CTRL1_LSBSEL_MSB |
                 SPI_CTRL1_ISSEL_DISABLE |
                 SPI_CTRL1_SSEN_DEFAULT |
                 SPI_CTRL1_RXOMEN_DEFAULT |
                 SPI_CTRL1_CRCLSE_DEFAULT |
                 SPI_CTRL1_CRCNXT_DEFAULT |
                 SPI_CTRL1_CRCEN_DEFAULT |
                 SPI_CTRL1_BMOEN_DEFAULT |
                 SPI_CTRL1_BMEN_DEFAULT
                ) & SPI_CTRL1_BITS_MASK,
        (uint32)(SPI_CTRL2_LDTX_DEFAULT |
                 SPI_CTRL2_LDRX_DEFAULT |
             #if (SPI_DATASIZE_CONFIG_8 == STD_ON)
                 SPI_CTRL2_FRTCFG_8 |
                 SPI_CTRL2_DSCFG_8 |
             #else
                 SPI_CTRL2_FRTCFG_16 |
                 SPI_CTRL2_DSCFG_16 |
             #endif
                 SPI_CTRL2_TXBEIEN_DEFAULT |
                 SPI_CTRL2_RXBNEIEN_DEFAULT |
                 SPI_CTRL2_ERRIEN_DEFAULT |
                 SPI_CTRL2_FRFCFG_DEFAULT |
                 SPI_CTRL2_NSSPEN_DEFAULT |
                 SPI_CTRL2_SSOEN_ENABLE |
                 SPI_CTRL2_TXDEN_DEFAULT |
                 SPI_CTRL2_RXDEN_DEFAULT
                ) & SPI_CTRL2_BITS_MASK,
        (uint32)(SPI_CRCPOLY_DEFAULT) &  SPI_CRCPOLY_BITS_MASK
    }
#else
    /** SpiExternalDevice_1 Master */
    {
        (uint32)(SPI_CTRL1_CPHA_TRAILING |
                 SPI_CTRL1_CPOL_LOW |
                 SPI_CTRL1_MSMCFG_MASTER |
                 SPI_CTRL1_BRSEL_64 |
                 SPI_CTRL1_SPIEN_ENABLE |
                 SPI_CTRL1_LSBSEL_MSB |
                 SPI_CTRL1_ISSEL_ENABLE |
                 SPI_CTRL1_SSEN_DEFAULT |
                 SPI_CTRL1_RXOMEN_DEFAULT |
                 SPI_CTRL1_CRCLSE_DEFAULT |
                 SPI_CTRL1_CRCNXT_DEFAULT |
                 SPI_CTRL1_CRCEN_DEFAULT |
                 SPI_CTRL1_BMOEN_DEFAULT |
                 SPI_CTRL1_BMEN_DEFAULT
                ) & SPI_CTRL1_BITS_MASK,
        (uint32)(SPI_CTRL2_LDTX_DEFAULT |
                 SPI_CTRL2_LDRX_DEFAULT |
             #if (SPI_DATASIZE_CONFIG_8 == STD_ON)
                 SPI_CTRL2_FRTCFG_8 |
                 SPI_CTRL2_DSCFG_8 |
             #else
                 SPI_CTRL2_FRTCFG_16 |
                 SPI_CTRL2_DSCFG_16 |
             #endif
                 SPI_CTRL2_TXBEIEN_DEFAULT |
                 SPI_CTRL2_RXBNEIEN_DEFAULT |
                 SPI_CTRL2_ERRIEN_DEFAULT |
                 SPI_CTRL2_FRFCFG_DEFAULT |
                 SPI_CTRL2_NSSPEN_DEFAULT |
                 SPI_CTRL2_SSOEN_ENABLE |
                 SPI_CTRL2_TXDEN_DEFAULT |
                 SPI_CTRL2_RXDEN_DEFAULT
                ) & SPI_CTRL2_BITS_MASK,
        (uint32)(SPI_CRCPOLY_DEFAULT) &  SPI_CRCPOLY_BITS_MASK
    }
#endif
};

#define SPI_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Spi_MemMap.h"

/**************************************************************************
                    CONSTANT DEFINITION
**************************************************************************/
#define SPI_START_SEC_VAR_INIT_UNSPECIFIED
#include "Spi_MemMap.h"
    
/** Spi Device Attribute Configuration list of SPI */
static P2CONST(Spi_DeviceAttrCfgType, SPI_VAR, SPI_APPL_CONST) Spi_PBLpDevAttrCfgList[1] =
{
    &Spi_PBLpDevAttrCfg[0]
};

#define SPI_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Spi_MemMap.h"

#define SPI_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "Spi_MemMap.h"

/** Spi External Device Attribute Configuration */
static CONST(Spi_ExtDeviceAttrCfgType, SPI_VAR) Spi_PBExtDeviceAttrCfg[1] =
{
    {
        &Spi_PBLpDevAttrCfgList[SPI_EXTERNALDEVICE_0],
    }
};

 /** Spi Channel Configuration */
static CONST(Spi_ChannelConfigType, SPI_CONST) Spi_PBChannelConfig[3] =
{
    {
        /** SpiChannel_0 */
        IB,
        (uint32)10U,
        SPI_TRANS_ONCE_LENGTH,
        &BufferInfo_SpiChannel_0,
        &g_spiChannelState[0]
    },
    {
        /** SpiChannel_1 */
        IB,
        (uint32)10U,
        SPI_TRANS_ONCE_LENGTH,
        &BufferInfo_SpiChannel_1,
        &g_spiChannelState[1]
    },
    {
        /** SpiChannel_2 */
        IB,
        (uint32)10U,
        SPI_TRANS_ONCE_LENGTH,
        &BufferInfo_SpiChannel_2,
        &g_spiChannelState[2]
    }
};

/** Channel configuration to Job */
static CONST(Spi_ChannelType, SPI_CONST) SpiJob_0_PBChannelConfig[1] = {SPI_CHANNELCFG_0};

/** Spi Job Configuration */
static CONST(Spi_JobConfigType, SPI_CONST) Spi_PBJobConfig[SPI_JOBCFG_NUM] =
{
    {
        /** SpiJob_0 */
        (Spi_ChannelType)1u, //!< Channels number in job
        SpiJob_0_PBChannelConfig, //!< Channel list
        &Spi_Job0_End_Notification, //!<  End Notification api
        &Spi_Job0_Start_Notification, //!< Start Notification api
        (sint8)0, //!< Job Priority 
        &g_spiJobState[0], //!< Job State  
        SPI0, //!< HWUnit index 
        SPI_0_OFFSET_CFG, //!< SPI HWUnit offset 
        /** External Device config */
        SPI_EXTERNALDEVICE_0, //!< External Device name 
        &Spi_PBExtDeviceAttrCfg[SPI_EXTERNALDEVICE_0] //!< External Device Attributes Config 
    }
};

/** Job configuration to Sequence */
static CONST(Spi_JobType, SPI_CONST) SpiSequence_0_PBJobConfig[1] = {SPI_JOBCFG_0};

/** Spi Sequence Configuration */
static CONST(Spi_SeqCfgType, SPI_CONST) Spi_PBSequenceConfig[1] =
{
    {  
        /** SpiSequence_0 */
        (Spi_JobType)1u, //!< Jobs number in sequence
        SpiSequence_0_PBJobConfig, //!< Jobs list 
        &Spi_Seq0_End_Notification, //!< End Notification api  
        (uint8)TRUE //!< the Sequence use as interruptible or not
    }
};

/** Spi Channel Attribute Configuration of SPI */
static CONST(Spi_ChannelAttrCfgType, SPI_CONST) Spi_PBLpChannelAttrCfg[3] =
{
    {   /** channel 0 */ 
        (uint32)(SPI_CTRL1_LSBSEL_MSB), //!< SPI_CTRL1 register attribution
    #if (SPI_DATASIZE_CONFIG_8 == STD_ON)
        (uint32)(SPI_CTRL2_FRTCFG_8 | SPI_CTRL2_DSCFG_8), //!< SPI_CTRL2 register attribution
        SPI_ACCESS_DATATYPE_8 //!< SpiDataWidthType as uint8 
    #else
        (uint32)(SPI_CTRL2_FRTCFG_16 | SPI_CTRL2_DSCFG_16), //!< SPI_CTRL2 register attribution
        SPI_ACCESS_DATATYPE_16 //!< SpiDataWidthType as uint16 
    #endif
    },
    {   /** channel 1 */ 
        (uint32)(SPI_CTRL1_LSBSEL_MSB), //!< SPI_CTRL1 register attribution
    #if (SPI_DATASIZE_CONFIG_8 == STD_ON)
        (uint32)(SPI_CTRL2_FRTCFG_8 | SPI_CTRL2_DSCFG_8), //!< SPI_CTRL2 register attribution
        SPI_ACCESS_DATATYPE_8 //!< SpiDataWidthType as uint8 
    #else
        (uint32)(SPI_CTRL2_FRTCFG_16 | SPI_CTRL2_DSCFG_16), //!< SPI_CTRL2 register attribution
        SPI_ACCESS_DATATYPE_16 //!< SpiDataWidthType as uint16 
    #endif
    },
    {   /** channel 2 */ 
        (uint32)(SPI_CTRL1_LSBSEL_MSB), //!< SPI_CTRL1 register attribution
    #if (SPI_DATASIZE_CONFIG_8 == STD_ON)
        (uint32)(SPI_CTRL2_FRTCFG_8 | SPI_CTRL2_DSCFG_8), //!< SPI_CTRL2 register attribution
        SPI_ACCESS_DATATYPE_8 //!< SpiDataWidthType as uint8 
    #else
        (uint32)(SPI_CTRL2_FRTCFG_16 | SPI_CTRL2_DSCFG_16), //!< SPI_CTRL2 register attribution
        SPI_ACCESS_DATATYPE_16 //!< SpiDataWidthType as uint16 
    #endif
    }
};

/** Spi Attribute Configuration */
static CONST(Spi_AttrCfgType, SPI_CONST) Spi_PBAttrCfg = 
{
    Spi_PBLpChannelAttrCfg,
    Spi_PBLpDevAttrCfgList
};

/** Spi HWUnit configurations information list */
static CONST(Spi_HWUnitConfigType, SPI_CONST) Spi_PBHwUnitCfg[SPI_HWUNITCFG_NUM] =
{
    {
        SPI_0_OFFSET_CFG,
        (uint8)0u,
    #if (SPI_MASTER_SUPPORT == STD_ON)
        SPI_MASTER, 
    #else
        SPI_SLAVE, 
    #endif
    #if (SPI_ASYNC_MODE_ENABLE == STD_ON)
        SPI_PHYUNIT_ASYNC_U32,
    #else
        SPI_PHYUNIT_SYNC_U32,
    #endif
    #if (LEVEL0 != SPI_LEVEL_DELIVERED)
        #if (STD_ON == SPI_DMA_SUPPORT)
            (uint16)TRUE,
            DMA_HW_CH3,
            DMA_HW_CH2,
        #endif
    #endif
    }
};

/**************************************************************************
                   GLOBAL CONSTANT DEFINITION
**************************************************************************/
/** Spi Configuration */
CONST(Spi_ConfigType, SPI_CONST) g_spiConfig =
{
    1u,
    2u,
    0u,
    0u,
    Spi_PBChannelConfig,
    Spi_PBJobConfig,
    Spi_PBSequenceConfig,
    &Spi_PBAttrCfg,
    Spi_PBHwUnitCfg,
    /** DEM Event parameters */
#if (STD_OFF == SPI_DEM_EVENT_ERROR_REPORT_DISABLED)
    { 
        /** SPI_E_HARDWARE_ERROR parameters */
        (uint32)STD_ON, 
        (uint32)DemConfigSet_DemEventParameter_0
    }, 
    { 
        /** SPI_E_TIMEOUT_ERROR parameters */
        (uint32)STD_ON, 
        (uint32)DemConfigSet_DemEventParameter_1
    }, 
#endif 
};

#define SPI_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "Spi_MemMap.h"
/**@} end of group SPI_Variable */
/**************************************************************************
                    GLOBAL FUNCTION
**************************************************************************/
/** @defgroup SPI_Fuctions
  @{
*/
#define SPI_START_SEC_CODE
#include "Spi_MemMap.h"
/*!
* @brief    Use for record the sequences transmission is end.
* 
* @param    None
*
* @retval   None
*
* @note   Non-AUTOSAR support function
*/
void Spi_Seq0_End_Notification(void)
{

}

/*!
* @brief    Use for record the jobs transmission is start.
* 
* @param    None
*
* @retval   None
*
* @note   Non-AUTOSAR support function
*/
void Spi_Job0_Start_Notification(void)
{

}

/*!
* @brief    Use for record the jobs transmission is end.
* 
* @param    None
*
* @retval   None
*
* @note   Non-AUTOSAR support function
*/
void Spi_Job0_End_Notification(void)
{

}

#define SPI_STOP_SEC_CODE
/** @warning Spi_Cfg_c_MISRA_REF1 Use of #include directive after code fragment. */
#include "Spi_MemMap.h"

/**@} end of group SPI_Fuctions */
#ifdef __cplusplus
}
#endif

/**@} end of group SPI_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
