/*!
 * @file        bsp_flash.h
 *
 * @brief       Header for bsp_flash.c module
 *
 * @version     V1.0.1
 *
 * @date        2023-03-31
 *
 * @attention
 *
 *  Copyright (C) 2023 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  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 SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

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

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

/** @addtogroup Examples
  @{
*/

/** @addtogroup BootLoader
  @{
*/

/** @addtogroup BSP_FLASH
  @{
*/

/** @defgroup BSP_FLASH_Macros Macros
  @{
*/

#define FLASH_BASE                  (uint32_t)0x0000

/* 1 Kbytes */
#define FLASH_PAGE_SIZE             (uint32_t)0x400
#if defined (__CC_ARM)|| (__ICCARM__)

#define USER_APP1_ADDRESS           (uint32_t)0x4000
/* 8 KBytes */
#define USER_APP1_END_ADDRESS       (uint32_t)0x6000

#define USER_APP2_ADDRESS           (uint32_t)0x6000
/* 8 KBytes */
#define USER_APP2_END_ADDRESS       (uint32_t)0x7FFF

#else

#define USER_APP1_ADDRESS           (uint32_t)0x5000
/* 8 KBytes */
#define USER_APP1_END_ADDRESS       (uint32_t)0x6800

#define USER_APP2_ADDRESS           (uint32_t)0x6800
/* 8 KBytes */
#define USER_APP2_END_ADDRESS       (uint32_t)0x7FFF

#endif

#define USER_APP1_FLASH_SIZE        (USER_APP1_END_ADDRESS - USER_APP1_ADDRESS + 1)

#define USER_APP2_FLASH_SIZE        (USER_APP2_END_ADDRESS - USER_APP2_ADDRESS + 1)

#define USER_FLASH_SIZE             (USER_APP2_END_ADDRESS - USER_APP1_ADDRESS + 1)

/**@} end of group BSP_FLASH_Macros */

/** @defgroup BSP_FLASH_Enumerations Enumerations
  @{
*/

/*!
 * @brief    APP type define
 */
typedef enum
{
  APP1 = 0,
  APP2 = 1
} APP_TypeDef;

/**@} end of group BSP_FLASH_Enumerations */

/** @defgroup BSP_FLASH_Functions Functions
  @{
*/

/* function declaration*/
uint32_t FLASH_IAP_Erase(APP_TypeDef Application);
void FLASH_IAP_Init(void);
uint32_t FLASH_IAP_Write(__IO uint32_t* address, uint32_t* data, uint16_t length, APP_TypeDef Application);

/**@} end of group BSP_FLASH_Functions */
/**@} end of group BSP_FLASH */
/**@} end of group BootLoader */
/**@} end of group Examples */

#endif
