#include "p_apps.h"
 
// 008B: sectors are 16k, 8k, 8k, 32k, 64k, 64k, 64k, 64k, ... 64k
// 008T: sectors are 64k, 64k, 64k, 64k, 64k, 64k, ... 64k, 32k, 8k, 8k, 16k 
// 800T: sectors are 64k, 64k, 64k, 64k, ... 64k, 64k, 64k, 32k, 8k, 8k, 16k
#if defined AM29LV008B || defined MX29LV008B || defined AM29LV008T
#define MAX_SECTOR	19
#define MAX_PAGE	15
#endif

#if defined AM29LV004T || defined MX29LV004T	// sectors are 64k, 64k, 64k, 64k, 64k, 64k, 64k, 32k, 8k, 8k, 16k 
#define MAX_SECTOR	11
#define MAX_PAGE	7
#endif

#ifdef AM29LV002T	// sectors are 64k, 64k, 64k, 32k, 8k, 8k, 16k 
#define MAX_SECTOR	7
#define MAX_PAGE	3
#endif

#ifdef AM29F040		// sectors are 8x64k
#define MAX_SECTOR	8
#define MAX_PAGE	7
#endif

#ifdef MT28F016
#define MAX_SECTOR	32
#define MAX_PAGE	31
#endif

#define ERASE_1K_WAIT_TIME		249900			// wait 0.25 seconds
#define WRITE_WAIT_TIME			350				// wait 0.35 milisecond

// Functions in serial.c
void SerialInitialize();

// Functions in pflash.c
void PFlashWriteBegin(UCHAR iLastSectorErased);
void PFlashWrite(UCHAR iVal);
void PFlashWriteFromSdram(UCHAR iIndexHi, UCHAR iIndexLo);
UCHAR PFlashEraseSector(UCHAR iSector);
UCHAR PFlashErasePage(UCHAR iPage);
void PFlashUpdateOptions();
void PFlashUpdateProgram();
//void PFlashUpdatePage();

void PFlashOperationEnd();
void SetBootingFlags(UCHAR iFlags);

#ifdef GUI_UPGRADE_RING
void PFlashUpdateRing();
#endif

void CheckSdram();
