/**
*   @file    Fls_Api.h
*   @implements Fls_Api.h_Artifact
*   @version 1.0.0
*
*   @brief   AUTOSAR Fls - AUTOSAR Module Flash Driver.
*   @details All external API declarations of Flash driver.
*
*   @addtogroup FLS
*   @{
*/
/*==================================================================================================
*   Project              : AUTOSAR 4.3 MCAL
*   Platform             : PA
*   Peripheral           : IPV_FLASHV2
*   Dependencies         : none
*
*   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.
==================================================================================================*/
/*==================================================================================================
==================================================================================================*/

#ifndef FLS_API_H
#define FLS_API_H

#ifdef __cplusplus
extern "C"{
#endif

/**
* @page misra_violations MISRA-C:2012 violations
*
* @section Fls_Api_h_REF_1
* 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 Fls_Api_h_REF_2
* Violates MISRA 2012 Advisory Rule 4.9, A function should be used in preference to a function-like macro where they are interchangeable.
* Macro is used for interaction of MCAL layers.
*
* @section [global]
* Violates MISRA 2012 Advisory Rule 2.5, A project should not contain unused macro declarations.
* Because this file is generation for all platform so this definition uses or not it depend by users
*/

/*==================================================================================================
                                         INCLUDE FILES
 1) system and project includes
 2) needed interfaces from external units
 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Fls_Cfg.h"
#include "MemIf_Types.h"

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
/**
* @brief          Version Check parameters.
*/
#define FLS_API_VENDOR_ID                    43
#define FLS_API_AR_RELEASE_MAJOR_VERSION     4
#define FLS_API_AR_RELEASE_MINOR_VERSION     3
#define FLS_API_SW_MAJOR_VERSION             1
#define FLS_API_SW_MINOR_VERSION             0
#define FLS_API_SW_PATCH_VERSION             0

/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and Fls_Cfg.h file are of the same vendor */
#if (FLS_API_VENDOR_ID != FLS_VENDOR_ID_CFG)
#error "Fls_Api.h and Fls_Cfg.h have different vendor ids"
#endif
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
/* Check if current file and Fls_Cfg.h file are of the same Autosar version */
#if ((FLS_API_AR_RELEASE_MAJOR_VERSION    != FLS_AR_RELEASE_MAJOR_VERSION_CFG) || \
     (FLS_API_AR_RELEASE_MINOR_VERSION    != FLS_AR_RELEASE_MINOR_VERSION_CFG) \
    )
#error "AutoSar Version Numbers of Fls_Api.h and Fls_Cfg.h are different"
#endif
#endif
/* Check if current file and Fls_Cfg.h file are of the same software version */
#if ((FLS_API_SW_MAJOR_VERSION != FLS_SW_MAJOR_VERSION_CFG) || \
     (FLS_API_SW_MINOR_VERSION != FLS_SW_MINOR_VERSION_CFG) || \
     (FLS_API_SW_PATCH_VERSION != FLS_SW_PATCH_VERSION_CFG)  \
    )
#error "Software Version Numbers of Fls_Api.h and Fls_Cfg.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
/* Check if current file and MemIf_Types.h file are of the same Autosar version */
#if ((FLS_API_AR_RELEASE_MAJOR_VERSION    != MEMIF_AR_RELEASE_MAJOR_VERSION) || \
     (FLS_API_AR_RELEASE_MINOR_VERSION    != MEMIF_AR_RELEASE_MINOR_VERSION) \
    )
#error "AutoSar Version Numbers of Fls_Api.h and MemIf_Types.h are different"
#endif
#endif

/*==================================================================================================
*                                          CONSTANTS
==================================================================================================*/
/* AUTOSAR module vendor identification */
#define FLS_VENDOR_ID            43

/* AUTOSAR module identification */
#define FLS_MODULE_ID            92

/* AUTOSAR module instance identification */
#define FLS_INSTANCE_ID          0U

/**
* @brief          Development error codes (passed to DET).
* @implements     DETERRORCODE_enumeration
*/
#define FLS_E_PARAM_CONFIG           0x01U /* API service called with wrong parameter */
#define FLS_E_PARAM_ADDRESS          0x02U /* API service called with wrong parameter */
#define FLS_E_PARAM_LENGTH           0x03U /* API service called with wrong parameter */
#define FLS_E_PARAM_DATA             0x04U /* API service called with wrong parameter */
#define FLS_E_UNINIT                 0x05U /* API service called without module initialization */
#define FLS_E_BUSY                   0x06U /* API service called while driver still busy */
#define FLS_E_PARAM_POINTER          0x0AU /* API service called with NULL pointer */
/**
* @brief          Runtime error codes (passed to DET).
*/
#define FLS_E_VERIFY_ERASE_FAILED    0x07U /* Erase verification (blank check) failed */
#define FLS_E_VERIFY_WRITE_FAILED    0x08U /* Write verification (compare) failed */
#define FLS_E_TIMEOUT                0x09U /* Timeout exceeded */
/**
* @brief          Transient Faults codes (passed to DET).
* 
*/
#define FLS_E_ERASE_FAILED           0x01U /* Flash erase failed (HW) */
#define FLS_E_WRITE_FAILED           0x02U /* Flash write failed (HW) */
#define FLS_E_READ_FAILED            0x03U /* Flash read failed (HW) */
#define FLS_E_COMPARE_FAILED         0x04U /* Flash compare failed (HW) */
/**
* @brief          All service IDs (passed to DET).
* @implements     SERVICEIDs_enumeration
*/
#define FLS_INIT_ID                  0x00U
#define FLS_ERASE_ID                 0x01U
#define FLS_WRITE_ID                 0x02U
#define FLS_CANCEL_ID                0x03U
#define FLS_GETJOBRESULT_ID          0x05U
#define FLS_MAINFUNCTION_ID          0x06U
#define FLS_READ_ID                  0x07U
#define FLS_COMPARE_ID               0x08U
#define FLS_SETMODE_ID               0x09U
#define FLS_GETVERSIONINFO_ID        0x10U
#define FLS_BLANK_CHECK_ID           0x11U

/**
* @brief          All sector flags.
*/
#define FLS_SECTOR_ERASE_ASYNCH      0x01U
#define FLS_PAGE_WRITE_ASYNCH        0x02U
#define FLS_SECTOR_IRQ_MODE          0x04U

/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/
/*==================================================================================================
*                                    FUNCTION PROTOTYPES
==================================================================================================*/

/**
* @brief    Start of Fls section CODE 
*/
#define FLS_START_SEC_CODE
/* @violates @ref Fls_Api_h_REF_1 Precautions shall be taken in order to prevent the contents of a header file being included more than once */
#include "Fls_MemMap.h"

extern FUNC( void, FLS_CODE ) Fls_Init
( P2CONST( Fls_ConfigType, AUTOMATIC, FLS_APPL_CONST ) pConfigPtr );

extern FUNC( Std_ReturnType, FLS_CODE ) Fls_Write
(   VAR( Fls_AddressType, AUTOMATIC) u32TargetAddress, 
    P2CONST( uint8, AUTOMATIC, FLS_APPL_CONST ) pSourceAddressPtr,
    VAR( Fls_LengthType, AUTOMATIC) u32Length 
);

extern FUNC( Std_ReturnType, FLS_CODE ) Fls_Erase
( 
    VAR( Fls_AddressType, AUTOMATIC) u32TargetAddress,
    VAR( Fls_LengthType, AUTOMATIC) u32Length 
);

#if( FLS_CANCEL_API == STD_ON )
extern FUNC( void, FLS_CODE ) Fls_Cancel( void );
#endif    /* FLS_CANCEL_API == STD_ON */

#if( FLS_GET_STATUS_API == STD_ON )
extern FUNC( MemIf_StatusType, FLS_CODE ) Fls_GetStatus( void );
#endif    /* FLS_GET_STATUS_API == STD_ON */

#if( FLS_GET_JOB_RESULT_API == STD_ON )
extern FUNC( MemIf_JobResultType, FLS_CODE ) Fls_GetJobResult( void );
#endif    /* FLS_GET_JOB_RESULT_API == STD_ON */

extern FUNC( Std_ReturnType, FLS_CODE ) Fls_Read
( 
    VAR( Fls_AddressType, AUTOMATIC) u32SourceAddress, 
    P2VAR( uint8, AUTOMATIC, FLS_APPL_DATA ) pTargetAddressPtr,    
    VAR( Fls_LengthType, AUTOMATIC) u32Length 
);

#if( FLS_COMPARE_API == STD_ON )
extern FUNC( Std_ReturnType, FLS_CODE ) Fls_Compare
(
    VAR( Fls_AddressType, AUTOMATIC) u32SourceAddress, 
    P2CONST( uint8, AUTOMATIC, FLS_APPL_CONST ) pTargetAddressPtr, 
    VAR( Fls_LengthType, AUTOMATIC) u32Length 
);
#endif /* FLS_COMPARE_API == STD_ON */

#if (FLS_BLANK_CHECK_API == STD_ON)
FUNC( Std_ReturnType, FLS_CODE ) Fls_BlankCheck
(
    VAR( Fls_AddressType, AUTOMATIC) u32TargetAddress,
    VAR( Fls_LengthType, AUTOMATIC) u32Length
);
#endif /* FLS_BLANK_CHECK_API == STD_ON */

#if( FLS_SET_MODE_API == STD_ON )
extern FUNC( void, FLS_CODE ) Fls_SetMode 
( VAR( MemIf_ModeType, AUTOMATIC ) eMode );
#endif /* FLS_SET_MODE_API == STD_ON */

#if( FLS_VERSION_INFO_API == STD_ON )
extern FUNC( void, FLS_CODE ) Fls_GetVersionInfo
( P2VAR( Std_VersionInfoType, AUTOMATIC, FLS_APPL_DATA ) pVersionInfoPtr );
#endif /* FLS_VERSION_INFO_API == STD_ON */

extern FUNC( void, FLS_CODE ) Fls_MainFunction( void );

#if (STD_ON == FLS_INTERNAL_FLASH_AVAILABLE)
#if( FLS_ECC_CHECK == STD_ON )
extern FUNC( Fls_CompHandlerReturnType, FLS_CODE ) Fls_DsiHandler
( P2CONST( Fls_ExceptionDetailsType, AUTOMATIC, FLS_APPL_CONST ) pExceptionDetailsPtr );  
#endif /* FLS_ECC_CHECK == STD_ON */
#endif /* FLS_INTERNAL_FLASH_AVAILABLE == STD_ON */
#if (FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON)
FUNC( uint32, FLS_CODE ) Fls_UpdateTimeoutLoopOrOs( VAR( uint32, AUTOMATIC) u32updateValueTimeOut);
#endif /*#if (FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON)*/

/**
* @brief    Stop of Fls section CODE 
*/
#define FLS_STOP_SEC_CODE
/* @violates @ref Fls_Api_h_REF_1 Precautions shall be taken in order to prevent the contents of a header file being included more than once */
#include "Fls_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif /* FLS_API_H */

/** @}*/
