www.pudn.com > SJF2443.zip > strata32.c


/************************************************************************************* 
 NAME: strata32.c 
 DESC: Strata Flash Programming code through 2443 JTAG  
 HISTORY: 
 JUN.14.2002:LSJ     : ported for 2443 
 Aug.19.2002:purnnamu: ported for 2443 JTAG version. 
 Nov.15.2002:purnnamu: - Fast programming by removing _RESET() in programming loop  
                         and omitting nRCS1 deassertion 
                       - E28F128 ClearLockBit function is added at sector erase step. 
 *************************************************************************************/ 
 
#include  
#include  
//#include  
#include "..\include\def.h" 
 
#include "..\include\pin2443.h" 
#include "..\include\Jtag.h" 
//#include "K9S1208.h" 
#include "..\include\sjf2443.h" 
 
#include "..\include\mem_rdwr.h" 
 
//I have not tested yet about fast programming. But, it will reduce the programming time. 
//IF the problem is occurred, let FAST_ROM_PROGRAM  0. 
#define	FAST_ROM_PROGRAM	1 
 
#define TARGET_RADDR_28F128      0x08000000  // nRCS1, 128MB area 
 
static U32 srcRAddr; 
 
static U32 targetOffset;  
static U32 targetRAddress;  
static U32 targetSize;  
 
static int error_erase=0;       // Read Status Register, SR.5 
static int error_program=0;     // Read Status Register, SR.4 
 
 
static int  Strata_ProgFlash(U32 realRAddr,U32 rdata); 
static void Strata_EraseSector(int targetRAddr); 
static int  Strata_CheckID(int targetRAddr); 
static int  Strata_CheckDevice(int targetRAddr); 
static int  Strata_CheckBlockLock(int targetRAddr); 
static int Strata_ClearBlockLock(int targetRAddr);  
static int  Strata_BlankCheck(int targetRAddr,int targetSize); 
static int  _WAIT(void); 
 
#if FAST_ROM_PROGRAM	 
    #define _WR(raddr,rdata)  MRW_Wr32QQ(raddr,rdata,0,0xf)  
#else 
    #define _WR(raddr,rdata)  MRW_Wr32Q(raddr,rdata,0,0xf)  
#endif 
#define _RD(raddr)       MRW_Rd32Q(raddr,0,0xf)       
#define _RESET()	MRW_Wr32Q(targetRAddress,0x00ff00ff,0,0xf) 
 
 
void Program28F128J3A(void) 
{ 
    U32 i; 
    U32 temp; 
 
    MRW_JtagInit(); 
 
    printf("\n[28F128J3A Flash JTAG Programmer]\n"); 
    printf("\n*** Very Important Notes ***\n"); 
    printf("1. 28F128J3A must be located at 0x08000000(Bank1) for programming.\n"); 
    printf("2. After programming, 28F128J3A may be located at 0x0(Bank0) for booting.\n"); 
          
    targetRAddress=TARGET_RADDR_28F128; 
    targetSize=imageSize; 
 
    printf("\nSource size = %xh\n",targetSize); 
    printf("\nAvailable Target Offset RAddress: \n");  
    printf("0x0,0x20000,0x40000, ..., 0x1ce0000\n"); 
    printf("Input target raddress offset [0x?] : "); 
    scanf("%x",&targetOffset); 
 
    printf("Target base raddress(0x08000000) = 0x%x\n",targetRAddress); 
    printf("Target offset      (0x0)        = 0x%x\n",targetOffset); 
    printf("Target size        (0x20000*n)  = 0x%x\n",targetSize); 
 
    if ( (Strata_CheckID(targetRAddress) & 0xffff) != 0x0089 )       // ID number = 0x0089 
    { 
        printf("Identification check error !!\n"); 
        return ; 
    } 
 
    if ( (Strata_CheckDevice(targetRAddress) & 0xffff) != 0x0018 )   // Device number=0x0018 
    { 
        printf("Device check error !!\n"); 
        return ; 
    } 
 
    printf("\nErase the sector from 0x%x.\n", targetRAddress+targetOffset); 
 
    for(i=0;i