/*==================================================================================================
*   Project              : RTD AUTOSAR 4.4
*   Platform             : CORTEXM
*   Peripheral           : 
*   Dependencies         : 
*
*   Autosar Version      : 4.4.0
*   Autosar Revision     : ASR_REL_4_4_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 1.0.0
*   Build Version        : S32K3_RTD_1_0_0_D2209_ASR_REL_4_4_REV_0000_20220916
*
*   (c) Copyright 2020 - 2022 NXP Semiconductors
*   All Rights Reserved.
*
*   NXP Confidential. 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 SPI_EXTERNAL_ACCESS_H
#define SPI_EXTERNAL_ACCESS_H

/**
*   @file
*
*   @addtogroup switch_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"
#ifdef USE_IPV_DSPI
#include "Spi_Ip.h"
#elif defined(USE_IPV_LPSPI)
#include "Lpspi_Ip.h"
#else
#include "Spi.h"
#include "CDD_Sbc_fs26_Cfg.h"
#endif

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define SPI_EXTERNAL_ACCESS_VENDOR_ID                      43
#define SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION       4
#define SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION       4
#define SPI_EXTERNAL_ACCESS_AR_RELEASE_REVISION_VERSION    0
#define SPI_EXTERNAL_ACCESS_SW_MAJOR_VERSION               1
#define SPI_EXTERNAL_ACCESS_SW_MINOR_VERSION               0
#define SPI_EXTERNAL_ACCESS_SW_PATCH_VERSION               0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Checks against StandardTypes.h */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if (( SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION    != STD_AR_RELEASE_MAJOR_VERSION    ) || \
     ( SPI_EXTERNAL_ACCESS_AR_RELEASE_MINOR_VERSION    != STD_AR_RELEASE_MINOR_VERSION    ) || \
     ( 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 USE_IPV_DSPI
/* Check if current file and Spi_Ip header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != SPI_IP_AR_RELEASE_MAJOR_VERSION) || \
     (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(USE_IPV_LPSPI)
/* Check if current file and Lpspi_Ip header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != LPSPI_IP_AR_RELEASE_MAJOR_VERSION) || \
     (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
#else
/* Check if current file and Spi header file are of the same version */
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
#if ((SPI_EXTERNAL_ACCESS_AR_RELEASE_MAJOR_VERSION != SPI_AR_RELEASE_MAJOR_VERSION) || \
     (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
==================================================================================================*/

/*==================================================================================================
                                 STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
typedef struct
{
    /* SPI instance (non-AUTOSAR) / SPI channel (AUTOSAR) */
    uint32 spi;
    /* SPI sync/async transmission */
    boolean syncTransmit;
    /* SPI External Device (non-AUTOSAR) / SPI sequence (AUTOSAR) */
    const void *extension;
    /* SPI buffer size */
    uint16 numberOfBytes;
    /* SPI timeout */
    uint32 timeout;
} Sbc_Ip_SpiSetupType;

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

/*==================================================================================================
*                                       FUNCTION PROTOTYPES
==================================================================================================*/
#define SBC_FS26_START_SEC_CODE
#include "Sbc_fs26_MemMap.h"

/*!
 * @brief SPI transfer.
 *
 * This function transfers data via SPI.
 *
 * @param[in] spiSetup      SPI interface setup
 * @param[in] txBuffer      SPI Tx buffer
 * @param[out] rxBuffer     SPI Rx buffer
 */
extern Std_ReturnType Sbc_Ip_SpiTransferExternal(const Sbc_Ip_SpiSetupType *spiSetup,
                                                     uint32 *txBuffer,
                                                     uint32 *rxBuffer);

/*!
 * @brief Sets the SPI asynchronous mode.
 *
 * This function sets the SPI asynchronous mode.
 *
 */
extern Std_ReturnType Sbc_Ip_SpiSetAsyncMode(void);

/*!
 * @brief Notifies the SPI transfer end.
 *
 * This function notifies the SPI transfer end.
 *
 */
#ifdef USE_IPV_DSPI
void Sbc_Ip_SpiNotifyTransferEnd(uint8 instance, Spi_Ip_EventType event);
#elif defined(USE_IPV_LPSPI)
void Sbc_Ip_SpiNotifyTransferEnd(uint8 instance, Lpspi_Ip_EventType event);
#else
    extern void Sbc_Ip_SpiNotifyTransferEnd(void);
#endif

#define SBC_FS26_STOP_SEC_CODE
#include "Sbc_fs26_MemMap.h"

#if defined(__cplusplus)
}
#endif

/** @}*/

#endif  /* SPI_EXTERNAL_ACCESS_H */
