/*!
* @file     Fls_Fmc.h
*
* @version  1.0.0
*
* @brief    Header file of FLASH FMC 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_FLASH_H
#define FLS_FLASH_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Fls.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_FLASH_H_VENDOR_ID                        0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define FLS_FLASH_H_MODULE_ID                        0x005CU
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_FLASH_H_AR_RELEASE_MAJOR_VERSION         0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_FLASH_H_AR_RELEASE_MINOR_VERSION         0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define FLS_FLASH_H_AR_RELEASE_REVISION_VERSION      0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_FLASH_H_SW_MAJOR_VERSION                 0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_FLASH_H_SW_MINOR_VERSION                 0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define FLS_FLASH_H_SW_PATCH_VERSION                 0x00U

/**@} end of group FLS_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
/* Make sure the vendor id is the same between Fls_Fmc.h and Fls.h */
#if (FLS_FLASH_H_VENDOR_ID != FLS_H_VENDOR_ID)
    #error "Vendor id mismatch between Fls_Fmc.h and Fls.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Fls_Fmc.h and Fls.h */
#if (FLS_FLASH_H_AR_RELEASE_MAJOR_VERSION != FLS_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Fls_Fmc.h and Fls.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Fls_Fmc.h and Fls.h */
#if (FLS_FLASH_H_AR_RELEASE_MINOR_VERSION != FLS_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Fls_Fmc.h and Fls.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Fls_Fmc.h and Fls.h */
#if (FLS_FLASH_H_AR_RELEASE_REVISION_VERSION != FLS_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Fls_Fmc.h and Fls.h"
#endif
/* Make sure the software major version number is the same between Fls_Fmc.h and Fls.h */
#if (FLS_FLASH_H_SW_MAJOR_VERSION != FLS_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Fls_Fmc.h and Fls.h"
#endif
/* Make sure the software minor version number is the same between Fls_Fmc.h and Fls.h */
#if (FLS_FLASH_H_SW_MINOR_VERSION != FLS_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Fls_Fmc.h and Fls.h"
#endif
/* Make sure the software patch version number is the same between Fls_Fmc.h and Fls.h */
#if (FLS_FLASH_H_SW_PATCH_VERSION != FLS_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Fls_Fmc.h and Fls.h"
#endif

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

#ifdef MCAL_PLATFORM_ARM
    #define FLS_ARM_FAR_CALL_TO_THUMB_CODE_BIT0   (0x00000001UL)
    /** Used for flash access code routine.
    *   On ARM/Thumb, BLX instruction used by the compiler for calling a function by the pointer requires that
    *   LSB bit of the address is set to one if the called fcn is coded in Thumb.
    */
    #define FLS_ACCESSCODE_CALL(ptr2fcn, ptr2fcnType) \
                              ((ptr2fcnType)(((uint32)(ptr2fcn))|FLS_ARM_FAR_CALL_TO_THUMB_CODE_BIT0))
#else
    #define FLS_ACCESSCODE_CALL(ptr2fcn, ptr2fcnType) (ptr2fcn)
#endif

/** Flash and option byte unlock key */
#define FMC_KEY_1             (0x45670123U)
#define FMC_KEY_2             (0xCDEF89ABU)

/**@} end of group FLS_Macros */

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

/** @defgroup FLS_Variable
  @{
*/

/** flash job result */
extern VAR(volatile MemIf_JobResultType, FLS_VAR) g_jobResult;
/** Pointer to flash configuration */
extern P2CONST(Fls_ConfigType, FLS_VAR, FLS_APPL_CONST) g_flsConfigPtr;

/**@} 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_CANCEL_API_EN )
FUNC(void, FLS_CODE) Fls_FMC_Cancel(void);
#endif

FUNC(Fls_LLDResultType, FLS_CODE) Fls_FMC_Read( CONST(Fls_AddressType, AUTOMATIC) readByteOffset,
                                                    VAR(Fls_LengthType, AUTOMATIC) DataLen,
                                                  P2VAR(uint8, AUTOMATIC, FLS_APPL_DATA) DataPtr );

FUNC(void, FLS_CODE) Fls_FMC_Init(void);

#if( STD_ON == FLS_BLANKCHECK_API_EN )
FUNC(Fls_LLDResultType, FLS_CODE) Fls_FMC_BlankCheck( CONST(Fls_AddressType, AUTOMATIC) blankcheckByteOffset,
                                                          VAR(Fls_LengthType, AUTOMATIC) DataLen);
#endif

#if( STD_ON == FLS_COMPARE_API_EN )
FUNC(Fls_LLDResultType, FLS_CODE) Fls_FMC_Compare( CONST(Fls_AddressType, AUTOMATIC) compareByteOffset,
                                                       VAR(Fls_LengthType, AUTOMATIC) DataLen,
                                              CONSTP2CONST(uint8, AUTOMATIC, FLS_APPL_CONST) DataPtr);
#endif

FUNC( Fls_LLDResultType, FLS_CODE ) Fls_FMC_Write ( CONST(Fls_AddressType, AUTOMATIC) writeByteOffset,
                                                        VAR(Fls_LengthType, AUTOMATIC) DataLen,
                                               CONSTP2CONST(uint8, AUTOMATIC, FLS_APPL_CONST) DataPtr );

FUNC( Fls_LLDResultType, FLS_CODE ) Fls_FMC_Erase(void);

#if(STD_ON == FLS_WRITE_OPTION_BYTE_API_EN)
FUNC(void, FLS_CODE) Fls_FMC_WriteOptionByte( CONSTP2CONST(uint32, AUTOMATIC, FLS_APPL_CONST) DataPtr );
#endif

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

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

/**@} 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 */
