/**
*   @file    Spi_Ipw.c
*   @version 1.0.0
*
*   @brief   AUTOSAR Spi - Isolation level file for SPI driver.
*   @details Implementation file for function definition on isolation level between high and low level driver.
*
*   @addtogroup SPI
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : DSPI
*   Dependencies         : 
*
*   Autosar Version      : 4.3.1
*   Autosar Revision     : ASR_REL_4_3_REV_0001
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : MPC5777C_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190315
*
*   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
*       Copyright 2017-2019 NXP
*   All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct. 
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.2, Identifiers declared in the same scope and name space shall be distinct. 
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct. 
* The used compilers use more than 31 chars for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names.
* The used compilers use more than 31 chars for identifiers.
*
* @section Spi_IPW_c_REF_1
* Violates MISRA 2012 Advisory Rule 20.1, #include directives should only be preceded by preprocessor directives or comments.
* <MA>_MemMap.h is included after each section define in order to set the current memory section as defined by AUTOSAR.
*
* @section Spi_IPW_c_REF_2
* Violates MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being
* included more than once
* This violation is not fixed since the inclusion of <MA>_MemMap.h is as per AUTOSAR requirement [SWS_MemMap_00003].
*
* @section Spi_IPW_c_REF_3
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
* Macros that are used in the code only in some configuration.
*
*/
/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Spi.h"
#include "Spi_IPW.h"

#include "Spi_DSPI.h"

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/*
* @violates @ref Spi_IPW_c_REF_3 A project should not contain unused macro declarations.
* Macros that are used in the code only in some configuration. 
*/
#define SPI_IPW_MODULE_ID_C                     83
#define SPI_IPW_VENDOR_ID_C                     43
#define SPI_IPW_AR_RELEASE_MAJOR_VERSION_C      4
#define SPI_IPW_AR_RELEASE_MINOR_VERSION_C      3
#define SPI_IPW_AR_RELEASE_REVISION_VERSION_C   1
#define SPI_IPW_SW_MAJOR_VERSION_C              1
#define SPI_IPW_SW_MINOR_VERSION_C              0
#define SPI_IPW_SW_PATCH_VERSION_C              0
/*==================================================================================================
*                                      FILE VERSION CHECKS
==================================================================================================*/
/* Check if this file and Spi.h are of the same vendor */
#if (SPI_IPW_VENDOR_ID_C != SPI_VENDOR_ID)
    #error "Spi_IPW.c and Spi.h have different vendor ids"
#endif

/* Check if this header file and Spi_IPW.h are of the same vendor */
#if (SPI_IPW_VENDOR_ID_C != SPI_IPW_VENDOR_ID)
    #error "Spi_IPW.c and Spi_IPW.h have different vendor ids"
#endif

/* Check if this header file and Spi_DSPI.h are of the same vendor */
#if (SPI_IPW_VENDOR_ID_C != SPI_VENDOR_ID_DSPI)
    #error "Spi_IPW.c and Spi_DSPI.h have different vendor ids"
#endif

/* Check if current file and Spi header file are of the same Autosar version */
#if ((SPI_IPW_AR_RELEASE_MAJOR_VERSION_C != SPI_AR_RELEASE_MAJOR_VERSION) || \
     (SPI_IPW_AR_RELEASE_MINOR_VERSION_C != SPI_AR_RELEASE_MINOR_VERSION) || \
     (SPI_IPW_AR_RELEASE_REVISION_VERSION_C != SPI_AR_RELEASE_REVISION_VERSION))
#error "AutoSar Version Numbers of Spi_IPW.c and Spi.h are different"
#endif

  /* Check if current file and Spi header file are of the same Software version */
#if ((SPI_IPW_SW_MAJOR_VERSION_C != SPI_SW_MAJOR_VERSION) || \
     (SPI_IPW_SW_MINOR_VERSION_C != SPI_SW_MINOR_VERSION) || \
     (SPI_IPW_SW_PATCH_VERSION_C != SPI_SW_PATCH_VERSION))
#error "Software Version Numbers of Spi_IPW.c and Spi.h are different"
#endif

/* Check if current file and Spi_IPW header file are of the same Autosar version */
#if ((SPI_IPW_AR_RELEASE_MAJOR_VERSION_C != SPI_IPW_AR_RELEASE_MAJOR_VERSION) || \
     (SPI_IPW_AR_RELEASE_MINOR_VERSION_C != SPI_IPW_AR_RELEASE_MINOR_VERSION) || \
     (SPI_IPW_AR_RELEASE_REVISION_VERSION_C != SPI_IPW_AR_RELEASE_REVISION_VERSION))
#error "AutoSar Version Numbers of Spi_IPW.c and Spi_IPW.h are different"
#endif

  /* Check if current file and Spi_IPW header file are of the same Software version */
#if ((SPI_IPW_SW_MAJOR_VERSION_C != SPI_IPW_SW_MAJOR_VERSION) || \
     (SPI_IPW_SW_MINOR_VERSION_C != SPI_IPW_SW_MINOR_VERSION) || \
     (SPI_IPW_SW_PATCH_VERSION_C != SPI_IPW_SW_PATCH_VERSION))
#error "Software Version Numbers of Spi_IPW.c and Spi_IPW.h are different"
#endif

#if (( SPI_IPW_AR_RELEASE_MAJOR_VERSION_C    != SPI_AR_RELEASE_MAJOR_VERSION_DSPI) || \
     ( SPI_IPW_AR_RELEASE_MINOR_VERSION_C    != SPI_AR_RELEASE_MINOR_VERSION_DSPI) || \
     ( SPI_IPW_AR_RELEASE_REVISION_VERSION_C != SPI_AR_RELEASE_REVISION_VERSION_DSPI))
#error "AutoSar Version Numbers of Spi_IPW.c and Spi_DSPI.h are different"
#endif

#if (( SPI_IPW_SW_MAJOR_VERSION_C != SPI_SW_MAJOR_VERSION_DSPI) || \
     ( SPI_IPW_SW_MINOR_VERSION_C != SPI_SW_MINOR_VERSION_DSPI) || \
     ( SPI_IPW_SW_PATCH_VERSION_C != SPI_SW_PATCH_VERSION_DSPI))
#error "Software Version Numbers of Spi_IPW.c and Spi_DSPI.h are different"
#endif
/*==================================================================================================
*                          LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/

/*==================================================================================================
*                                       LOCAL MACROS
==================================================================================================*/

/*==================================================================================================
*                                       LOCAL CONSTANTS
==================================================================================================*/


/*==================================================================================================
*                                       LOCAL VARIABLES
==================================================================================================*/

/*==================================================================================================
*                                       GLOBAL CONSTANTS
==================================================================================================*/

/*==================================================================================================
*                                       GLOBAL VARIABLES
==================================================================================================*/

/*==================================================================================================
*                                   LOCAL FUNCTION PROTOTYPES
==================================================================================================*/

/*==================================================================================================
*                                       LOCAL FUNCTIONS
==================================================================================================*/

/*==================================================================================================
*                                       GLOBAL FUNCTIONS
==================================================================================================*/

#define SPI_START_SEC_CODE
/*
* @violates @ref Spi_IPW_c_REF_1 #include directives should only be preceded by preprocessor directives or comments.
* <MA>_MemMap.h is included after each section define in order to set the current memory section as defined by AUTOSAR.
*/
/*
* @violates @ref Spi_IPW_c_REF_2 Precautions shall be taken in order to prevent the contents
*        of a header file being included twice.
*/
#include "Spi_MemMap.h"

/* Spi_Ipw_Init */
FUNC(void, SPI_CODE) Spi_Ipw_Init(VAR(Spi_HWUnitType, AUTOMATIC) HWUnit, P2VAR(Spi_StatusType, AUTOMATIC, SPI_APPL_DATA) pStatus)
{
if (Spi_pcSpiConfigPtr->pcHWUnitConfig[HWUnit].u8HWtype == DSPI)
    {
        Spi_Dspi_Init(HWUnit, pStatus);
    }
else
    {
        /* Do nothing */
    }   
}

                        /* Spi_Ipw_DeInit */
FUNC(void, SPI_CODE) Spi_Ipw_DeInit(VAR(Spi_HWUnitType, AUTOMATIC) HWUnit)
{
if (Spi_pcSpiConfigPtr->pcHWUnitConfig[HWUnit].u8HWtype == DSPI)
    {
        Spi_Dspi_DeInit(HWUnit);
    }
else
    {
        /* Do nothing */
    }   
}

                    /* Spi_Ipw_PrepareCacheInformation */
#if (((SPI_LEVEL_DELIVERED == LEVEL2) || (SPI_LEVEL_DELIVERED == LEVEL0)) && \
    (SPI_OPTIMIZE_ONE_JOB_SEQUENCES == STD_ON))
FUNC(void, SPI_CODE) Spi_Ipw_PrepareCacheInformation()
{
    Spi_Dspi_PrepareCacheInformation();
}
#endif  /* #if (((SPI_LEVEL_DELIVERED == LEVEL2) || (SPI_LEVEL_DELIVERED == LEVEL0)) && \
    (SPI_OPTIMIZE_ONE_JOB_SEQUENCES == STD_ON))*/

                        /* Spi_Ipw_SyncTransmit */
#if ( (SPI_LEVEL_DELIVERED == LEVEL2) || (SPI_LEVEL_DELIVERED == LEVEL0) )
FUNC(Std_ReturnType, SPI_CODE) Spi_Ipw_SyncTransmit(VAR(Spi_SequenceType, AUTOMATIC) Sequence)
{
#if (SPI_OPTIMIZE_ONE_JOB_SEQUENCES == STD_ON)
    P2CONST(Spi_Dspi_SequenceCacheAttrsType, AUTOMATIC, SPI_APPL_CONST) pDspiSequenceCache;
    VAR(Spi_JobType, AUTOMATIC) Ipw_Job;
    P2CONST(Spi_SequenceConfigType, AUTOMATIC, SPI_APPL_CONST) Ipw_pcSequenceConfig;
    P2CONST(Spi_JobConfigType, AUTOMATIC, SPI_APPL_CONST) Ipw_pcJobConfig;
#endif  
VAR(Std_ReturnType, AUTOMATIC) Ipw_Status = (Std_ReturnType)E_NOT_OK;
if (Spi_pcSpiConfigPtr->pcSequenceConfig[Sequence].u8HWtypeOfSequence == DSPI)
{
#if (SPI_OPTIMIZE_ONE_JOB_SEQUENCES == STD_ON)
    pDspiSequenceCache = Spi_Dspi_apOneJobSeqsOptimized[Sequence];
    if (NULL_PTR != pDspiSequenceCache)
    {
        Ipw_pcSequenceConfig = &Spi_pcSpiConfigPtr->pcSequenceConfig[Sequence];
        /* Get the job id */
        Ipw_Job = Ipw_pcSequenceConfig->pcJobIndexList[0];
        Ipw_pcJobConfig = &Spi_pcSpiConfigPtr->pcJobConfig[Ipw_Job];
        /* start job notification to assert the non-cs pin,
                when non-cs pin is used as chipselect*/
        if (NULL_PTR != Ipw_pcJobConfig->pfStartNotification)
        {
            Ipw_pcJobConfig->pfStartNotification();
        }
        else
        {
            /* Do nothing */
        }
        Ipw_Status = Spi_Dspi_SyncTransmit_Fast(pDspiSequenceCache);
        /* end job notification to assert the non-cs pin,
        when non-cs pin is used as chipselect*/
        if (NULL_PTR != Ipw_pcJobConfig->pfEndNotification)
        {
            Ipw_pcJobConfig->pfEndNotification();
        }
        else
        {
            /* Do nothing */
        }
    }
    else
    {
        Ipw_Status = Spi_Dspi_SyncTransmit(Sequence);
    }
#else
    Ipw_Status = Spi_Dspi_SyncTransmit(Sequence);
#endif
}
else
{
    /* Do nothing */
}
return Ipw_Status;    
}
#endif /* #if ( (SPI_LEVEL_DELIVERED == LEVEL2) || (SPI_LEVEL_DELIVERED == LEVEL0) ) */

                    /* Spi_Ipw_JobTransfer */
#if ((SPI_LEVEL_DELIVERED == LEVEL1) || (SPI_LEVEL_DELIVERED == LEVEL2))
FUNC(void, SPI_CODE) Spi_Ipw_JobTransfer(P2CONST(Spi_JobConfigType, AUTOMATIC, SPI_APPL_CONST) pcJobConfig)
{
if (Spi_pcSpiConfigPtr->pcHWUnitConfig[pcJobConfig->HWUnit].u8HWtype == DSPI)
    {
        Spi_Dspi_JobTransfer(pcJobConfig);
    }
else
    {
        /* Do nothing */
    }   
} 
#endif

#if ((SPI_LEVEL_DELIVERED == LEVEL1) || (SPI_LEVEL_DELIVERED == LEVEL2))  
    
                    /* Spi_Ipw_IrqConfig */
FUNC(void, SPI_CODE) Spi_Ipw_IrqConfig(VAR(Spi_HWUnitType, AUTOMATIC) HWUnit, VAR(Spi_AsyncModeType, AUTOMATIC) AsyncMode)
{
if (Spi_pcSpiConfigPtr->pcHWUnitConfig[HWUnit].u8HWtype == DSPI)
    {
        Spi_Dspi_IrqConfig(HWUnit, AsyncMode);
    }
else
    {
        /* Do nothing */
    }   
}
#endif

#if ((SPI_LEVEL_DELIVERED == LEVEL1) || (SPI_LEVEL_DELIVERED == LEVEL2))
                    /* Spi_Ipw_IrqPoll */
FUNC(void, SPI_CODE) Spi_Ipw_IrqPoll(VAR(Spi_HWUnitType, AUTOMATIC) HWUnit)
{
if (Spi_pcSpiConfigPtr->pcHWUnitConfig[HWUnit].u8HWtype == DSPI)
    {
        Spi_Dspi_IrqPoll(HWUnit);
    }
else
    {
        /* Do nothing */
    }
}
#endif

                    /* Spi_Ipw_SlaveCancel */
#if ((SPI_CANCEL_API == STD_ON) && (SPI_SLAVE_SUPPORT == STD_ON))
FUNC(void, SPI_CODE) Spi_Ipw_SlaveCancel(VAR(Spi_SequenceType, AUTOMATIC) Sequence)
{
if (Spi_pcSpiConfigPtr->pcSequenceConfig[Sequence].u8HWtypeOfSequence == DSPI)
    {
        Spi_Dspi_SlaveCancel(Sequence);
    }
else
    {
        /* Do nothing */
    }
}
#endif /* #if ((SPI_CANCEL_API == STD_ON) && (SPI_SLAVE_SUPPORT == STD_ON)) */

#ifdef TSB_MODE_SUPPORTED
#if (SPI_TSB_MODE == STD_ON)
FUNC(void, SPI_CODE) Spi_Ipw_SetTSBMode(VAR(Spi_JobType, AUTOMATIC) TSBJob)
{
    if(Spi_pcSpiConfigPtr->pcSequenceConfig[TSBJob].u8HWtypeOfSequence == DSPI)
    {
        Spi_Dspi_SetTSBMode(TSBJob);
    }
    else
    {
        /* Do nothing */ }
    }

FUNC(void, SPI_CODE) Spi_Ipw_StopTSBMode(VAR(Spi_JobType, AUTOMATIC) TSBJob)
{
    if(Spi_pcSpiConfigPtr->pcSequenceConfig[TSBJob].u8HWtypeOfSequence == DSPI)
    {
        Spi_Dspi_StopTSBMode(TSBJob);
    }
    else
    {
        /* Do nothing */
    }
}

FUNC(void, SPI_CODE) Spi_Ipw_TSB_ASDR_DataUpdate(VAR(Spi_JobType, AUTOMATIC)TSBJob,P2CONST(uint32, AUTOMATIC,SPI_APPL_DATA) ASDR_Data)
{
    if(Spi_pcSpiConfigPtr->pcSequenceConfig[TSBJob].u8HWtypeOfSequence == DSPI)
    { 
        Spi_Dspi_TSB_ASDR_DataUpdate(TSBJob, ASDR_Data);
    }
    else
    {
        /* Do nothing */
    }
}
#endif
#endif/* #ifdef TSB_MODE_SUPPORTED */

#define SPI_STOP_SEC_CODE
/*
* @violates @ref Spi_IPW_c_REF_1 #include directives should only be preceded by preprocessor directives or comments.
* <MA>_MemMap.h is included after each section define in order to set the current memory section as defined by AUTOSAR.
*/
/*
* @violates @ref Spi_IPW_c_REF_2 Precautions shall be taken in order to prevent the contents
*        of a header file being included twice.
*/
#include "Spi_MemMap.h"

#ifdef __cplusplus
}
#endif
/** @} */
