⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intel_j3_1x16.c

📁 ebd9307开发板wince bsp源码,包括cs8900,lcd,nand,serial,touch,usb,gpio,wd等驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
//  dwDest       -  Address in flash where the start of the downloaded image 
//                  is to be written. Note that if this is not a flash 
//                  block-aligned address, the platform code will need 
//                  to take this into account and handle it as a special
//                  case. 
//
//  dwSource     -  Location of the Flash Cache.
//
//  dwLength     -  Length of the image, in bytes, to be written to flash. 
// 
//
BOOL  WriteFlashJ3_1x16(DWORD dwDest, DWORD dwSource, DWORD dwLength)
{
    ULONG               ulCount;
    ULONG               ulEndCount;
    volatile PUSHORT    pusBlockAddress;
    volatile PUSHORT    pusDest, pusSource;
    USHORT              usWordsToWrite;
    ULONG               ulStart,ulCurrent;
    BOOL                bSuccess;
    ULONG               ulAddDelay;


    ulCount     = 0;
    pusDest     = (PUSHORT)dwDest;
    pusSource   = (PUSHORT)dwSource;
    
    while( ulCount < dwLength)
    {   
    
        //
        // Calculate the block address
        //
        pusBlockAddress = (USHORT *)(((ULONG)&pusDest[ulCount>>1]) &  FLASH_BLOCK_MASK);        
        
        //
        // Write the Flash to buffer command until the flash is ready.
        //
        ulStart = GetSystemTimeInMsec();
        ulAddDelay = 1;
        do
        {    
            *pusBlockAddress = FLASH_WRITE_TO_BUFFER;
            
            //
            // Check to make sure that we are not in a loop.
            //
            ulCurrent = GetSystemTimeInMsec();
            if(ulStart + 1000 <ulCurrent)
            {
                EdbgOutputDebugString("FLASH_WRITE_TO_BUFFER - Failed\n.");
                EdbgOutputDebugString("pusBlockAddress  = %x.\n",(ULONG)pusBlockAddress);
                EdbgOutputDebugString("*pusBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
                *pusBlockAddress = FLASH_READ_STATUS;
                EdbgOutputDebugString("*FLASH_READ_STATUS pusBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
                while(1);

                return FALSE;
            }                
        }            
        while((*pusBlockAddress & EXT_STATUS_WBUFFER_READY)!= EXT_STATUS_WBUFFER_READY);
        
        //
        // Program the Flash size to be written.
        //
        usWordsToWrite = (FLASH_BUFFER_SIZE - 1)>>1;
        *pusBlockAddress = usWordsToWrite;
        
        ulEndCount  = ulCount + FLASH_BUFFER_SIZE;
        do
        {
            pusDest[ulCount>>1] = pusSource[ulCount>>1]; 
            ulCount += sizeof(USHORT);
        } while(ulCount < ulEndCount);
        
        //
        // End of programming the block.
        //
        *pusBlockAddress = FLASH_BLOCK_PROGRAM_RESUME;
        
        //
        // Occasionally write out a dot so they don't think
        // the system is dead.
        //
        if(((ULONG)&pusDest[ulCount>>1] & (FLASH_BLOCK_SIZE - 1)) == 0)
        {
            EdbgOutputDebugString(".");
        }            
        
        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(pusBlockAddress, 6000, EXT_STATUS_WBUFFER_READY);
        if(!bSuccess)
        {
            EdbgOutputDebugString("FLASH_BLOCK_PROGRAM_RESUME - Failed\n.");
            EdbgOutputDebugString("pulBlockAddress  = %x.\n",(ULONG)pusBlockAddress);
            EdbgOutputDebugString("*pulBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
            *pusBlockAddress = FLASH_READ_STATUS;
            EdbgOutputDebugString("*FLASH_READ_STATUS pulBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
            while(1);
            break;
        }            
    }        
    *pusBlockAddress =  FLASH_READ_MODE;

    return TRUE;
}

#else
//****************************************************************************
// WriteFlashJ3_1x16
//****************************************************************************
//  Writes to J3 Flash.  Different from parameters than  OEMWriteFlash.
//
//  dwDest       -  Address in flash where the start of the downloaded image 
//                  is to be written. Note that if this is not a flash 
//                  block-aligned address, the platform code will need 
//                  to take this into account and handle it as a special
//                  case. 
//
//  dwSource     -  Location of the Flash Cache.
//
//  dwLength     -  Length of the image, in bytes, to be written to flash. 
// 
//
BOOL  WriteFlashJ3_1x16(DWORD dwDest, DWORD dwSource, DWORD dwLength)
{
    ULONG               ulCount;
    volatile PUSHORT    pusBlockAddress;
    volatile PUSHORT    pusDest, pusSource;
    BOOL                bSuccess;
#if (FCLOCK <= 166)
    ULONG               ulEndCount;
    USHORT              usWordsToWrite;
    ULONG               ulStart,ulCurrent;
    ULONG               ulAddDelay;
#endif

    ulCount     = 0;
    pusDest     = (PUSHORT)dwDest;
    pusSource   = (PUSHORT)dwSource;
    
    while( ulCount < dwLength)
    {   
#if (FCLOCK <= 166)
		//EdbgOutputDebugString("166\r\n");
        //
        // Calculate the block address
        //
        pusBlockAddress = (USHORT *)(((ULONG)&pusDest[ulCount>>1]) &  FLASH_BLOCK_MASK);        
        
        //
        // Write the Flash to buffer command until the flash is ready.
        //
        ulStart = GetSystemTimeInMsec();
        ulAddDelay = 1;
        do
        {    
            *pusBlockAddress = FLASH_WRITE_TO_BUFFER;
            
            //
            // Check to make sure that we are not in a loop.
            //
            ulCurrent = GetSystemTimeInMsec();
            if(ulStart + 1000 <ulCurrent)
            {
                EdbgOutputDebugString("FLASH_WRITE_TO_BUFFER - Failed\n.");
                EdbgOutputDebugString("pusBlockAddress  = %x.\n",(ULONG)pusBlockAddress);
                EdbgOutputDebugString("*pusBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
                *pusBlockAddress = FLASH_READ_STATUS;
                EdbgOutputDebugString("*FLASH_READ_STATUS pusBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
                while(1);

                return FALSE;
            }                
        }            
        while((*pusBlockAddress & EXT_STATUS_WBUFFER_READY)!= EXT_STATUS_WBUFFER_READY);
        
        //
        // Program the Flash size to be written.
        //
        usWordsToWrite = (FLASH_BUFFER_SIZE - 1)>>1;
        *pusBlockAddress = usWordsToWrite;
        
        ulEndCount  = ulCount + FLASH_BUFFER_SIZE;
        do
        {
            pusDest[ulCount>>1] = pusSource[ulCount>>1]; 
            ulCount += sizeof(USHORT);
        } while(ulCount < ulEndCount);
        
        //
        // End of programming the block.
        //
        *pusBlockAddress = FLASH_BLOCK_PROGRAM_RESUME;
        
        //
        // Occasionally write out a dot so they don't think
        // the system is dead.
        //
        if(((ULONG)&pusDest[ulCount>>1] & (FLASH_BLOCK_SIZE - 1)) == 0)
        {
            EdbgOutputDebugString(".");
        }            
        
        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(pusBlockAddress, 6000, EXT_STATUS_WBUFFER_READY);
        if(!bSuccess)
        {
            EdbgOutputDebugString("FLASH_BLOCK_PROGRAM_RESUME - Failed\n.");
            EdbgOutputDebugString("pulBlockAddress  = %x.\n",(ULONG)pusBlockAddress);
            EdbgOutputDebugString("*pulBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
            *pusBlockAddress = FLASH_READ_STATUS;
            EdbgOutputDebugString("*FLASH_READ_STATUS pulBlockAddress = %x.\n",(ULONG)*pusBlockAddress);
            while(1);
            break;
        }    
#else
	int i;
	int ulCountCmp;
	ulCountCmp = ulCount;


	//EdbgOutputDebugString("200\r\n");

	for(i=0; i<FLASH_BLOCK_SIZE/2 && ulCount < dwLength; i++)
	//for(i=0; i<4096 && ulCount < dwLength; i++)
	{
		pusDest[ulCount>>1] = 0x0040;	//#define     FLASH_WRITE_WORD    0x0040

		pusDest[ulCount>>1] = pusSource[ulCount>>1];
		bSuccess = WaitForReady(&pusDest[ulCount>>1], 50000, EXT_STATUS_WBUFFER_READY);
		if( !bSuccess )
		{
			EdbgOutputDebugString("\r\nfail at 0x%x 0x%x\r\n.",
				(ULONG) (&pusDest[ulCount>>1]),
				(ULONG) (&pusSource[ulCount>>1]));
			while (1);
			return bSuccess;
		}
		//if( ulCount % 1023 == 0)
		//	EdbgOutputDebugString("+");
		ulCount += sizeof(USHORT);
	}

	if( bSuccess )
	{
		pusDest[ulCountCmp>>1] = FLASH_READ_MODE;

		for(i=0; i<FLASH_BLOCK_SIZE/2 && ulCountCmp < (int)dwLength; i++)
		//for(i=0; i<4096 && ulCountCmp < dwLength; i++)
		{
			// verify pargramed word
			unsigned short t;
			//pusDest[ulCountCmp>>1] = FLASH_READ_MODE;
			t = pusDest[ulCountCmp>>1];
			if( t != pusSource[ulCountCmp>>1] )
			{
				bSuccess = FALSE;
				EdbgOutputDebugString("\r\nmismatch at 0x%x 0x%x 0x%x != 0x%x  failed\r\n.",
					(ULONG) (&pusDest[ulCountCmp>>1]),
					(ULONG) (&pusSource[ulCountCmp>>1]),
					t,
					pusSource[ulCountCmp>>1] );
				while(1);
				return bSuccess;			
			}		
			//if( ulCountCmp % 1023 == 0)
			//	EdbgOutputDebugString("-");
			ulCountCmp += sizeof(USHORT);
		}
	}
	EdbgOutputDebugString(".");
#endif        
    }   

#if (FCLOCK > 166)
    pusBlockAddress = (unsigned short*)PHYSICAL_ADDR_FLASH_INTEL;
#endif         

    *pusBlockAddress =  FLASH_READ_MODE;

    return TRUE;
}
#endif

//****************************************************************************
// WaitForReady
//****************************************************************************
// Wait until the flash is ready.
// 
//
static BOOL  WaitForReady
(
    volatile USHORT *pusFlash, 
    ULONG           ulTimeoutInMsec, 
    USHORT          usBitField
)
{
    ULONG       ulStart;
    ULONG       ulCurrent;
    BOOL        bSuccess = FALSE;
   
    ulStart = GetSystemTimeInMsec();
    do
    {
        //
        // See if there are errors.
        //
        if((*pusFlash & usBitField)== usBitField)
        {
            bSuccess = TRUE;
            break;
        }
        
        //
        // Get the current time.
        //
        ulCurrent = GetSystemTimeInMsec();
    } while(ulCurrent<ulStart + ulTimeoutInMsec);

    if(!bSuccess)
    {
        EdbgOutputDebugString("*pusFlash        = %x .\n",(ULONG)*pusFlash);
    }        
    
    return bSuccess;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -