/*!
 * @file        bsp_flash.h
 *
 * @brief       Header for bsp_flash.c module
 *
 * @version     V1.0.0
 *
 * @date        2026-02-26
 *
 * @attention
 *
 *  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 useful 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.
 */

/* Define to prevent recursive inclusion */
#ifndef BSP_FLASH_H
#define BSP_FLASH_H

/* Includes */
#include "g32a10xx_fls.h"

/** @addtogroup Examples
  @{
  */

/** @addtogroup IAP_Examples
  @{
*/

/** @addtogroup IAP_BootLoader
  @{
  */

/** @defgroup IAP_BootLoader_Macros Macros
  @{
*/

#define FLASH_BASE                  (uint32_t)0x08000000

#define FLASH_PAGE_SIZE             ((uint16_t)0x200)

#define USER_APP1_START_ADDRESS     (uint32_t)0x0800B400
/* 8 KBytes */
#define USER_APP1_END_ADDRESS       (uint32_t)0x08024400
#define USER_APP1_FLASH_SIZE        (USER_APP1_END_ADDRESS - USER_APP1_START_ADDRESS)

#define USER_APP2_START_ADDRESS     (uint32_t)0x08024400
/* 8 KBytes */
#define USER_APP2_END_ADDRESS       (uint32_t)0x0803D400
#define USER_APP2_FLASH_SIZE        (USER_APP2_END_ADDRESS - USER_APP2_START_ADDRESS)

#define USER_FLASH_SIZE             (USER_APP2_END_ADDRESS - USER_APP1_START_ADDRESS)

#define APP1                        (0U)
#define APP2                        (1U)
/**@} end of group IAP_BootLoader_Macros */

/** @defgroup IAP_BootLoader_Enumerations Enumerations
  @{
  */

/* APP type define */
typedef uint8_t App_DefType;

/*!
 * @brief    FMC operation type define
 */
typedef enum
{
    FMC_OP_SUCCESS,
    FMC_OP_ERROR
} Fmc_OpType;

/**@} end of group IAP_BootLoader_Enumerations */

/** @defgroup IAP_BootLoader_Functions Functions
  @{
  */

/* function declaration*/
void Flash_IapInit(void);
uint32_t Flash_IapErase(App_DefType Application);
uint32_t Flash_IapWrite(__IO uint32_t* AddressPtr, const uint32_t* DataPtr, uint16_t Length, App_DefType Application);

/**@} end of group IAP_BootLoader_Functions */
/**@} end of group IAP_BootLoader */
/**@} end of group IAP_Examples */
/**@} end of group Examples */

#endif
