#ifndef __CALI_FLASH_H__
#define __CALI_FLASH_H__

#ifdef __cplusplus
 extern "C" {
#endif

#include "stm32f4xx.h"
#include "cali.h"

#define CALI_FLASH_STATE_EMPTY (0) /* only check first word as 0xFFFFFFFF */
#define CALI_FLASH_STATE_PURE  (1) /* check all word as 0xFFFFFFFF */
#define CALI_FLASH_STATE_WORK  (2) /* previous are addr and find an 0xFFFFFFFF  */
#define CALI_FLASH_STATE_FULL  (3) /* check all as addr */
#define CALI_FLASH_STATE_ERROR (4) /* error data structure */

/* reference for bootloader, partition.h */
#define ADDR_CALI0          (0x080C0000)
#define ADDR_CALI1          (0x080E0000)
#define SIZE_CALI_SECTOR    (128 * 1024)
#define SECTOR_CALI0        (FLASH_Sector_10)
#define SECTOR_CALI1        (FLASH_Sector_11)
#define CALI_FLASH_CALI_CNT (SIZE_CALI_SECTOR / CALI_FLASH_CALI_SIZE)
#define ADDR_CALI0_END      (ADDR_CALI0 + CALI_FLASH_CALI_CNT * CALI_FLASH_CALI_SIZE)
#define ADDR_CALI1_END      (ADDR_CALI1 + CALI_FLASH_CALI_CNT * CALI_FLASH_CALI_SIZE)

void cali_flash_sector_erase(uint16_t sector);
void cali_flash_copy(uint32_t dest, uint32_t src);
void cali_flash_copy_empty(uint32_t addr);
uint32_t cali_flash_get_info(void);
void cali_flash_write(void);

#ifdef __cplusplus
}
#endif

#endif /* __CALI_FLASH_H__ */
