/*==================================================================================================
*   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.
==================================================================================================*/

/**
* @file         CDD_Sbc_fs26.h
* @version      6.0.0
*
* @brief        CDD Sbc_fs26 - module interface.
* @details      API header for FS26 driver.
*
* @addtogroup   CDD_SBC_FS26_DRIVER
* @{
*/

#ifndef CDD_SBC_FS26_H
#define CDD_SBC_FS26_H

#ifdef __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 "CDD_Sbc_fs26_Types.h"
/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define SBC_FS26_VENDOR_ID                    43
#define SBC_FS26_MODULE_ID                    255
#define SBC_FS26_AR_RELEASE_MAJOR_VERSION     4
#define SBC_FS26_AR_RELEASE_MINOR_VERSION     9
#define SBC_FS26_AR_RELEASE_REVISION_VERSION  0
#define SBC_FS26_SW_MAJOR_VERSION             6
#define SBC_FS26_SW_MINOR_VERSION             0
#define SBC_FS26_SW_PATCH_VERSION             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and CDD_Sbc_fs26 configuration header file are of the same vendor */
#if (SBC_FS26_VENDOR_ID != SBC_FS26_VENDOR_ID_TYPES_H)
    #error "CDD_Sbc_fs26.h and CDD_Sbc_fs26_Types.h have different vendor ids"
#endif
/* Check if current file and CDD_Sbc_fs26 configuration header file are of the same module */
#if (SBC_FS26_MODULE_ID != SBC_FS26_MODULE_ID_TYPES_H)
    #error "CDD_Sbc_fs26.h and CDD_Sbc_fs26_Types.h have different module ids"
#endif
/* Check if current file and CDD_Sbc_fs26 configuration header file are of the same Autosar version */
#if ((SBC_FS26_AR_RELEASE_MAJOR_VERSION != SBC_FS26_AR_RELEASE_MAJOR_VERSION_TYPES_H) || \
     (SBC_FS26_AR_RELEASE_MINOR_VERSION != SBC_FS26_AR_RELEASE_MINOR_VERSION_TYPES_H) || \
     (SBC_FS26_AR_RELEASE_REVISION_VERSION != SBC_FS26_AR_RELEASE_REVISION_VERSION_TYPES_H))
    #error "AutoSar Version Numbers of CDD_Sbc_fs26.h and CDD_Sbc_fs26_Types.h are different"
#endif
/* Check if current file and CDD_Sbc_fs26 configuration header file are of the same software version */
#if ((SBC_FS26_SW_MAJOR_VERSION != SBC_FS26_SW_MAJOR_VERSION_TYPES_H) || \
     (SBC_FS26_SW_MINOR_VERSION != SBC_FS26_SW_MINOR_VERSION_TYPES_H) || \
     (SBC_FS26_SW_PATCH_VERSION != SBC_FS26_SW_PATCH_VERSION_TYPES_H))
    #error "Software Version Numbers of CDD_Sbc_fs26.h and CDD_Sbc_fs26_Types.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if current file and DEM header file are of the same version */
    #if (STD_OFF == SBC_FS26_DISABLE_DEM_ERROR_REPORT)
        #if ((SBC_FS26_AR_RELEASE_MAJOR_VERSION != DEM_AR_RELEASE_MAJOR_VERSION) || \
            (SBC_FS26_AR_RELEASE_MINOR_VERSION != DEM_AR_RELEASE_MINOR_VERSION))
            #error "AutoSar Version Numbers of CDD_Sbc_fs26.h and Dem.h are different"
        #endif
    #endif
#endif
/*==================================================================================================
*                                          CONSTANTS
==================================================================================================*/

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

/*==================================================================================================
*                                             ENUMS
==================================================================================================*/

/*==================================================================================================
*                                STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/

/*==================================================================================================
*                                GLOBAL VARIABLE DECLARATIONS
==================================================================================================*/
#ifdef SBC_FS26_CONFIG_EXT
#define SBC_FS26_START_SEC_CONFIG_DATA_UNSPECIFIED
/**
* @brief Include Memory mapping specification
*/
#include "Sbc_fs26_MemMap.h"

/**
* @brief Extern SPI, driver and device configuration structures.
*/
SBC_FS26_CONFIG_EXT

#define SBC_FS26_STOP_SEC_CONFIG_DATA_UNSPECIFIED
/**
* @brief Include Memory mapping specification
*/
#include "Sbc_fs26_MemMap.h"
#endif

/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/
#define SBC_FS26_START_SEC_CODE
/**
* @brief Include Memory mapping specification
*/
#include "Sbc_fs26_MemMap.h"

/**
* @brief        Initializes the FS26 driver. SID is 0x00.
* @details      Internally stores the run-time configuration.
*
* @param[in]    pConfig         Pointer to FS26 driver configuration set. The argument cannot be NULL_PTR in case SBC_FS26_PRECOMPILE_SUPPORT = STD_OFF.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_Init(const Sbc_fs26_ConfigType* pConfig);
/**
* @brief        Configures the device. SID is 0x10.
* @details      Performs initialization checks (in INIT_FS or not, LBIST, ABIST1 are pass)
*               and writes all INIT_FS registers and watchdog configuration.
*               Closes initialization phase by sending first watchdog refresh.
*               Exit Debug mode (if available) and release Fsxb pin.
*               The device shall go to NORMAL state after executing this function.
*
*
* @return       Std_ReturnType  Return code.
*
* @api
*/
Std_ReturnType Sbc_fs26_InitDevice(void);

/**
* @brief        Performs a read from a single FS26 register. SID is 0x01.
* @details      Performs a single read register based on provided address.
*               The response is returned in Sbc_fs26_RxFrameType structure.
*
* @param[in]    bIsFailSafe      TRUE if the register is Fail Safe.
* @param[in]    u8Address        Register address. Valid range for address is less than SBC_FS26_MAX_REG_ADD_U8.
* @param[out]   pRxData          Pointer to structure holding the response from SBC. The argument cannot be NULL_PTR.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_ReadRegister(boolean bIsFailSafe,
                                     uint8 u8Address,
                                     Sbc_fs26_RxFrameType* pRxData);

/**
* @brief        Sends write command to the FS26. SID is 0x02.
*
* @param[in]    bIsFailSafe        TRUE: Reading from FS register, FALSE: Reading from Main register.
* @param[in]    u8Address          Register address. Valid range for address is less than SBC_FS26_MAX_REG_ADD_U8.
* @param[in]    u16WriteData       Register write value. The whole 16 bit range is valid.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_WriteRegister(boolean bIsFailSafe,
                                      uint8 u8Address,
                                      uint16 u16WriteData);

/**
* @brief        Sets device operating mode. SID is 0x03.
* @details      The FS26 provides three main operating modes:
*               - NORMAL mode: The system is fully functional with all power supplies enabled
*                 as required by the system as well as all the system functionality provided
*                 by the FS26 device is available. During the normal mode, the Fail Safe state machine
*                 is available and providing full monitoring and operation of all the safety features
*                 in the device.
*               - STANDBY mode: This is intended to be a low power ON mode, providing support
*                 to the minimum system requirements with low current consumption from the battery.
*                 During the standby mode, only the VPRE remain enabled to supply the microcontroller
*                 I/O rail. LDO1 and LDO2 can be enabled in this mode depending on OTP configuration.
*                 This mode is assumed to be a safe state with no critical activity and therefore
*                 the Fail-safe state machine is disabled to allow minimum current consumption of the system.
*               - LPOFF mode: this mode is intended to place the system in a fully OFF state with no
*                 system supplies active. Logic circuitry is supplied internally to allow proper wake up
*                 from any of the available wake-up mechanism, with the minimum current consumption possible.
*               The FS26 only supports switching from Normal mode to Low power mode as follow:
*               - Switching to standby mode is done from normal mode through pre standby mode.
*               - Switching to LPOFF mode is done from normal mode through pre LPOFF mode.
*
*               NOTE: Before entering any low-power mode make sure some wake-up source is enabled
*               (using Sbc_fs26_SetWakeup).
*
* @param[in]    eOpMode          Device operating mode. Valid value is SBC_FS26_OPMODE_STANDBY or SBC_FS26_OPMODE_LPOFF.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetOperatingMode(Sbc_fs26_OpModeType eOpMode);

#if (STD_ON == SBC_FS26_LDT_FUNCTION_API)
/**
* @brief        Sets long duration timer function. SID is 0x04.
* @details      FS26 features a long duration timer, with an integrated oscillator. The timer is
*               configurable by SPI and can operate in NORMAL and in Low Power modes. The timer is
*               based on a 24-bit counter, with a 32768Hz oscillator allowing a 1.0 second time base.
*               In normal operation, the timer can count up to 194 days, with 1 second resolution.
*               The timer functions are:
*               - Function 1: In normal mode, count and generate a flag or an Interrupt when
*                 the counter reaches the after run value.
*               - Function 2: In normal mode, count until the counter reaches the after run value
*                 and enters into low-power mode.
*               - Function 3: In normal mode, count until the counter reaches the after run value
*                 and enters into low-power mode. Once in low-power mode, count until the counter
*                 reaches the wake-up value and wakes up.
*               - Function 4: In low-power mode, count until the counter reaches the wake-up
*                 value and wakes up.
*               - Function 5: In low-power mode, count and do not wake-up unless the counter overflow
*                 occurs, or if the device wakes up by wake up input source.
*
*               NOTE: For functions 1-3 the timer is started automatically, for functions 4-5 the timer
*               starts as soon as the application enters low-power mode (using Sbc_fs26_SetOperatingMode).
*
*               NOTE: For functions 3-5 make sure LDT wake up is enabled (using Sbc_fs26_SetWakeup).
*
* @param[in]    eLdtFunction       LDT function. Valid value is between the range (including) of SBC_FS26_LDTFUNC_FUNC1 and SBC_FS26_LDTFUNC_FUNC5.
* @param[in]    eLdtMode           LDT operation mode. Valid value is SBC_FS26_LDTMODE_LONG or SBC_FS26_LDTMODE_SHORT.
* @param[in]    u16AfterRun        LDT after run value (16 bits). Valid value is the whole 16 bit range.
* @param[in]    u32WakeUp          LDT wake-up value (24 bits). Valid value is only the last 24 bits. Mask with value 0x0000FFFFU is performed.
* @param[in]    eLdtLp             Low-power mode to go to for functions 2-3. Valid value is SBC_FS26_LDTLP_LPOFF or SBC_FS26_LDTLP_STANDBY.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetLDT(Sbc_fs26_LdtFuncType eLdtFunction,
                               Sbc_fs26_LdtModeType eLdtMode,
                               uint16 u16AfterRun,
                               uint32 u32WakeUp,
                               Sbc_fs26_LdtLpType eLdtLp);

/**
* @brief        Reads actual Long Duration Timer value. SID is 0x05.
* @details      This function checks if the Long Duration Timer is running and reads the real-time value.
*
* @param[out]   pu32LdtValue       Pointer to Long Duration Timer value storage. Value cannot be NULL_PTR.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_GetLDTValue(uint32* pu32LdtValue);
#endif /* (STD_ON == SBC_FS26_LDT_FUNCTION_API) */

/**
* @brief        Changes token of LFSR used for watchdog. SID is 0x06.
* @details      The watchdog token can be changed just during the INIT_FS phase (for challenger WD)
*               or during the OPEN watchdog window (for simple WD). Timing is up to the application!
*
* @param[in]    u16Token         New watchdog token, stored to run-time configuration if change was successful. Valid value is the whole 16 bit range.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_WdChangeToken(uint16 u16Token);

/**
* @brief        Performs the watchdog refresh. SID is 0x07.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_WdRefresh(void);

/**
* @brief        Reads actual Fault Error Counter value. SID is 0x08.
*
* @param[out]   pu8FaultErrorCounterValue  Pointer to Fault Error counter value storage. Value cannot be NULL_PTR.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_GetFaultErrorCounterValue(uint8* pu8FaultErrorCounterValue);

/**
* @brief        FSxB release routine. SID is 0x09.
*
* @details      This function allows release FS0B pin or FS1B pin or both pins when these pins were asserted low by the device before.
*               This function also checks all preconditions before it sends the register write command (LBIST_OK = ABIST1_OK = 1, launch ABIST2, remove fault and clear Fault Error Counter).
*               If any precondition is not met, the function returns E_NOT_OK.
*
* @param[in]    eFsOutput        FS output to release. Valid value is SBC_FS26_FS_FS0B, SBC_FS26_FS_FS1B or SBC_FS26_FS_BOTH.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_FsxbRelease(Sbc_fs26_FsOutputType eFsOutput);

#if (STD_ON == SBC_FS26_SET_REGULATOR_API)
/**
* @brief        Sets state (enable/disable) of the selected voltage regulator. SID is 0x0A.
*
* @param[in]    eVreg            Voltage regulator. Vaid value is between (including) the range of SBC_FS26_REG_LDO1 and SBC_FS26_REG_VREF.
* @param[in]    bEnable          State (enable = TRUE / disable = FALSE).
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetRegulatorState(Sbc_fs26_RegOutputType eVreg,
                                          boolean bEnable);
#endif /* (STD_ON == SBC_FS26_SET_REGULATOR_API) */

#if (STD_ON == SBC_FS26_AMUX_CHANNEL_API)
/**
* @brief        Configures analog multiplexer. SID is 0x0B.
* @details      The AMUX pin delivers internal voltage channels to the AMUX pin. Maximum AMUX output
*               voltage range is VDDIO. The analog multiplexer can be used in the system to monitor
*               critical parameters of the FS26 and the application.
*               AMUX divider selection is used only for VBST, VSUP, WAKE1, WAKE2, GPIO1, GPIO2
*               and BATSENSE pin voltages (see datasheet or Sbc_fs26_AmuxDivType type for details).
*
* @param[in]    eAmuxChannel     AMUX channel selection. Valid value is equal or less than SBC_FS26_AMUXCHAN_GPIO1_TEMP.
* @param[in]    eAmuxDiv         AMUX divider. Valid value is SBC_FS26_AMUXDIV_LOW or SBC_FS26_AMUXDIV_HIGH.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetAmux(Sbc_fs26_AmuxChanType eAmuxChannel,
                                Sbc_fs26_AmuxDivType eAmuxDiv);
#endif /* (STD_ON == SBC_FS26_AMUX_CHANNEL_API) */

#if (STD_ON == SBC_FS26_WAKEUP_API)
/**
* @brief        Configures wake up from low-power mode. SID is 0x0C.
* @details      The system can Wake up from any of the Low Power modes via any of the selectable
*               wake up mechanism available in the device:
*               - WAKE1 and WAKE2 pins,
*               - GPIO1 and GPIO2 pins,
*               - Long Duration Timer (LDT) expiration (needed for proper Sbc_fs26_SetLDT functionality),
*               - SPI CS pin edge detection (needed for proper Sbc_fs26_SetOperatingMode functionality).
*               This function enables/disables all of the wake up sources and sets wake up polarity
*               for WAKE1/2 and GPIO1/2 wake up.
*
* @param[in]    xWakeupSrc       Wake up source (when source is TRUE = enabled).
* @param[in]    xWakeupPol       Wake up polarity (when source polarity is TRUE = low).
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetWakeup(Sbc_fs26_WuSrcType xWakeupSrc,
                                  Sbc_fs26_WuPolType xWakeupPol);

/**
* @brief        Reads device wake up flags. SID is 0x0D.
* @details      This function reads device wake up flags and clears them if requested.
*               The device has dedicated wake up flags for WAKE1/2, GPIO1/2 and LDT sources,
*               but also reports general wake up status, which contains also sources such as
*               deep fail safe recovery, battery fail or SPI wake up (see datasheet).
*
* @param[in]    bClearFlags     TRUE = clear wake up flags after reading.
* @param[out]   pWakeupReason   Status of wake up flags. Value cannot be NULL_PTR.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_GetWakeup(boolean bClearFlags,
                                  Sbc_fs26_WuReasonType* pWakeupReason);
#endif /* (STD_ON == SBC_FS26_WAKEUP_API) */

/**
* @brief        Switch SBC device back to Init mode. SID is 0x11.
* @details      This function is used to switch device back to Init state and then users can re-configure
*               the Fail-safe register. To make sure every register is set before closing the Init phase,
*               the requesting watchdog refresh must be ignored. In order to trigger watchdog again, the user
*               must use Sbc_fs26_InitDevice() function after executing this function.
*
*
* @return       Std_ReturnType  Return code.
*
* @api
*/
Std_ReturnType Sbc_fs26_GotoInitFS(void);

/**
* @brief        Disable Watchdog during runtime. SID is 0x12.
* @details      This function is used to set Window Period Infinity which only be set in InitFS state.
*               Device will go to InitFS to set Window Period Infinity then switch back to Normal state at the end of function.
*
*
* @return       Std_ReturnType  Return code.
*
* @api
*/
Std_ReturnType Sbc_fs26_DisableWatchdog(void);

#if (STD_ON == SBC_FS26_ABIST2_CHECK_API)
/**
* @brief        Perform Abist on demand (Abist2) check. SID is 0x13.
* @details      This check can be launched as soon as device is in Normal mode.
*               This feature is available for specific part numbers. To launch this
*               check, the user must select which monitoring has to be checked. It will return E_OK
*               only when the diagnostic on Abist2 is DONE and report PASS then.
*
* @param[in]    eVmonitor            Voltage to be checked. Valid value is equal or less than SBC_FS26_MOR_VEXT.
*
* @return       Std_ReturnType  Return code.
*
* @api
*/
Std_ReturnType Sbc_fs26_PerformAbist2Check(Sbc_fs26_VoltageSupervisionType eVmonitor);
#endif /* (STD_ON == SBC_FS26_ABIST2_CHECK_API) */

#ifdef SBC_FS26_ASYNC_TRANSMIT
/**
* @brief        Get Asynchronous Transmision  status.
* @details      This function return status for Asynchronous Transmision.
*
* @return       Sbc_fs26_SpiAsyncStatusType
*               SBC_FS26_TRANS_DONE: Successful Spi transmission
*               SBC_FS26_TRANS_ON_GOING: Spi transmission is on-going
*               SBC_FS26_TRANS_FAILED: Spi transmission faile
*
* @api
*/
/** @implements   Sbc_fs26_GetAsyncTransmissionStatus_Activity */
Sbc_fs26_SpiAsyncStatusType Sbc_fs26_GetAsyncTransmissionStatus(void);
/**
* @brief        Hook-up function is called by Spi callback in case Asynchronous is used.
* @details      When Spi hardware transmission is completed, the function must be called in order to handle queue activities.
*
*
* @return       void
*
* @api
*/
/** @implements   Sbc_fs26_SpiNotification_Activity */
void Sbc_fs26_SpiNotification(void);

#endif /*SBC_FS26_ASYNC_TRANSMIT*/

#if (STD_ON == SBC_FS26_VERSION_INFO_API)
/**
* @brief        FS26 driver get version info function. SID is 0x0E.
* @details      Returns the version information of this module.
*
* @param[out]   pVersionInfo    Pointer to where to store the version information of this module. Value cannot be NULL_PTR.
*
* @return       void
*/
void Sbc_fs26_GetVersionInfo(Std_VersionInfoType* pVersionInfo);
#endif /* (STD_ON == SBC_FS26_VERSION_INFO_API) */

/**
*   @brief          This function indicate the current Sbc's state. SID is 0x14
*
*   @param[in]      void
*
*
*   @return         Sbc_fs26_DeviceState    Device State
*/
/** @implements   Sbc_fs26_GetDeviceState_Activity */
Sbc_fs26_DeviceState Sbc_fs26_GetDeviceState(void);

/**
* @brief        Deinitializes the FS26 driver. SID is 0x0F.
* @details      Clears the internal run-time configuration.
*
* @return       void
*/
void Sbc_fs26_Deinit(void);

#define SBC_FS26_STOP_SEC_CODE
/**
* @brief Include Memory mapping specification
*/
#include "Sbc_fs26_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif /*CDD_SBC_FS26_H*/

/** @} */
