/*==================================================================================================
*   Project              : RTD AUTOSAR 4.9
*   Platform             : CORTEXM
*   Peripheral           : FS26
*   Dependencies         :
*
*   Autosar Version      : 4.9.0
*   Autosar Revision     : ASR_REL_4_9_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 6.0.0
*   Build Version        : S32K3_RTD_6_0_0_D2511_ASR_REL_4_9_REV_0000_20251114
*
*   Copyright 2020 - 2025 NXP
*
*   NXP Confidential and Proprietary. This software is owned or controlled by NXP and may only be
*   used strictly in accordance with the applicable license terms. By expressly
*   accepting such terms or by downloading, installing, activating and/or otherwise
*   using the software, you are agreeing that you have read, and that you agree to
*   comply with and are bound by, such license terms. If you do not agree to be
*   bound by the applicable license terms, then you may not retain, install,
*   activate or otherwise use the software.
==================================================================================================*/

#ifndef SBC_FS26_SPI_EXTERNAL_ACCESS_H
#define SBC_FS26_SPI_EXTERNAL_ACCESS_H

/**
*   @file Sbc_fs26_spi_external_access.h
*
*   @addtogroup spi_external_access
*   @{
*/

#if defined (__cplusplus)
extern "C" {
#endif

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "StandardTypes.h"
#include "CDD_Sbc_fs26_Cfg.h" /* Includes driver specific Ip Cfg file. This file defines then macro which says if HLD or IP layer is used. */
#ifdef SBC_FS26_SPI_USED
    #if defined(SBC_FS26_USE_IPV_DSPI)
        #include "Dspi_Ip.h"
    #elif defined(SBC_FS26_USE_IPV_SPI)
        #include "Spi_Ip.h"
    #elif defined(SBC_FS26_USE_IPV_LPSPI)
        #include "Lpspi_Ip.h"
    #elif defined(SBC_FS26_USE_IPV_FLEXIO_SPI)
        #include "Flexio_Spi_Ip.h"
    #else
        #include "Spi.h"
    #endif

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define SBC_FS26_SPI_EXTERNAL_ACCESS_VENDOR_ID                      43
#define SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION       4
#define SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION       9
#define SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_REVISION_VERSION    0
#define SBC_FS26_SPI_EXTERNAL_ACCESS_SW_MAJOR_VERSION               6
#define SBC_FS26_SPI_EXTERNAL_ACCESS_SW_MINOR_VERSION               0
#define SBC_FS26_SPI_EXTERNAL_ACCESS_SW_PATCH_VERSION               0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Checks against StandardTypes.h */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if (( SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION    != STD_AR_RELEASE_MAJOR_VERSION    ) || \
     ( SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION    != STD_AR_RELEASE_MINOR_VERSION    ) || \
     ( SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_REVISION_VERSION != STD_AR_RELEASE_REVISION_VERSION ))
     #error "AUTOSAR Version Numbers of Spi External Access header file and StandardTypes.h are different"
#endif
#endif

#ifdef SBC_FS26_USE_IPV_DSPI
/* Check if current file and Spi_Ip header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != SPI_IP_AR_RELEASE_MAJOR_VERSION) || \
     (SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION != SPI_IP_AR_RELEASE_MINOR_VERSION) \
    )
#error "AutoSar Version Numbers of Spi External Access header file and Spi_Ip.h are different"
#endif
#endif
#elif defined(SBC_FS26_USE_IPV_LPSPI)
/* Check if current file and Lpspi_Ip header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != LPSPI_IP_AR_RELEASE_MAJOR_VERSION) || \
     (SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION != LPSPI_IP_AR_RELEASE_MINOR_VERSION) \
    )
#error "AutoSar Version Numbers of Spi External Access header file and Lpspi_Ip.h are different"
#endif
#endif
#elif defined(SBC_FS26_USE_IPV_FLEXIO_SPI)
/* Check if current file and Flexio_Spi_Ip header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != FLEXIO_SPI_IP_AR_RELEASE_MAJOR_VERSION) || \
     (SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION != FLEXIO_SPI_IP_AR_RELEASE_MINOR_VERSION) \
    )
#error "AutoSar Version Numbers of Spi External Access header file and Flexio_Spi_Ip.h are different"
#endif
#endif
#elif defined(SBC_FS26_USE_IPV_SPI)
/* Check if current file and Spi_Ip header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != SPI_IP_AR_RELEASE_MAJOR_VERSION) || \
     (SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION != SPI_IP_AR_RELEASE_MINOR_VERSION) \
    )
#error "AutoSar Version Numbers of Spi External Access header file and Spi_Ip.h are different"
#endif
#endif
#else
/* Check if current file and Spi header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != SPI_AR_RELEASE_MAJOR_VERSION) || \
     (SBC_FS26_SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION != SPI_AR_RELEASE_MINOR_VERSION) \
    )
#error "AutoSar Version Numbers of Spi External Access header file and Spi.h are different"
#endif
#endif
#endif

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

/*==================================================================================================
                                       DEFINES AND MACROS
==================================================================================================*/

/*==================================================================================================
                                             ENUMS
==================================================================================================*/
#ifndef SBC_FS26_SYNC_TRANSMIT
typedef enum
{
    SPI_TRANS_OK = 0,
    SPI_TRANS_PENDING,
    SPI_TRANS_FAILED,
}Sbc_fs26_SpiStatusType;
#endif
/*==================================================================================================
                                 STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
typedef struct
{
    /* SPI sync/async transmission */
    boolean SyncTransmit;
    /* SPI External Device (non-AUTOSAR) / SPI sequence (AUTOSAR) */
#ifdef SBC_FS26_USE_IPV_DSPI
    const Dspi_Ip_ExternalDeviceType * Extension;
    Dspi_Ip_CallbackType Callback;
#elif defined(SBC_FS26_USE_IPV_SPI)
    const Spi_Ip_ExternalDeviceType * Extension;
    Spi_Ip_CallbackType Callback
#elif defined(SBC_FS26_USE_IPV_LPSPI)
    const Lpspi_Ip_ExternalDeviceType * Extension;
    Lpspi_Ip_CallbackType Callback;
#elif defined(SBC_FS26_USE_IPV_FLEXIO_SPI)
    const Flexio_Spi_Ip_ExternalDeviceType * Extension;
    Flexio_Spi_Ip_CallbackType Callback;
#else
    /* SPI channel (AUTOSAR) */
    Spi_ChannelType Spi;
    const Spi_SequenceType * Extension;
#endif
    /* SPI buffer size */
    uint16 NumberOfBytes;
    /* SPI Timeout */
    uint32 Timeout;
} Sbc_fs26_SpiSetupType;

/*==================================================================================================
                                 GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/

/*==================================================================================================
*                                       FUNCTION PROTOTYPES
==================================================================================================*/
#define SBC_FS26_START_SEC_CODE
#include "Sbc_fs26_MemMap.h"
/*!
 * @brief SPI transfer.
 *
 * This function Setup transmit/receive buffer of SPI master.
 *
 * @param[in] pSpiSetup      SPI interface setup
 * @param[in] pTxBuffer      SPI Tx buffer
 * @param[out] pRxBuffer     SPI Rx buffer
 *
 * @return Std_ReturnType    Return E_NOT_OK in case buffer preparation failed. Otherwise return E_OK.
 */
extern Std_ReturnType Sbc_fs26_SpiPrepareBuffer(const Sbc_fs26_SpiSetupType * pSpiSetup, const uint8 * pTxBuffer, uint8 * pRxBuffer);

/*!
 * @brief SPI transfer.
 *
 * This function transfers data via SPI.
 *
 * @param[in] pSpiSetup      SPI interface setup
 * @param[in] pTxBuffer      SPI Tx buffer
 * @param[out] pRxBuffer     SPI Rx buffer
 *
 * @return Std_ReturnType    Return E_NOT_OK in case spi transfer failed. Otherwise return E_OK.
 */
extern Std_ReturnType Sbc_fs26_SpiTransferExternal(const Sbc_fs26_SpiSetupType * pSpiSetup, const uint8 * pTxBuffer, uint8 * pRxBuffer);

#ifndef SBC_FS26_SYNC_TRANSMIT
/*!
 * @brief Get the hardware SPI transmission status
 *
 * This function returns the SPI transmission status.
 * @param[in] pSpiSetup      SPI interface setup
 * @return                   SPI transmission status.
 *
 */
extern Sbc_fs26_SpiStatusType Sbc_fs26_GetTransmissionStatus(const Sbc_fs26_SpiSetupType *pSpiSetup);
#endif

#define SBC_FS26_STOP_SEC_CODE
#include "Sbc_fs26_MemMap.h"

#endif /* SBC_FS26_SPI_USED */
#if defined(__cplusplus)
}
#endif

/** @}*/

#endif  /* SBC_FS26_SPI_EXTERNAL_ACCESS_H */
