/******************************************************************************
 * @file     data_manege.h
 * @version  V4.0.1
 * @date     30-July-2026
 *
 * @brief    Template project for user
 *
 * @note
 * Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd.. All rights reserved.
*****************************************************************************/
#ifndef __DATA_MANAGE_H__
#define __DATA_MANAGE_H__


#include "flash.h"

#define      FLASH_DURTY_FLAG                                       (0xACCEU)

#if defined(SPC1168) || defined(SPD1148) || defined(SPD1178) || defined(SPD1188) || defined(SPD1163)
    #define          FLASH_END_ADDR                                         (0x10020000)
#elif defined(SPC1158)
    #define          FLASH_END_ADDR                                         (0x10010000)
#endif

#if defined(SPC1168) || defined(SPD1148) || defined(SPD1178) || defined(SPD1188) || defined(SPD1163)
    #define          EMULATION_START_ADDR                               (0x10010000)        //This address must be align with 0x200
#elif defined(SPC1158)
    #define          EMULATION_START_ADDR                               (0x10008000)        //This address must be align with 0x200
#endif

#if defined(SPC1168) || defined(SPD1148) || defined(SPD1178) || defined(SPD1188) || defined(SPD1163)
    #define          EMULATION_END_ADDR                                 (0x10010600)        //This address must be align with 0x200
#elif defined(SPC1158)
    #define          EMULATION_END_ADDR                                 (0x10008600)        //This address must be align with 0x200
#endif

/**
 *  @brief  User data struct
 */
struct UserData_t
{
    /* User can define your own data type */

    int8_t  myData[6];
    uint32_t test[10];
    int8_t test2;
    uint16_t test3[2];

    /*
    .
    .
    */

} ;


/**
 *  @brief  Data struct for EEPROM emulation
 */
struct ManagementData_t
{
    uint32_t  u32IndexStartAddr;          /*eeprom emulation index region start address*/
    uint32_t  u32IndexLineCnt;                /*eeprom emulation index region lines*/
    uint16_t    u16IndexLineExSectors;  /*the number of sectors index region taken*/
    uint32_t  u32DataStartAddr;               /*eeprom emulation data region start address*/
    uint32_t  u32DataEndAddr;                 /*eeprom emulation data region end address*/
    uint16_t    u16UserDataAlignSize;       /*user data siez align with 4*/
    uint16_t    u16OneUserDataExSectors;/*the number of sectors one user data struct taken*/
} ;


ErrorStatus EEPROM_Init(uint32_t u32StartAddr, uint32_t u32EndAddr, uint32_t u32UserDataSize);
ErrorStatus EEPROM_Write(struct UserData_t *UserData);
void EEPROM_Read(struct UserData_t *UserData);


#endif //__MOTOR_MCU_HARDWARE_DRIVER_H__
/*** (C) COPYRIGHT 2022 Spintrol Technology Corp. ***/
