/******************************************************************************
 * @file     data_manege.h
 * @version  V1.00
 *
 * @brief    Template project for user
 *
 * @note
 * Copyright (C) 2013 Spintrol Technology Corp. All rights reserved.
*****************************************************************************/
#ifndef __DATA_MANAGE_H__
#define __DATA_MANAGE_H__

#include "flash.h"

#define      DATA_FLASH_ACCESS_PRIMARY_ADDR     (( unsigned int)0x10010000UL)
#define      DATA_FLASH_ACCESS_MAX_ADDR         (( unsigned int)0x10020000UL)
#define      FLASH_REAL_SECTOR_SIZE             (0x200)
#define      FLASH_EXTEND_SECTOR_SIZE           (0x2000)
#define      FLASH_INDEX_FLAG										(0x35U)



/**
 *  @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];
  
  /* Example : */
  /*
  struct STRUCT_T mystruct;
  int32_t test[10];
  int8_t  test2;
  uint16_t test[2];
  .
  .
  .
  */
  
} ;




/**
 *  @brief  Data struct for EEPROM emulation
 */
struct DataPack_t{
  uint32_t  u32SectorAddr32Bit;
  uint32_t  u32SectorNumber;
  uint8_t   u8CheckSum;
  int32_t   i32DataIndex;
  uint16_t  u16DataLength;
  struct    UserData_t sUserData;
} ;




/**
 *  @brief  Data Manage Public Function Declaration
 */
uint32_t DATA_ByteSeriesSave(uint32_t u32SectorAddr32Bit,uint32_t *pu32Buffer,uint32_t u32DataLength);
void DATA_ByteSeriesRead(uint32_t u32SectorAddr32Bit,uint32_t *pu32Buffer,uint32_t u32DataLength);
void DATA_Read(struct DataPack_t* myDataPack);
int DATA_Save(struct DataPack_t* myDataPack);
int DATA_WriteOffset(uint32_t u32SectorStartAddr,uint32_t u32DataOffset);
int32_t DATA_ReadIndex(uint32_t uPageStartAddr);
int32_t DATA_AccessInit(struct DataPack_t* myDataPack,uint32_t u32SectorAddr);


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