/**
*   @file    Fls_Types.h  
*   @implements Fls_Types.h_Artifact 
*   @version 1.0.0
*
*   @brief   AUTOSAR Fls - AUTOSAR Module Flash Driver.
*   @details Definitions of all Flash driver 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_TYPES_H
#define FLS_TYPES_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_Type_h_REF_1
* Violates MISRA 2012 Advisory Rule 2.3, A project should not contain unused type declaration.
* This type may be called in user or support for multi IPV
*/

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

/*==================================================================================================
*                              SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define FLS_TYPES_VENDOR_ID                    43
#define FLS_TYPES_AR_RELEASE_MAJOR_VERSION     4
#define FLS_TYPES_AR_RELEASE_MINOR_VERSION     3
#define FLS_TYPES_AR_RELEASE_REVISION_VERSION  1
#define FLS_TYPES_SW_MAJOR_VERSION             1
#define FLS_TYPES_SW_MINOR_VERSION             0
#define FLS_TYPES_SW_PATCH_VERSION             0
/*==================================================================================================
                                      FILE VERSION CHECKS
==================================================================================================*/
#ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
    /* Check if current file and Std_Types.h file are of the same version */
    #if ((FLS_TYPES_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
         (FLS_TYPES_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION)\
        )
        #error "AutoSar Version Numbers of Fls_Types.h and Std_Types.h are different"
    #endif
#endif

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

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

/*==================================================================================================
                                 STRUCTURES AND OTHER TYPEDEFS
==================================================================================================*/
/**
    @brief Physical flash sectors type, unique identifier for each configured sector.
*/
typedef uint32 Fls_PhysicalSectorType;

/**
    @brief Flash sector channel type.
*/
typedef enum
{
    FLS_CH_INTERN = 0,
    FLS_CH_QSPI = 1
} Fls_HwChType;

/**
* @brief          Type of job currently executed by Fls_MainFunction.
*/
typedef enum
{
    /**
    * @brief erase one or more complete flash sectors
    */
    FLS_JOB_ERASE = 0,    
    /**
    * @brief write one or more complete flash pages 
    */
    FLS_JOB_WRITE,        
    /**
    * @brief read one or more bytes from flash memory 
    */
    FLS_JOB_READ,     
    /**
    * @brief compare data buffer with content of flash memory
    */
    FLS_JOB_COMPARE,
    /**
    * @brief check content of erased flash memory area
    */
    FLS_JOB_BLANK_CHECK
} Fls_JobType;


/**
* @brief          Result of low-level flash operation.
*/
typedef enum 
{
    FLASH_E_OK = 0,                 /**< @brief operation succeeded */
    FLASH_E_FAILED,                 /**< @brief operation failed due to hardware error */
    FLASH_E_BLOCK_INCONSISTENT,     /**< @brief data buffer doesn't match with content of flash memory */
    FLASH_E_PENDING,                /**< @brief operation is pending */
    FLASH_E_PARTITION_ERR           /**< @brief FlexNVM partition ratio error */
} Fls_LLDReturnType;

/**
* @brief          Type of job currently executed by Fls_LLDMainFunction.
*/
typedef enum
{
    /**
    * @brief no job executed by Fls_LLDMainFunction 
    */    
    FLASH_JOB_NONE = 0, 
    /**
    * @brief erase one flash sector 
    */    
    FLASH_JOB_ERASE, 
    /**
    * @brief complete erase and start an interleaved erase flash sector 
    */
    FLASH_JOB_ERASE_TEMP,
    /**
    * @brief write one or more complete flash pages 
    */
    FLASH_JOB_WRITE, 
    /**
    * @brief erase blank check of flash sector
    */    
    FLASH_JOB_ERASE_BLANK_CHECK 
    
} Fls_LLDJobType;

/**
* @brief    Type of job executed in interrupt context.
*/
typedef enum
{
    /**
    * @brief no job scheduled to be executed in interrupt context 
    */    
    FLASH_IRQ_JOB_NONE = 0, 
    /**
    * @brief read one or more flash bytes, in interrupt context.
    */    
    FLASH_IRQ_JOB_READ, 
    /**
    * @brief read and compare one or more flash bytes, in interrupt context.
    */    
    FLASH_IRQ_JOB_COMPARE, 
    /**
    * @brief read and compare against erased value one or more flash bytes, in interrupt context.
    */    
    FLASH_IRQ_JOB_BLANK_CHECK,
    /**
    * @brief erase one flash sector, in interrupt context. 
    */    
    FLASH_IRQ_JOB_ERASE, 
    /**
    * @brief read the external memory status, in interrupt context. 
    */
    FLASH_IRQ_JOB_GET_STATUS, 
    /**
    * @brief read the external memory status for the parallel device, in interrupt context. 
    */
    FLASH_IRQ_JOB_GET_STATUS_PAR, 
    /**
    * @brief send the first sequence of the hyperflash get status command, enter read status register mode.
    */
    FLASH_IRQ_JOB_HYPER_GET_STATUS_1, 
    /**
    * @brief send the second sequence of the hyperflash get status command, read the status register.
    */
    FLASH_IRQ_JOB_HYPER_GET_STATUS_2,  
    /**
    * @brief send the first sequence of the hyperflash write command, write the first unlock sequence.
    */
    FLASH_IRQ_JOB_HYPER_WRITE_UNLOCK_1,  
    /**
    * @brief send the second sequence of the hyperflash write command, write the second unlock sequence.
    */
    FLASH_IRQ_JOB_HYPER_WRITE_UNLOCK_2,  
    /**
    * @brief send the third sequence of the hyperflash write command, write the word program command id.
    */
    FLASH_IRQ_JOB_HYPER_WRITE_WORD_ID,  
    /**
    * @brief send the forth sequence of the hyperflash write command, write the actual data.
    */
    FLASH_IRQ_JOB_HYPER_WRITE_WORD_DATA,
    /**
    * @brief set the write enable bit, in interrupt context.
    */
    FLASH_IRQ_JOB_WRITE_EN, 
    /**
    * @brief write one or more complete flash pages, in interrupt context.
    */
    FLASH_IRQ_JOB_WRITE
    
} Fls_LLDIrqJobType;

/**
* @brief          Size of data to be processeed by CRC.
*
* @implements     Fls_CrcDataSizeType_enumeration
*/
typedef enum 
{
    FLS_CRC_8_BITS = 0,
    FLS_CRC_16_BITS
} Fls_CrcDataSizeType;

/** 
    @brief Enumeration of physical flash sectors program size
*/
typedef enum
{
    FLS_WRITE_DOUBLE_WORD = 8U,
    FLS_WRITE_PAGE = 32U,
    FLS_WRITE_QUAD_PAGE = 128U,
    FLS_WRITE_128BYTES_PAGE = 128U,
    FLS_WRITE_256BYTES_PAGE = 256U,
    FLS_WRITE_512BYTES_PAGE = 512U
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */    
} Fls_ProgSizeType;
/**
* @brief the number of bytes uses to compare.    
*
*/
typedef enum
{
    FLS_SIZE_1BYTE = 1U,
    FLS_SIZE_4BYTE = 4U
} Fls_DataBytesType;
/**
* @brief          Logical sector index.
*/
typedef uint32 Fls_SectorIndexType;

/**
* @brief          Fls CRC Type.
* @details        CRC computed over config set.
* @implements     Fls_CrcType_typedef
*/
typedef uint16 Fls_CrcType;

/**
* @brief          Fls Address Type.
* @details        Address offset from the configured flash base address to access a certain flash 
*                 memory area.
* @implements     Fls_AddressType_typedef
*/
typedef uint32 Fls_AddressType;

/**
* @brief          Fls Length Type.
* @details        Number of bytes to read,write,erase,compare
* @implements     Fls_LengthType_typedef
*/
typedef uint32 Fls_LengthType;

/**
* @brief          Fls Sector Count Type
* @details        Number of configured sectors
*/
typedef uint32 Fls_SectorCountType;

/**
* @brief          Fls Multi Core Request Return Type.
* @details        The return value for the function requesting multi core access.
* 
*/
typedef enum 
{
    FLS_MCORE_ERROR = 0,
    FLS_MCORE_TIMEOUT,
    FLS_MCORE_PENDING,
    FLS_MCORE_GRANTED,
    FLS_MCORE_CANCELLED
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */     
} Fls_MCoreReqReturnType;

/**
* @brief          Fls Multi Core Job Priority.
* @details        The priority for current requested job. Used as a global flag, to mark 
*                 an erase or write job which needs to be executed with high priority.
* 
*/
typedef enum
{
    FLS_PRIO_NORMAL = 0,
    FLS_PRIO_HIGH
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */ 
} Fls_MCorePrioType;

/**
* @brief          Fls Multi Core hardware job status
* @details        The status of a multicore core flash job, in hardware. Used to determine
*                 if a flash job subject to multicore arbitration was started/suspended/aborted
*                 in hardware, in the flash controller. This can be used for example, to 
*                 clear a semaphore granted for erase directly, if the job was not actually started
*                 in hardware, instead of attempting to suspend it.
* 
*/
typedef enum
{
    FLS_MCORE_HW_JOB_IDLE = 0,
    FLS_MCORE_HW_JOB_STARTED,
    FLS_MCORE_HW_JOB_SUSPENDED,
    FLS_MCORE_HW_JOB_CANCELLED,
    FLS_MCORE_HW_JOB_ELEVATED
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */ 
} Fls_MCoreHwJobStatusType;

/**
* @brief          Fls Multi Core timeout notification jobs
* @details        The timeout notification specifies the job during which timeout occurred.
*
*/
typedef enum
{
    FLS_MCORE_TIMEOUT_ERASE = 0,
    FLS_MCORE_TIMEOUT_NORMAL_WRITE,
    FLS_MCORE_TIMEOUT_HIGH_PRIO_WRITE
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */ 
} Fls_MCoreTimeoutJobType;
/**
 * @brief Pointer type of Fls_AC_Callback function
*/
typedef P2FUNC( void, FLS_CODE, Fls_ACCallbackPtrType )  ( void );


/**
* @brief          Fls Job End Notification Pointer Type
* @details        Pointer type of Fls_JobEndNotification function
* @implements     Fls_JobEndNotificationPtrType_typedef
*/
typedef P2FUNC(void, FLS_CODE, Fls_JobEndNotificationPtrType)(void);

/**
* @brief          Fls Job Error Notification Pointer Type
* @details        Pointer type of Fls_JobErrorNotification function
* @implements     Fls_JobErrorNotificationPtrType_typedef
*/
typedef P2FUNC(void, FLS_CODE, Fls_JobErrorNotificationPtrType)(void);  


/**
* @brief          Fls Start Flash Access Notification Pointer Type
* @details        Pointer type of Fls_StartFlashAccessNotif function
*
*/
typedef P2FUNC(void, FLS_CODE, Fls_StartFlashAccessNotifPtrType)(void);

/**
* @brief          Fls Finished Flash Access Notification Pointer Type
* @details        Pointer type of Fls_FinishedFlashAccessNotif function
* 
*/
typedef P2FUNC(void, FLS_CODE, Fls_FinishedFlashAccessNotifPtrType)(void);  

/**
* @brief          Fls Multi Core Notification Pointer Type
* @details        Pointer type of Fls_MCoreTimeoutNotifPtrType function
* 
*/
typedef P2FUNC(void, FLS_CODE, Fls_MCoreTimeoutNotifPtrType)(VAR(Fls_MCoreTimeoutJobType, AUTOMATIC) eMCoreTimeoutJob); 

/** 
    @brief Define pointer type of erase access code function
*/
typedef P2FUNC( void, FLS_CODE, Fls_AcErasePtrTOType )    (
                                                                    CONST(uint32, AUTOMATIC) u32RegBaseAddr, 
                                                                    P2FUNC(void, FLS_CODE, CallBack)( void ), 
                                                                    P2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pTimerCounterAC, 
                                                                    P2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pTimerCounterAbort
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */
                                                                );
typedef P2FUNC( void, FLS_CODE, Fls_AcErasePtrNoTOType )  (
                                                                    CONST(uint32, AUTOMATIC) u32RegBaseAddr, 
                                                                    P2FUNC(void, FLS_CODE, CallBack)( void )
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */
                                                                );

/**
    @brief Define pointer type of write access code function
*/
typedef P2FUNC( void, FLS_CODE, Fls_AcWritePtrTOType )    (
                                                                    CONST(uint32, AUTOMATIC) u32RegBaseAddr, 
                                                                    P2FUNC(void, FLS_CODE, CallBack)( void ), 
                                                                    P2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pTimerCounterAC, 
                                                                    P2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) pTimerCounterAbort
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */
                                                                );
typedef P2FUNC( void, FLS_CODE, Fls_AcWritePtrNoTOType )  (
                                                                    CONST(uint32, AUTOMATIC) u32RegBaseAddr, 
                                                                    P2FUNC(void, FLS_CODE, CallBack)( void )
/* @violates @ref Fls_Type_h_REF_1 A project should not contain unused type declaration */
                                                                );                                 
#ifdef __cplusplus
}
#endif

#endif /* FLS_TYPES_H */

/** @}*/
