/***********************************************************************
 * Copyright (c)  2017 - 2020, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : eflash.h
 * Description : eflash header file
 * Author(s)   : Dan
 * version     : V1.0
 * Modify date : 2020-07-16
 ***********************************************************************/
#ifndef __EFLASH_H__
#define __EFLASH_H__

#include "um800x.h"


#define PagePerChip                      64

#define PAGE_SIZE                        512

#define EFlashMainBaseAddr			    (0x0000)				//main mode


#define EFC_WRITE_MODE				    (1<<0)  				//EFC_CTRL：Write模式设使能
#define EFC_PAGE_ERASE_MODE			    (1<<1)  				//EFC_CTRL：Sector Erase Mode模式设使能

#define NVR0_BASE_ADDR					(0x9000)
#define NVR1_BASE_ADDR					(0x9200)


//NVR2地址
#define SM_NVR1_UID0_ADDR				(NVR1_BASE_ADDR+0x48)
#define SM_NVR1_UID1_ADDR				(NVR1_BASE_ADDR+0x4C)
#define SM_NVR1_UID2_ADDR				(NVR1_BASE_ADDR+0x50)
#define SM_NVR1_UID3_ADDR				(NVR1_BASE_ADDR+0x54)
#define SM_NVR1_CRC_ADDR				(NVR1_BASE_ADDR+0x58)

void eflash_init(uint32_t system_clk_hz); 
void eflash_erase_page(uint16_t page_addr);
void eflash_write_byte(uint16_t addr,uint8_t value);						//write 8bits
void eflash_write_bytes(uint16_t addr, uint8_t *buff, uint32_t length);
uint8_t eflash_read_byte(uint16_t addr);
uint32_t eflash_read_bytes(uint16_t addr, uint8_t *buff, uint32_t length);

void read_sequence(uint8_t *buff);
void read_UID(uint8_t *buff);

#endif

