/**
  ******************************************************************************
  * @file    eflash_hal.h
  * @author  Product application department
  * @version V1.0
  * @date    2020.03.20
  * @brief   Header file of Eflash HAL module.
  * 
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __EFLASH_HAL_H
#define __EFLASH_HAL_H

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "eflash_drv.h"

/**@defgroup HAL HAL driver
  *
  *@{
  */

/** @defgroup HAL_EFLASH EFLASH
  *
  *@{
  */

/*** 宏定义 *******************************************************************/
/** @defgroup EFLASH_Exported_Macros Exported Macros
  *
  * @{
  */
#define _EFLASH_SET_RWSC(val)       _eflash_set_rwsc(EFM, val)
//xukai20200408,bt_demo的函数中使用
#define EFLASH_PAGE_SIZE_BYTE       (0x200)		  //512
#define EFLASH_PAGE_SIZE_HFWORD     (0x100)		  //256
#define EFLASH_PAGE_SIZE_WORD       (0x80)		  //128
#define EFLASH_BYTE_SIZE            (0x80000)	  //512kbytes, 128k words
#define EFLASH_ALL_PAGE_LEN         (1024)      //1024page
#define PAGE_MASK                   (EFLASH_PAGE_SIZE_BYTE-1)
//xukai20200408,bt_demo的函数中使用 end
/**
  * @}
  */

/*** 结构体、枚举变量定义 *****************************************************/
/** @defgroup EFLASH_Exported_Types Exported Types
  *
  * @{
  */

/**
  * @brief eflash 错误码定义
  *
  */
typedef enum
{
	HAL_EFLASH_ERROR_NONE = 0,    /**< No error */
	HAL_EEFLASH_ERROR_ERASE = 1,  /**< Erash error */
	HAL_EFLASH_ERROR_OUTRANGE = 2 /**< 地址越界 */
} EFLASH_ErrCodeTypeDef;

/**
  *@brief EFLASH句柄结构体定义.
  *
  */
typedef struct{
	EFLASH_TypeDef *instance;

	uint32_t        efm_clk;

}EFLASH_HandleTypeDef;

/**
  * @}
  */

/*** 全局变量声明 **************************************************************/
/** @defgroup EFLASH_Exported_Variables Exported Variables
  *
  * @{
  */



/**
  * @}
  */

/*** 函数声明 ******************************************************************/
/** @defgroup EFLASH_Exported_Functions Exported Functions
  * @{
  */

extern void HAL_EFLASH_Init(uint32_t efm_clk);
extern void HAL_EFLASH_SetWritePermission(void);
extern void HAL_EFLASH_Lock(EFLASH_HandleTypeDef *hefm);
extern void HAL_EFLASH_Unlock(EFLASH_HandleTypeDef *hefm);
extern uint8_t HAL_EFLASH_ProgramWord(uint32_t Address, uint32_t Data);
extern uint8_t HAL_EFLASH_ProgramBulk(uint32_t Address, uint8_t *buffer, uint32_t length);
extern uint8_t HAL_EFLASH_PageErase(uint32_t Address);
extern void HAL_EFLASH_Read(const uint32_t Address, uint8_t *buffer,uint32_t length);


/**
  * @}
  */

/**
  *@}
  */

/**
  *@}
  */

#ifdef __cplusplus
}
#endif

#endif /* __EFLASH_HAL_H */

