/**
*   @file    Fls_Flash.h   
*   @version 1.0.0
*
*   @brief   AUTOSAR Fls - AUTOSAR Module Flash Driver.
*   @details Definitions of Flash IP exported types.
*
*   @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_FLASH_H
#define FLS_FLASH_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_Flash_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_Flash_h_REF_2
* Violates MISRA 2012 Advisory Rule 4.9, Function-like macro defined: 'FLASH_AC_CALL'
* Macro is used for the purpose of abstraction between PPC and ARM platforms.
*/

/*==================================================================================================
*                                        INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Fls.h"
#include "Fls_Types.h"
#include "Fls_Flash_Types.h"
#if ( (FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON) && (STD_OFF == FLS_TIMEOUT_AS_LOOP) )
#include "Os.h"
#endif
/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define FLS_FLASH_VENDOR_ID                    43
#define FLS_FLASH_AR_RELEASE_MAJOR_VERSION     4
#define FLS_FLASH_AR_RELEASE_MINOR_VERSION     3
#define FLS_FLASH_SW_MAJOR_VERSION             1
#define FLS_FLASH_SW_MINOR_VERSION             0
#define FLS_FLASH_SW_PATCH_VERSION             0
/*==================================================================================================
                                      FILE VERSION CHECKS
==================================================================================================*/
/* Check if current file and Fls header file are of the same vendor */
#if (FLS_FLASH_VENDOR_ID != FLS_VENDOR_ID)
    #error "Fls_Flash.h and Fls.h have different vendor ids"
#endif

/* Check if current file and Fls header file are of the same Software version */
#if ((FLS_FLASH_SW_MAJOR_VERSION != FLS_SW_MAJOR_VERSION) || \
     (FLS_FLASH_SW_MINOR_VERSION != FLS_SW_MINOR_VERSION) || \
     (FLS_FLASH_SW_PATCH_VERSION != FLS_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of Fls_Flash.h and Fls.h are different"
#endif

#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if current file and Fls header file are of the same Autosar version */
    #if ((FLS_FLASH_AR_RELEASE_MAJOR_VERSION    != FLS_AR_RELEASE_MAJOR_VERSION) || \
         (FLS_FLASH_AR_RELEASE_MINOR_VERSION    != FLS_AR_RELEASE_MINOR_VERSION) \
        )
        #error "AutoSar Version Numbers of Fls_Flash.h and Fls.h are different"
    #endif
#endif

/* Check if current file and Fls_Types.h header file are of the same vendor */
#if (FLS_FLASH_VENDOR_ID != FLS_TYPES_VENDOR_ID)
    #error "Fls_Flash.h and Fls_Types.h have different vendor ids"
#endif
/* Check if current file and Fls_Types.h header file are of the same Software version */
#if ((FLS_FLASH_SW_MAJOR_VERSION != FLS_TYPES_SW_MAJOR_VERSION) || \
     (FLS_FLASH_SW_MINOR_VERSION != FLS_TYPES_SW_MINOR_VERSION) || \
     (FLS_FLASH_SW_PATCH_VERSION != FLS_TYPES_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of Fls_Flash.h and Fls_Types.h are different"
#endif
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if current file and Fls_Types.h header file are of the same Autosar version */
    #if ((FLS_FLASH_AR_RELEASE_MAJOR_VERSION != FLS_TYPES_AR_RELEASE_MAJOR_VERSION) || \
         (FLS_FLASH_AR_RELEASE_MINOR_VERSION != FLS_TYPES_AR_RELEASE_MINOR_VERSION) \
        )
        #error "AutoSar Version Numbers of Fls_Flash.h and Fls_Types.h are different"
    #endif
#endif

/* Check if current file and Fls_Flash_Types.h header file are of the same vendor */
#if (FLS_FLASH_VENDOR_ID != FLS_FLASH_TYPES_VENDOR_ID)
    #error "Fls_Flash.h and Fls_Flash_Types.h have different vendor ids"
#endif
/* Check if current file and Fls_Flash_Types.h header file are of the same Software version */
#if ((FLS_FLASH_SW_MAJOR_VERSION != FLS_FLASH_TYPES_SW_MAJOR_VERSION) || \
     (FLS_FLASH_SW_MINOR_VERSION != FLS_FLASH_TYPES_SW_MINOR_VERSION) || \
     (FLS_FLASH_SW_PATCH_VERSION != FLS_FLASH_TYPES_SW_PATCH_VERSION) \
    )
    #error "Software Version Numbers of Fls_Flash.hc and Fls_Flash_Types.h are different"
#endif
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if current file and Dem header file are of the same Autosar version */
    #if ((FLS_FLASH_AR_RELEASE_MAJOR_VERSION != FLS_FLASH_TYPES_AR_RELEASE_MAJOR_VERSION) || \
         (FLS_FLASH_AR_RELEASE_MINOR_VERSION != FLS_FLASH_TYPES_AR_RELEASE_MINOR_VERSION) \
        )
        #error "AutoSar Version Numbers of Fls_Flash.h and Fls_Flash_Types.h are different"
    #endif
#endif 
#if ( (FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON) && (STD_OFF == FLS_TIMEOUT_AS_LOOP) )
/* Check if current file and Os.h header file are of the same Autosar version */
#if ((FLS_FLASH_AR_RELEASE_MAJOR_VERSION    != OS_AR_RELEASE_MAJOR_VERSION) || \
     (FLS_FLASH_AR_RELEASE_MINOR_VERSION    != OS_AR_RELEASE_MINOR_VERSION) \
    )
    #error "AutoSar Version Numbers of Os.h and Fls_Flash.h are different"
#endif
#endif /*#if ( (FLS_TIMEOUT_SUPERVISION_ENABLED == STD_ON) && (STD_OFF == FLS_TIMEOUT_AS_LOOP) )*/
/*==================================================================================================
*                                      DEFINES AND MACROS
==================================================================================================*/
#if (STD_ON == FLS_INTERNAL_FLASH_AVAILABLE)
#if (STD_ON == FLS_INTERNAL_SECTORS_CONFIGURED)
#ifdef MCAL_PLATFORM_ARM
#define FLASH_ARM_FAR_CALL2THUMB_CODE_BIT0_U32 (0x00000001UL)
    /* Macro for Access Code Call. On ARM/Thumb, BLX instruction used by the compiler for calling a function
       pointed to by the pointer requires that LSB bit of the address is set to one if the called fcn is coded in Thumb. */ 
    /* @violates @ref Fls_Flash_h_REF_2 Function-like macro defined */
    #define FLASH_AC_CALL(ptr2fcn, ptr2fcnType) ((ptr2fcnType)(((uint32)(ptr2fcn)) | FLASH_ARM_FAR_CALL2THUMB_CODE_BIT0_U32))
#else
    /* @violates @ref Fls_Flash_h_REF_2 Function-like macro defined */
    #define FLASH_AC_CALL(ptr2fcn, ptr2fcnType) (ptr2fcn)
#endif
#endif /*(STD_ON == FLS_INTERNAL_SECTORS_CONFIGURED)*/
#endif /*(STD_ON == FLS_INTERNAL_FLASH_AVAILABLE)*/
/*==================================================================================================
*                                      GLOBAL VARIABLES
==================================================================================================*/

#define FLS_START_SEC_VAR_INIT_32
/* @violates @ref Fls_Flash_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"

#define FLS_STOP_SEC_VAR_INIT_32
/* @violates @ref Fls_Flash_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"

/*==================================================================================================
                                       FUNCTION PROTOTYPES
==================================================================================================*/
#if (STD_ON == FLS_INTERNAL_FLASH_AVAILABLE)
#if (STD_ON == FLS_INTERNAL_SECTORS_CONFIGURED)
#define FLS_START_SEC_CODE
/* @violates @ref Fls_Flash_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"

FUNC( void, FLS_CODE ) Fls_Flash_Init( void );
FUNC( Fls_LLDReturnType, FLS_CODE ) Fls_Flash_AbortSuspended( VAR( uint8, AUTOMATIC) u8ServiceID );
#if (FLS_CANCEL_API == STD_ON )
FUNC( void, FLS_CODE ) Fls_Flash_Cancel( void );
#endif   /* FLS_CANCEL_API == STD_ON */
FUNC( Fls_LLDReturnType, FLS_CODE ) Fls_Flash_SectorErase
(
    CONST( Fls_PhysicalSectorType, AUTOMATIC) ePhySector,
#if( (FLS_ERASE_VERIFICATION_ENABLED == STD_ON) || (STD_ON == FLS_SYNCRONIZE_CACHE) )
    CONST( Fls_LengthType, AUTOMATIC) u32PhysicalSectorSize,
#endif    /* FLS_ERASE_VERIFICATION_ENABLED == STD_ON */
    CONST( boolean, AUTOMATIC) bAsynch
);
FUNC( Fls_LLDReturnType, FLS_CODE ) Fls_Flash_SectorWrite
(
    CONST( Fls_PhysicalSectorType, AUTOMATIC) ePhySector,
    CONST(Fls_AddressType, AUTOMATIC) u32SectorOffset,
    CONST(Fls_LengthType, AUTOMATIC) u32DataLength,
    CONSTP2CONST(uint8, AUTOMATIC, FLS_APPL_CONST) pDataPtr,
    CONST( boolean, AUTOMATIC) bAsynch
);
FUNC( Fls_LLDReturnType, FLS_CODE ) Fls_Flash_SectorRead
(
    CONST( Fls_PhysicalSectorType, AUTOMATIC) ePhySector,
    CONST(Fls_AddressType, AUTOMATIC) u32SectorOffset,
    VAR(Fls_LengthType, AUTOMATIC) u32DataLength,
    P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) pDataPtr
);
#if(( FLS_COMPARE_API == STD_ON ) || ( FLS_BLANK_CHECK_API == STD_ON ))
FUNC( Fls_LLDReturnType, FLS_CODE ) Fls_Flash_SectorCompare
(
    CONST( Fls_PhysicalSectorType, AUTOMATIC) ePhySector,
    CONST(Fls_AddressType, AUTOMATIC) u32SectorOffset,
    VAR(Fls_LengthType, AUTOMATIC) u32DataLength,
    P2CONST(uint8, AUTOMATIC, FLS_APPL_CONST) pDataPtr
);
#endif
FUNC( void, FLS_CODE ) Fls_Flash_MainFunctionErase( void );
FUNC( void, FLS_CODE ) Fls_Flash_MainFunctionWrite( void );
#if( FLS_ERASE_VERIFICATION_ENABLED == STD_ON )
FUNC( void, FLS_CODE ) Fls_Flash_MainFunctionEraseBlankCheck( void );
#endif
#define FLS_STOP_SEC_CODE
/* @violates @ref Fls_Flash_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"
   
#endif /*(STD_ON == FLS_INTERNAL_SECTORS_CONFIGURED)*/
#endif /*(STD_ON == FLS_INTERNAL_FLASH_AVAILABLE)*/
#ifdef __cplusplus
}
#endif

#endif /* FLS_FLASH_H */

/** @}*/
