/**
* @file         CDD_Sbc_fs26.h
* @version      1.0.0
*
* @brief        AUTOSAR Sbc_fs26 - module interface.
* @details      API header for FS26 driver.
*
* @addtogroup   CDD_SBC_FS26_DRIVER
* @{
*/
/*==================================================================================================
*   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 CDD_SBC_FS26_H
#define CDD_SBC_FS26_H

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.1, Identifiers (internal and external) shall not rely
* on the significance of more than 31 characters. The used compilers use more than 31 chars for
* identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.1, identifier clash
* The supported compilers use more than 31 significant characters for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.2, identifier clash
* The supported compilers use more than 31 significant characters for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.4, identifier clash
* The supported compilers use more than 31 significant characters for identifiers.
*
* @section [global]
* Violates MISRA 2012 Required Rule 5.5, identifier clash
* The supported compilers use more than 31 significant characters for identifiers.
*
*/

/*==================================================================================================
*                                        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
==================================================================================================*/
/*
    Internal micro-dependent versioning. Check of AUTOSAR & Vendor specification version.
*/
#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     4
#define SBC_FS26_AR_RELEASE_REVISION_VERSION  0
#define SBC_FS26_SW_MAJOR_VERSION             1
#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

/*==================================================================================================
*                                          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.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_Init(Sbc_fs26_ConfigType* pConfig);
/**
* @brief        Configures the device. SID is 0x10.
* @details      Performs initialization checks (LBIST, ABIST1 are pass)
*               and writes all INIT_FS registers and watchdog configuration.
*               Closes initialization phase by sending first watchdog refresh.
*
*               NOTE: If external watchdog is used (SBC_FS26_EXTERNAL_WDG_USED = TRUE) writing
*               watchdog related registers and first watchdog refresh (closing INIT_FS phase)
*               is skipped in order to allow watchdog configuration by the external watchdog.
*               The function leaves the device in INIT_FS phase, which needs to be properly
*               closed by the external watchdog within 256 ms from FS26 start-up.
*
* @return       Std_ReturnType  Return code.
*/
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]    IsFailSafe      TRUE if the register is Fail Safe.
* @param[in]    Address         Register address.
* @param[out]   pRxData         Pointer to structure holding the response from SBC.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_ReadRegister(boolean IsFailSafe, uint8 Address, Sbc_fs26_RxFrameType* pRxData);

/**
* @brief        Sends write command to the FS26. SID is 0x02.
*
* @param[in]    IsFailSafe      TRUE: Reading from FS register, FALSE: Reading from Main register.
* @param[in]    Address         Register address.
* @param[in]    WriteData       Register write value.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_WriteRegister(boolean IsFailSafe, uint8 Address, uint16 WriteData, Sbc_fs26_RxFrameType* pRxData);

/**
* @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.
*               Switching between the modes is done as follows:
*               - Switch to normal mode (via SPI) can be done from standby mode only. SPI CSB transition
*                 wake-up must be previously enabled in M_WIO_CFG register (using Sbc_fs26_SetWakeup).
*               - 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]    OpMode          Device operating mode.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetOperatingMode(Sbc_fs26_OpModeType OpMode);

/**
* @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]    LdtFunction     LDT function.
* @param[in]    LdtMode         LDT operation mode.
* @param[in]    AfterRun        LDT after run value (16 bits).
* @param[in]    WakeUp          LDT wake-up value (24 bits).
* @param[in]    LdtLp           Low-power mode to go to for functions 2-3.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetLDT(Sbc_fs26_LdtFuncType LdtFunction, Sbc_fs26_LdtModeType LdtMode, uint16 AfterRun, uint32 WakeUp, Sbc_fs26_LdtLpType LdtLp);

/**
* @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]   pLdtValue       Pointer to Long Duration Timer value storage.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_GetLDTValue(uint32* pLdtValue);

/**
* @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]    WdToken         New watchdog token, stored to run-time configuration if change was successful.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_WdChangeToken(uint16 WdToken);

/**
* @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]   pFaultErrorCounterValue  Pointer to Fault Error counter value storage.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_GetFaultErrorCounterValue(uint8* pFaultErrorCounterValue);

/**
* @brief        FSxB release routine. SID is 0x09.
*
* @details      This function also checks all preconditions before it sends the register write
*               command (LBIST_OK = ABIST1_OK = 1, Fault Error Counter = 0).
*               If any precondition is not met, the function returns E_NOT_OK.
*
* @param[in]    FsOutput        FS output to release.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_FsxbRelease(Sbc_fs26_FsOutputType FsOutput);

/**
* @brief        Sets state (enable/disable) of the selected voltage regulator. SID is 0x0A.
*
* @param[in]    Vreg            Voltage regulator.
* @param[in]    Enable          State (enable = TRUE / disable = FALSE).
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetRegulatorState(Sbc_fs26_RegOutputType Vreg, boolean Enable);

/**
* @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]    AmuxChannel     AMUX channel selection.
* @param[in]    AmuxDiv         AMUX divider.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetAmux(Sbc_fs26_AmuxChanType AmuxChannel, Sbc_fs26_AmuxDivType AmuxDiv);

/**
* @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]    WakeupSrc       Wake up source (when source is TRUE = enabled).
* @param[in]    WakeupPol       Wake up polarity (when source polarity is TRUE = low).
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_SetWakeup(Sbc_fs26_WuSrcType WakeupSrc, Sbc_fs26_WuPolType WakeupPol);

/**
* @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]    ClearFlags      TRUE = clear wake up flags after reading.
* @param[out]   pWakeupReason   Status of wake up flags.
*
* @return       Std_ReturnType  Return code.
*/
Std_ReturnType Sbc_fs26_GetWakeup(boolean ClearFlags, Sbc_fs26_WuReasonType* pWakeupReason);

#if (SBC_FS26_VERSION_INFO_API == STD_ON)
/**
* @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.
*
* @return       void
*/
void Sbc_fs26_GetVersionInfo(Std_VersionInfoType* pVersionInfo);
#endif

/**
* @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*/

/** @} */
