/**
*   @file    Fls.h
*   @implements Fls.h_Artifact
*   @version 1.0.0
*
*   @brief   AUTOSAR Fls - AUTOSAR Module Flash Driver.
*   @details Include all external API declarations and definitions of all pre-compile parameters.
*
*   @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_H
#define FLS_H

#ifdef __cplusplus
extern "C"{
#endif

/**
 * @page misra_violations MISRA-C:2012 violations
 *
 * @section [global]
 * Violates MISRA 2012 Required Rule 5.1, External identifiers shall be distinct.
 * 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.2, Identifiers declared in the same scope and namespace shall be distinct.
 * This violation is due to the requirement that requests to have a file version check.
 *
 * @section [global]
 * Violates MISRA 2012 Required Rule 5.4, Macro identifiers shall be distinct.
 *  This violation is due to the requirement that requests to have a file version check.
 *
 * @section [global]
 * Violates MISRA 2012 Required Rule 5.5, Identifiers shall be distinct from macro names.
 * This violation is due to the requirement that requests to have a file version check.
 *
 * @section Fls_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_h_REF_2
 * Violates MISRA 2012 Advisory Rule 20.1, #Include directives should only be preceded by preprocessor directives or comments.
 * <MA>_MemMap.h is included after each section define in order to set the current memory section as defined by AUTOSAR.
 */

/*==================================================================================================
                                         INCLUDE FILES
 1) system and project includes
 2) needed interfaces from external units
 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Mcal.h"
#include "Fls_Cfg.h"
#include "Fls_Api.h"
#if ((FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON) && (STD_OFF == FLS_TIMEOUT_AS_LOOP))
#include "Os.h"
#endif /* (FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON) && (STD_OFF == FLS_TIMEOUT_AS_LOOP) */
/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define FLS_AR_RELEASE_MAJOR_VERSION     4
#define FLS_AR_RELEASE_MINOR_VERSION     3
#define FLS_AR_RELEASE_REVISION_VERSION  1
#define FLS_SW_MAJOR_VERSION             1
#define FLS_SW_MINOR_VERSION             0
#define FLS_SW_PATCH_VERSION             0
/*==================================================================================================
*                                     FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and Mcal.h header file are of the same Autosar version */
    #if ((FLS_AR_RELEASE_MAJOR_VERSION != MCAL_AR_RELEASE_MAJOR_VERSION) || \
         (FLS_AR_RELEASE_MINOR_VERSION != MCAL_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Fls.h and Mcal.h are different"
    #endif
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and Fls_Cfg.h header file are of the same Autosar version */
    #if ((FLS_AR_RELEASE_MAJOR_VERSION != FLS_AR_RELEASE_MAJOR_VERSION_CFG) || \
         (FLS_AR_RELEASE_MINOR_VERSION != FLS_AR_RELEASE_MINOR_VERSION_CFG))
        #error "AutoSar Version Numbers of Fls.h and Fls_Cfg.h are different"
    #endif
#endif
/* Check if header file and Fls_Cfg.h header file are of the same vendor */
#if (FLS_VENDOR_ID != FLS_VENDOR_ID_CFG)
    #error "Fls.h and Fls_Cfg.h have different vendor ids"
#endif
/* Check if header file and Fls_Cfg.h header file are of the same software version */
#if ((FLS_SW_MAJOR_VERSION != FLS_SW_MAJOR_VERSION_CFG) || \
     (FLS_SW_MINOR_VERSION != FLS_SW_MINOR_VERSION_CFG) || \
     (FLS_SW_PATCH_VERSION != FLS_SW_PATCH_VERSION_CFG))
    #error "Software Version Numbers of Fls.h and Fls_Cfg.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if header file and Fls_Api.h header file are of the same Autosar version */
    #if ((FLS_AR_RELEASE_MAJOR_VERSION != FLS_API_AR_RELEASE_MAJOR_VERSION) || \
         (FLS_AR_RELEASE_MINOR_VERSION != FLS_API_AR_RELEASE_MINOR_VERSION))
        #error "AutoSar Version Numbers of Fls.h and Fls_Api.h are different"
    #endif
#endif
/* Check if header file and Fls_Api.h header file are of the same vendor */
#if (FLS_VENDOR_ID != FLS_API_VENDOR_ID)
    #error "Fls.h and Fls_Api.h have different vendor ids"
#endif
/* Check if header file and Fls_Api.h header file are of the same software version */
#if ((FLS_SW_MAJOR_VERSION != FLS_API_SW_MAJOR_VERSION) || \
     (FLS_SW_MINOR_VERSION != FLS_API_SW_MINOR_VERSION) || \
     (FLS_SW_PATCH_VERSION != FLS_API_SW_PATCH_VERSION))
    #error "Software Version Numbers of Fls.h and Fls_Api.h are different"
#endif

/*==================================================================================================
                                       GLOBAL VARIABLES
==================================================================================================*/

#define FLS_START_SEC_VAR_INIT_UNSPECIFIED
/*
 * @violates @ref Fls_h_REF_1 Precautions shall be taken in order to prevent the contents of a header file being included more than once
 * @violates @ref Fls_h_REF_2 #Include directives should only be preceded by preprocessor directives or comments
 */
#include "Fls_MemMap.h"

/**
 * @brief Logical address of data block currently processed by Fls_MainFunction
 */
extern VAR(Fls_AddressType, FLS_VAR) Fls_u32JobAddrIt;
/**
 * @brief Index of flash sector currently processed by a job
 * @details Used by all types of job
 */
extern VAR(volatile Fls_SectorIndexType, FLS_VAR) Fls_u32JobSectorIt;
/**
 * @brief Type of currently executed job (erase, write, read, or compare)
 */
extern VAR(Fls_JobType, FLS_VAR) Fls_eJob;
/**
 * @brief Index of last flash sector by current job
 * @details Used to check status of all external flash chips before start jobs
 * or is the last sector in Erease job
 */
extern VAR(Fls_SectorIndexType, FLS_VAR) Fls_u32JobSectorEnd;
/**
 * @brief Result of last flash hardware job
 */
extern VAR(volatile MemIf_JobResultType, FLS_VAR) Fls_eLLDJobResult;
/**
 * @brief Type of current flash hardware job - used for asynchronous operating mode.
 */
extern VAR(Fls_LLDJobType, FLS_VAR) Fls_eLLDJob;
/**
 * @brief Type of current flash hardware job - used for interrupt operating mode.
 */
extern VAR(volatile Fls_LLDIrqJobType, FLS_VAR) Fls_eLLDIrqJob;
/**
 * @brief Pointer to current flash module configuration set
 */
extern P2CONST(Fls_ConfigType, FLS_VAR, FLS_APPL_CONST) Fls_pConfigPtr;
/**
 * @brief Number of bytes of data left to write.
 */
extern VAR(volatile Fls_LengthType, AUTOMATIC) Fls_u32LLDRemainingDataToWrite;
#define FLS_STOP_SEC_VAR_INIT_UNSPECIFIED
/*
 * @violates @ref Fls_h_REF_1 Precautions shall be taken in order to prevent the contents of a header file being included more than once
 * @violates @ref Fls_h_REF_2 #Include directives should only be preceded by preprocessor directives or comments
 */
#include "Fls_MemMap.h"

#define FLS_START_SEC_VAR_INIT_32
/*
 * @violates @ref Fls_h_REF_1 Precautions shall be taken in order to prevent the contents of a header file being included more than once
 * @violates @ref Fls_h_REF_2 #Include directives should only be preceded by preprocessor directives or comments
 */
#include "Fls_MemMap.h"

#if((FLS_ERASE_VERIFICATION_ENABLED == STD_ON) || (FLS_WRITE_VERIFICATION_ENABLED == STD_ON) || (FLS_SYNCRONIZE_CACHE == STD_ON))
extern VAR(Fls_LengthType, AUTOMATIC) Fls_u32LLDNumberOfStepBack;
#endif /* (FLS_ERASE_VERIFICATION_ENABLED == STD_ON) || (FLS_WRITE_VERIFICATION_ENABLED == STD_ON) || (FLS_SYNCRONIZE_CACHE == STD_ON) */

#if (FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON)
/**
 * @brief Timeout counter used in both sync/async modes
 */
extern VAR(uint32, FLS_VAR) Fls_u32LLDTimeout_Counter;
#if (STD_OFF == FLS_TIMEOUT_AS_LOOP)
extern VAR(TickType, AUTOMATIC) Fls_u32CurrentValue;
extern VAR(TickType, AUTOMATIC) Fls_u32ElapsedTime;
#endif /* STD_OFF == FLS_TIMEOUT_AS_LOOP */
#endif /* FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON */

#define FLS_STOP_SEC_VAR_INIT_32
/*
 * @violates @ref Fls_h_REF_1 Precautions shall be taken in order to prevent the contents of a header file being included more than once
 * @violates @ref Fls_h_REF_2 #Include directives should only be preceded by preprocessor directives or comments
 */
#include "Fls_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif /* FLS_H */

/** @} */
