#ifndef _SMARTEE_H
#define _SMARTEE_H
#include "Std_Types.h"
#include "same51j19a.h"
#include "plib_nvmctrl.h"

#ifndef ENABLE
#define ENABLE 1u 
#endif

#ifndef DISABLE
#define DISABLE 0u 
#endif

#define SmartEE_BaseAddr       0x44000000

/* Define the NVMCTRL_SEESBLK_MASK_BITS to extract the NVMCTRL_SEESBLK bits(35:32) from NVM User Page Mapping(0x00804000) */
#define NVMCTRL_SEESBLK_MASK_BITS   0x0F
/* Define the NVMCTRL_SEEPSZ_MASK_BITS to extract the NVMCTRL_SEEPSZ bits(38:36) from NVM User Page Mapping(0x00804000) */
#define NVMCTRL_SEEPSZ_MASK_BITS    0x07

#define NVMCTRL_SEESBLK_CONFIG  0x01
#define NVMCTRL_SEEPSZ_CONFIG   0x02

#if (NVMCTRL_SEESBLK_CONFIG==0x01 && NVMCTRL_SEEPSZ_CONFIG==0x00)
    #define SMARTEEPROM_SIZE    512
#elif (NVMCTRL_SEESBLK_CONFIG==0x01 && NVMCTRL_SEEPSZ_CONFIG==0x01)
    #define SMARTEEPROM_SIZE    1024
#elif (NVMCTRL_SEESBLK_CONFIG==0x01 && NVMCTRL_SEEPSZ_CONFIG==0x02)
    #define SMARTEEPROM_SIZE    2048
#elif (NVMCTRL_SEESBLK_CONFIG==0x01 && NVMCTRL_SEEPSZ_CONFIG==0x03)
    #define SMARTEEPROM_SIZE    4096
#endif

/***************************API***************************/
/* check smart eeprom config , return 0 if config pass, return -1 for not*/
int8_t SmartEE_CheckConfig(void);

/* smart eeprom read function, return actrual byte length readed, return -1 if fail to read*/
int8_t SmartEE_Read(uint16_t address, uint8_t *data, uint8_t len);

/* smart eeprom write function, return actural byte length writen, return -1 if fail to write*/
int8_t SmartEE_Write(uint16_t address, uint8_t *data, uint8_t len);


#endif