/*!
* @file     Fls_FmcTypes.h
*
* @version  1.0.0
*
* @brief    Data Type Definition File for the FLS Module Based on FMC IP
*
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_01-Otc-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

#ifndef FLS_FMC_TYPES_H
#define FLS_FMC_TYPES_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Std_Types.h"
#include "Fls_FmcReg.h"

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup FLS_Driver
  * @brief FLS driver modules
  @{
*/

/** @defgroup FLS_Macros
  @{
*/
/**************************************************************************
                  VENDOR ID & AUTOSAR VERSION INFO
**************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define FLS_FMC_TYPES_H_VENDOR_ID                        0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define FLS_FMC_TYPES_H_MODULE_ID                        0x005CU
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_FMC_TYPES_H_AR_RELEASE_MAJOR_VERSION         0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_FMC_TYPES_H_AR_RELEASE_MINOR_VERSION         0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_FMC_TYPES_H_AR_RELEASE_REVISION_VERSION      0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_FMC_TYPES_H_SW_MAJOR_VERSION                 0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_FMC_TYPES_H_SW_MINOR_VERSION                 0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_FMC_TYPES_H_SW_PATCH_VERSION                 0x00U

/**@} end of group FLS_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Fls_FmcTypes.h and Std_Types.h */
    #if (FLS_FMC_TYPES_H_AR_RELEASE_MAJOR_VERSION != STD_TYPES_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR Major Version Number mismatch between Fls_FmcTypes.h and Std_Types.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Fls_FmcTypes.h and Std_Types.h */
    #if (FLS_FMC_TYPES_H_AR_RELEASE_MINOR_VERSION != STD_TYPES_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR Minor Version Number mismatch between Fls_FmcTypes.h and Std_Types.h"
    #endif
#endif

/* Make sure the vendor id is the same between Fls_FmcTypes.h and Fls_FmcReg.h */
#if (FLS_FMC_TYPES_H_VENDOR_ID != FLS_FMC_REG_H_VENDOR_ID)
    #error "Vendor id mismatch between Fls_FmcTypes.h and Fls_FmcReg.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Fls_FmcTypes.h and Fls_FmcReg.h */
#if (FLS_FMC_TYPES_H_AR_RELEASE_MAJOR_VERSION != FLS_FMC_REG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Fls_FmcTypes.h and Fls_FmcReg.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Fls_FmcTypes.h and Fls_FmcReg.h */
#if (FLS_FMC_TYPES_H_AR_RELEASE_MINOR_VERSION != FLS_FMC_REG_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Fls_FmcTypes.h and Fls_FmcReg.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Fls_FmcTypes.h and Fls_FmcReg.h */
#if (FLS_FMC_TYPES_H_AR_RELEASE_REVISION_VERSION != FLS_FMC_REG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Fls_FmcTypes.h and Fls_FmcReg.h"
#endif
/* Make sure the software major version number is the same between Fls_FmcTypes.h and Fls_FmcReg.h */
#if (FLS_FMC_TYPES_H_SW_MAJOR_VERSION != FLS_FMC_REG_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Fls_FmcTypes.h and Fls_FmcReg.h"
#endif
/* Make sure the software minor version number is the same between Fls_FmcTypes.h and Fls_FmcReg.h */
#if (FLS_FMC_TYPES_H_SW_MINOR_VERSION != FLS_FMC_REG_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Fls_FmcTypes.h and Fls_FmcReg.h"
#endif
/* Make sure the software patch version number is the same between Fls_FmcTypes.h and Fls_FmcReg.h */
#if (FLS_FMC_TYPES_H_SW_PATCH_VERSION != FLS_FMC_REG_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Fls_FmcTypes.h and Fls_FmcReg.h"
#endif

/**************************************************************************
                    ENUMERATION DEFINITION
**************************************************************************/
/** @defgroup FLS_Enumerations
  @{
*/

/**
 * @brief    Used to description the flash operation result.
 */
typedef enum
{
    FLS_E_OK                  =  0U,  //!< operation ok
    FLS_E_FAILED              =  1U,  //!< operation failed due to hardware error
    FLS_E_BLOCK_INCONSISTENT  =  2U,  //!< Compare operation: data buffer is different with content of flash memory
    FLS_E_PENDING             =  3U   //!< operation is pending
} Fls_LLDResultType;

/**
 * @brief    Currently job operation type used for Fls_MainFunction
 */
typedef enum
{
    JOB_TO_ERASE        =  0U,   //!< operation: erase one or more complete flash sectors
    JOB_TO_WRITE        =  1U,   //!< operation: write data to flash page
    JOB_TO_READ         =  2U,   //!< operation: read bytes from flash
    JOB_TO_COMPARE      =  3U,   //!< operation: compare data buffer with content of appointed flash memory
    JOB_TO_CHECK_BLANK  =  4U    //!< operation: Check if the flash content is 0xFF
} Fls_JobOpnType;

/**
 * @brief    Erase flash type
 */
typedef enum
{
    ONLY_EARSE_PFLASH    =  0U,   //!< only erase pflash
    ONLY_EARSE_DFLASH    =  1U,   //!< only erase dflash
    EARSE_PFLASH_DFLASH  =  2U    //!< erase pflash and dflash
} Fls_EraseFlashType;

/**
 * @brief    option byte register id
 */
typedef enum
{
    OPTBYTE_READPORT_REG =  0x1FFFF800U,
    OPTBYTE_UOB_REG      =  0x1FFFF802U,
    OPTBYTE_DATA0_REG    =  0x1FFFF804U,
    OPTBYTE_DATA1_REG    =  0x1FFFF806U,
    OPTBYTE_WRP0_REG     =  0x1FFFF808U,
    OPTBYTE_WRP1_REG     =  0x1FFFF80AU,
    OPTBYTE_WRP2_REG     =  0x1FFFF80CU,
    OPTBYTE_WRP3_REG     =  0x1FFFF80EU,
    OPTBYTE_WRP4_REG     =  0x1FFFF810U,
    OPTBYTE_WRP5_REG     =  0x1FFFF812U,
    OPTBYTE_WRP6_REG     =  0x1FFFF814U,
    OPTBYTE_WRP7_REG     =  0x1FFFF816U 
} Fls_OptByteReadRegIdType;


/**
 * @brief    irq error types
 */
typedef enum
{
    FLS_IRQ_ERROR_PEF   =  0U,
    FLS_IRQ_ERROR_PAEF  =  1U,
    FLS_IRQ_ERROR_WPEF  =  2U,
    FLS_IRQ_ERROR_OCF   =  3U,
    FLS_IRQ_ERROR_ECC   =  4U
} Fls_IrqErrorType;

/**@} end of group FLS_Enumerations */
/**************************************************************************
                    OTHER TYPE DEFINITION
**************************************************************************/
/** @defgroup FLS_Structure
  @{
*/

/** Used to descript the Pointer type of write access code API */
typedef P2FUNC( void, FLS_CODE, Fls_OffAcWritePtrType) (CONST(uint32, AUTOMATIC) BaseAddr, P2FUNC(void, FLS_CODE, CallBackPtr)(void));
typedef P2FUNC( void, FLS_CODE, Fls_OnAcWritePtrType)
        (CONST(uint32, AUTOMATIC) BaseAddr, P2FUNC(void, FLS_CODE, CallBackPtr)(void), P2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) TimerCntrACPtr);
/** Used to descript the Pointer type of FlsJobEndNotification API */
typedef P2FUNC(void, FLS_CODE, Fls_JobEndNotifyPtrType)(void);
/** Physical flash Length type, used to read, write, erase, compare */
typedef uint32 Fls_LengthType;
/** Used to descript the type of data bus width */
typedef uint32 Fls_DataWidthType;
/** Used to descript the Pointer type of Fls Finished Flash Access Notification API */
typedef P2FUNC(void, FLS_CODE, Fls_EndFlsAccessNotifyPtrType)(void);
/** Physical flash sectors type */
typedef uint32 Fls_SectorIdxType;
/** Physical flash Sector Count type */
typedef uint32 Fls_SectorCntType;
/** Used to descript the Pointer type of FlsStartAccessNotification API */
typedef P2FUNC(void, FLS_CODE, Fls_StartFlsAccessNotifyPtrType)(void);
/** Used to descript the Pointer type of instruction that generated the ECC */
typedef const uint8 * Fls_InsAddrPtrType;
/** Used to descript the Pointer type of Fls_AC Callback API */
typedef P2FUNC(void, FLS_CODE, Fls_AC_CBPtrType) (void);
/** Used to descript the Pointer type of data address that caused the ECC error */
typedef const void * Fls_DataAddrPtrType;
/** Used to descript the return value of Fls handler API.
*   FLS_HANDLEDSTS_UN, FLS_HANDLEDSTS_RETRY, FLS_HANDLEDSTS_SKIP, FLS_HANDLEDSTS_STOP 
*/
typedef uint8_least Fls_HandlerRetType;
/** Used to descript the Pointer type of FlsJobErrorNotification API */
typedef P2FUNC(void, FLS_CODE, Fls_JobErrorNotifyPtrType)(void);
/** Physical flash Address type */
typedef uint32 Fls_AddressType;
/** Used to descript the Pointer type of erase access code API */
typedef P2FUNC(void, FLS_CODE, Fls_OffAcErasePtrType) (CONST(uint32, AUTOMATIC) BaseAddr, 
        P2FUNC(void, FLS_CODE, CallBackPtr)(void));
typedef P2FUNC(void, FLS_CODE, Fls_OnAcErasePtrType) (CONST(uint32, AUTOMATIC) BaseAddr, 
        P2FUNC(void, FLS_CODE, CallBackPtr)(void), P2VAR(uint32, AUTOMATIC, FLS_APPL_DATA) TimerCntrACPtr );

/**@} end of group FLS_Structure */

/**************************************************************************
                    MACRO DEFINITION
**************************************************************************/
/** @defgroup FLS_Macros
  @{
*/

/** Define the return value for Fls_DsiHandler */
/** module doesn't handle */
#define FLS_HANDLEDSTS_UN        ((Fls_HandlerRetType)0U)
/** module handle retry */
#define FLS_HANDLEDSTS_RETRY     ((Fls_HandlerRetType)1U)
/** module handle skip, current job failed */
#define FLS_HANDLEDSTS_SKIP      ((Fls_HandlerRetType)2U)
/** module handle stop the system */
#define FLS_HANDLEDSTS_STOP      ((Fls_HandlerRetType)3U)

/**@} end of group FLS_Macros */

/**************************************************************************
                    STRUCT DEFINITION
**************************************************************************/
/** @defgroup FLS_Structure
  @{
*/

/** 
 * @brief    Used to descript the detailed information on the exception.
 *           insPtr         It matches address currently accessed ECC.
 *           dataAddrPtr    It matches address currently accessed by pending flash read or flash compare job.
 *           syndrome       Indicates DSI or MCI reason.
 */
typedef struct
{
    Fls_InsAddrPtrType insPtr;       //!< pointer to the instruction Address that generated the ECC
    Fls_DataAddrPtrType dataAddrPtr; //!< pointer to data address that caused the ECC error
    uint32 syndrome;                 //!< details exception type
} Fls_ExcDetailsType;

/** 
 * @brief    Used to descript the type of internal FLASH physical sector
 */
typedef struct
{
    P2VAR(volatile uint32, FLS_VAR, FLS_APPL_DATA) sectorStartAddrPtr; //!< Sector start address 
    uint32 sectorId; //!< Sector ID
} Fls_IntlSectorInfoType;

typedef const Fls_ExcDetailsType *Fls_ExceptionDetailsPtrType;

/**@} end of group FLS_Structure */

#ifdef __cplusplus
}
#endif

#endif

/**@} end of group FLS_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
