/*!
* @file     Fls.h
*
* @version  1.0.0
*
* @brief    Header file of AUTOSAR FLS driver
*
* @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_H
#define FLS_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Fls_Cfg.h"
#include "Mcal.h"
#include "Fls_SignatureTypes.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_H_VENDOR_ID                        0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define FLS_H_MODULE_ID                        0x005CU
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_H_AR_RELEASE_MAJOR_VERSION         0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_H_AR_RELEASE_MINOR_VERSION         0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_H_AR_RELEASE_REVISION_VERSION      0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_H_SW_MAJOR_VERSION                 0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_H_SW_MINOR_VERSION                 0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_H_SW_PATCH_VERSION                 0x00U

/**@} end of group FLS_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
/* Make sure the vendor id is the same between Fls.h and Fls_Cfg.h */
#if (FLS_H_VENDOR_ID != FLS_CFG_H_VENDOR_ID)
    #error "Vendor id mismatch between Fls.h and Fls_Cfg.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Fls.h and Fls_Cfg.h */
#if (FLS_H_AR_RELEASE_MAJOR_VERSION != FLS_CFG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Fls.h and Fls_Cfg.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Fls.h and Fls_Cfg.h */
#if (FLS_H_AR_RELEASE_MINOR_VERSION != FLS_CFG_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Fls.h and Fls_Cfg.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Fls.h and Fls_Cfg.h */
#if (FLS_H_AR_RELEASE_REVISION_VERSION != FLS_CFG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Fls.h and Fls_Cfg.h"
#endif
/* Make sure the software major version number is the same between Fls.h and Fls_Cfg.h */
#if (FLS_H_SW_MAJOR_VERSION != FLS_CFG_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Fls.h and Fls_Cfg.h"
#endif
/* Make sure the software minor version number is the same between Fls.h and Fls_Cfg.h */
#if (FLS_H_SW_MINOR_VERSION != FLS_CFG_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Fls.h and Fls_Cfg.h"
#endif
/* Make sure the software patch version number is the same between Fls.h and Fls_Cfg.h */
#if (FLS_H_SW_PATCH_VERSION != FLS_CFG_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Fls.h and Fls_Cfg.h"
#endif

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Fls.h and Mcal.h */
    #if (FLS_H_AR_RELEASE_MAJOR_VERSION != MCAL_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR Major Version Number mismatch between Fls.h and Mcal.h "
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Fls.h and Mcal.h */
    #if (FLS_H_AR_RELEASE_MINOR_VERSION != MCAL_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR Minor Version Number mismatch between Fls.h and Mcal.h "
    #endif
#endif

/* Make sure the vendor id is the same between Fls.h and Fls_SignatureTypes.h */
#if (FLS_H_VENDOR_ID != FLS_SIGNATURE_TYPES_H_VENDOR_ID)
    #error "Vendor id mismatch between Fls.h and Fls_SignatureTypes.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Fls.h and Fls_SignatureTypes.h */
#if (FLS_H_AR_RELEASE_MAJOR_VERSION != FLS_SIGNATURE_TYPES_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Fls.h and Fls_SignatureTypes.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Fls.h and Fls_SignatureTypes.h */
#if (FLS_H_AR_RELEASE_MINOR_VERSION != FLS_SIGNATURE_TYPES_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Fls.h and Fls_SignatureTypes.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Fls.h and Fls_SignatureTypes.h */
#if (FLS_H_AR_RELEASE_REVISION_VERSION != FLS_SIGNATURE_TYPES_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Fls.h and Fls_SignatureTypes.h"
#endif
/* Make sure the software major version number is the same between Fls.h and Fls_SignatureTypes.h */
#if (FLS_H_SW_MAJOR_VERSION != FLS_SIGNATURE_TYPES_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Fls.h and Fls_SignatureTypes.h"
#endif
/* Make sure the software minor version number is the same between Fls.h and Fls_SignatureTypes.h */
#if (FLS_H_SW_MINOR_VERSION != FLS_SIGNATURE_TYPES_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Fls.h and Fls_SignatureTypes.h"
#endif
/* Make sure the software patch version number is the same between Fls.h and Fls_SignatureTypes.h */
#if (FLS_H_SW_PATCH_VERSION != FLS_SIGNATURE_TYPES_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Fls.h and Fls_SignatureTypes.h"
#endif

/**************************************************************************
                    CONSTANT DEFINITION
**************************************************************************/
/** @defgroup FLS_Macros
  @{
*/

/** Instance identification ID for AUTOSAR module  */
#define FLS_INSTANCE_MODULE_ID         0x00U

/** AUTOSAR API service ID */
/** Fls_Init Service ID */
#define FLS_INIT_SVC_ID                ((uint8)0x00U)
/** Fls_Erase Service ID */
#define FLS_ERASE_SVC_ID               ((uint8)0x01U)
/** Fls_Write Service ID */
#define FLS_WRITE_SVC_ID               ((uint8)0x02U)
/** Fls_Cancel Service ID */
#define FLS_CANCEL_SVC_ID              ((uint8)0x03U)
/** Fls_GetStatus Service ID */
#define FLS_GETSTATUS_SVC_ID           ((uint8)0x04U)
/** Fls_GetJobResult Service ID */
#define FLS_GETJOBRESULT_SVC_ID        ((uint8)0x05U)
/** Fls_MainFunction Service ID */
#define FLS_MAINFUNCTION_SVC_ID        ((uint8)0x06U)
/** Fls_Read Service ID */
#define FLS_READ_SVC_ID                ((uint8)0x07U)
/** Fls_Compare Service ID */
#define FLS_COMPARE_SVC_ID             ((uint8)0x08U)
/** Fls_SetMode Service ID */
#define FLS_SETMODE_SVC_ID             ((uint8)0x09U)
/** Fls_GetVersionInfo Service ID */
#define FLS_GETVERSIONINFO_SVC_ID      ((uint8)0x0AU)
/** Fls_BlankCheck Service ID */
#define FLS_BLANKCHECK_SVC_ID          ((uint8)0x0BU)
/** Fls_WriteOptionByte Service ID */
#define FLS_WRITEOPTIONBYTE_SVC_ID     ((uint8)0x0CU)
/** Fls_ReadOptionByte Service ID */
#define FLS_READOPTIONBYTE_SVC_ID      ((uint8)0x0DU)
/** Fls_ErasePflashDflash Service ID */
#define FLS_ERASEPFLASHDFLASH_SVC_ID   ((uint8)0x0EU)
/** Fls_GetChipId Service ID */
#define FLS_GETCHIPID_SVC_ID           ((uint8)0x10U)
/** Fls_GetMemoryCapacity Service ID */
#define FLS_GETMEMORYCAPACITY_SVC_ID   ((uint8)0x11U)
/** Fls_GetChipProductSeries Service ID */
#define FLS_GETCHIPPRODUCTSERIES_SVC_ID   ((uint8)0x12U)

/** AUTOSAR Transient Faults */
/** Flash erase failed (HW) */
#define FLS_E_ERASE_FAILED             ((uint8)0x01U)
/** Flash write failed (HW) */
#define FLS_E_WRITE_FAILED             ((uint8)0x02U)
/** Flash read failed (HW) */
#define FLS_E_READ_FAILED              ((uint8)0x03U)
/** Flash compare failed (HW) */
#define FLS_E_COMPARE_FAILED           ((uint8)0x04U)
/** Expected hardware ID not matched */
#define FLS_E_UNEXPECTED_FLASH_ID      ((uint8)0x05U)

/** Development errors */
/** API service called with wrong configuration parameter */
#define FLS_E_PARAM_CONFIG             ((uint8)0x01U)
/** API service called with wrong address parameter */
#define FLS_E_PARAM_ADDRESS            ((uint8)0x02U)
/** API service called with wrong length parameter */
#define FLS_E_PARAM_LENGTH             ((uint8)0x03U)
/** API service called with wrong data parameter */
#define FLS_E_PARAM_DATA               ((uint8)0x04U)
/** API service called without module initialization */
#define FLS_E_UNINIT                   ((uint8)0x05U)
/** API service called while driver still busy */
#define FLS_E_BUSY                     ((uint8)0x06U)
/** Erase verification (blank check) failed */
#define FLS_E_VERIFY_ERASE_FAILED      ((uint8)0x07U)
/** Write verification (compare) failed */
#define FLS_E_VERIFY_WRITE_FAILED      ((uint8)0x08U)
/** Timeout exceeded */
#define FLS_E_TIMEOUT                  ((uint8)0x09U)
/** API service called with NULL pointer */
#define FLS_E_PARAM_POINTER            ((uint8)0x0AU)
/** Configured sector is protected */
#define FLS_E_PROTECTED_SECTOR         ((uint8)0x0BU)

/**@} end of group FLS_Macros */

/**************************************************************************
                    GLOBAL VARIABLE
**************************************************************************/
#define FLS_START_SEC_VAR_INIT_UNSPECIFIED
#include "Fls_MemMap.h"

/** @defgroup FLS_Variable
  @{
*/

/** Start sector ID to be erased */
extern VAR(Fls_SectorIdxType, FLS_VAR) g_EraseSectorStartId;
/** End sector ID to be erased */
extern VAR(Fls_SectorIdxType, FLS_VAR) g_EraseSectorEndId;

/** Current sector ID to be writted */
extern VAR(Fls_SectorIdxType, FLS_VAR) g_WriteCurSectorId;

/** Current sector ID to be read */
extern VAR(Fls_SectorIdxType, FLS_VAR) g_ReadCurSectorId;

#if( STD_ON == FLS_COMPARE_API_EN )
/** Current sector ID to be compared */
extern VAR(Fls_SectorIdxType, FLS_VAR) g_CompareCurSectorId;
#endif

#if( STD_ON == FLS_BLANKCHECK_API_EN )
/** Current sector ID to be blank checked */
extern VAR(Fls_SectorIdxType, FLS_VAR) g_BlankCheckCurSectorId;
#endif

/**@} end of group FLS_Variable */

#define FLS_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Fls_MemMap.h"

/**************************************************************************
                    FUNCTION DECLARATION
**************************************************************************/
#define FLS_START_SEC_CODE
#include "Fls_MemMap.h"

/** @defgroup FLS_Fuctions
  @{
*/

#if(STD_ON == FLS_DSIHANDLER_API_EN)
    extern FUNC(Fls_HandlerRetType, FLS_CODE) Fls_DsiHandler(void);
#endif

FUNC(void, FLS_CODE) Fls_MainFunction(void);

#if(STD_ON == FLS_VERSIONINFO_API_EN)
FUNC(void, FLS_CODE) Fls_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, FLS_APPL_DATA) VersioninfoPtr);
#endif

#if(STD_ON == FLS_SETMODE_API_EN)
FUNC(void, FLS_CODE) Fls_SetMode(VAR(MemIf_ModeType, AUTOMATIC) Mode);
#endif

#if (STD_ON == FLS_BLANKCHECK_API_EN)
FUNC(Std_ReturnType, FLS_CODE) Fls_BlankCheck(VAR(Fls_AddressType, AUTOMATIC) TargetAddress,
                                              VAR(Fls_LengthType, AUTOMATIC) Length);
#endif

#if(STD_ON == FLS_COMPARE_API_EN)
FUNC(Std_ReturnType, FLS_CODE) Fls_Compare (VAR(Fls_AddressType, AUTOMATIC) SourceAddress,
                                        P2CONST(uint8, AUTOMATIC, FLS_APPL_CONST) TargetAddressPtr,
                                            VAR(Fls_LengthType, AUTOMATIC) Length);
#endif

FUNC(Std_ReturnType, FLS_CODE) Fls_Read (VAR(Fls_AddressType, AUTOMATIC) SourceAddress,
                                       P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) TargetAddressPtr,
                                         VAR(Fls_LengthType, AUTOMATIC) Length);

#if(STD_ON == FLS_GETJOBRESULT_API_EN)
FUNC(MemIf_JobResultType, FLS_CODE) Fls_GetJobResult(void);
#endif

#if(STD_ON == FLS_GETSTATUS_API_EN)
FUNC(MemIf_StatusType, FLS_CODE) Fls_GetStatus(void);
#endif

#if(STD_ON == FLS_CANCEL_API_EN)
FUNC(void, FLS_CODE) Fls_Cancel(void);
#endif

FUNC(Std_ReturnType, FLS_CODE) Fls_Write(VAR(Fls_AddressType, AUTOMATIC) TargetAddress,
                                     P2CONST(uint8, AUTOMATIC, FLS_APPL_CONST) SourceAddressPtr,
                                         VAR(Fls_LengthType, AUTOMATIC) Length);

FUNC(Std_ReturnType, FLS_CODE) Fls_Erase(VAR(Fls_AddressType, AUTOMATIC) TargetAddress,
                                         VAR(Fls_LengthType, AUTOMATIC) Length);

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

#if(STD_ON == FLS_WRITE_OPTION_BYTE_API_EN)
FUNC(void, FLS_CODE) Fls_WriteOptionByte(P2CONST(uint32, AUTOMATIC, FLS_APPL_CONST) SourceAddressPtr);
#endif

FUNC(uint8, FLS_CODE) Fls_ReadOptionByte(VAR(Fls_OptByteReadRegIdType, AUTOMATIC) RegId);

#if(STD_ON == FLS_ERASE_PFLASH_DFLASH_API_EN)
FUNC(Std_ReturnType, FLS_CODE) Fls_ErasePflashDflash(VAR(Fls_EraseFlashType, AUTOMATIC) TargetFlash);
#endif

FUNC(void, FLS_CODE) Fls_GetChipId(P2VAR(Fls_ChipIdType, AUTOMATIC, FLS_APPL_DATA) ChipIdPtr);

FUNC(uint16, FLS_CODE) Fls_GetMemoryCapacity(VAR(Fls_InternalFlashType, AUTOMATIC) Memory);

FUNC(void, FLS_CODE) Fls_GetChipProductSeries(P2VAR(Fls_ChipProductSeriesType, AUTOMATIC, FLS_APPL_DATA) ChipSeriesPtr);

/**@} end of group FLS_Fuctions */

#define FLS_STOP_SEC_CODE
#include "Fls_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif

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