/*******************************************************************************
** Document: FW_flash_api.h
** Copyright (c) 2004 R&D Center, Tailyn Communication Company, Ltd.  
** Created by: Chien Chung Lo
** Date: Dec. 24, 2004
** Description: Flash Firmware interface API.
** Version: 0.1
**
** Flash allocation:                     one row 1Mbytes
**   0 1 2 3 4 5 6 7  8 9 A B C D E F    one sector 64Kbytes
** 0 R E n n P n n n  S S S S S S S S    
** 1 S S S S S S S S  S S S S S S S S    R:winmon reset config
** 2 S S S S S S S S  S S S S S S S S    E:env parameter
** 3 S S S S S S S S  S S S S S S S S    P:flash partition parameter
** 4 W W W W n n n n  S S S S S S S S    S:O.S.
** 5 S S S S S S S S  S S S S S S S S    W:winmon
** . . . . . . . . .  . . . . . . . .    n:un-use
** . . . . . . . . .  . . . . . . . .
*******************************************************************************/
#ifndef _FW_API_FLASH_H_
#define _FW_API_FLASH_H_
//----------------------------------------------------------------------
#include <umap_type.h>

//----------------------------------------------------------------------
#define FLASH_DEVICE_FILE_NAME		"/dev/w747_flash_drv"

//----------------------------------------------------------------------
// Flash address 
//----------------------------------------------------------------------
#define ONE_PARTITION           0
#define TWO_PARTITION           1

#define ALL_PARTITION_SIZE      0xf00000  //15M bytes
#define ONE_PARTITION_SIZE      (ALL_PARTITION_SIZE / 2) //7.5M bytes

#define PARAMETER_OFFSET        0x40000   //256K
#define PARTITION_ONE_OFFSET    0x80000   //512K
#define PARTITION_TWO_OFFSET    0x880000  //8.5M

#define WINMON_OFFSET           0x400000  // 4M

#define SECTOR_SIZE             0x10000   //64K bytes
#define WORD_SIZE               0x1000    // 4K words

#define SECTOR_OFFSET(x)        (SECTOR_SIZE * x)
#define FLASH_BASE_ADDRESS      0x1f800000
#define VIRTUAL_OFFSET          0xa0000000

#define SECTOR_ERASE            0
#define SECTOR_PROGRAM          1

struct flash_option_info
{
	UMAP_U8  type;                //option type
	UMAP_U32 sector_offset;       //unit byte
	UMAP_U32 sector_size;
	UMAP_U32 addr_offset;         //unit word
	UMAP_U32 word_size;
	UMAP_U16 data[WORD_SIZE];
} flash_option_info;

//----------------------------------------------------------------------
UMAP_S32 FW_ReadFlash(UMAP_U32 addr, UMAP_U32 size, void *data);
UMAP_S32 FW_WriteFlash(UMAP_U32 addr, UMAP_U32 size, void *data);

UMAP_S32 FW_FlashCopy(char file[256],int partition);
UMAP_S32 FW_FlashErase(int partition,unsigned short parameter);
UMAP_S32 FW_FlashParameter(unsigned short parameter);

#endif // _FW_API_FLASH_H_

