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

📄 intel_c3_2x16.c

📁 CIRRUS 93XX系列windows mobile 6.0 BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
    //
    // Check to see if the flash has been completely erased. If so just
    // return.
    //
    if(gbFlashEraseComplete)
    {
        return TRUE;
    }
	RETAILMSG(INTELC3_DEBUG,(L"FinishEraseFlashC3_2x16 1 %x %x %x %x %x\r\n",
		gdwNumEraseRegion,gdwCurEraseRegion,gdwCurEraseBlock,
		sBlockInfo[gdwCurEraseRegion].block_size,
		sBlockInfo[gdwCurEraseRegion].blocks));

    //
    // Wait for the Flash block command to succeed.
    //
    bSuccess = WaitForReady(gpulCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
    if(bSuccess == FALSE)
    {
        return FALSE;
    }
    
	RETAILMSG(INTELC3_DEBUG,(L"FinishEraseFlashC3_2x16 2 %x %x %x %x %x\r\n",
		gdwNumEraseRegion,gdwCurEraseRegion,gdwCurEraseBlock,
		sBlockInfo[gdwCurEraseRegion].block_size,
		sBlockInfo[gdwCurEraseRegion].blocks ));

    
    *gpulCurAddr  = FLASH_CLEAR_STATUS;
    //
    // Erase the block before unlocking the next block.
    //
    if(gbUnlocked)
    {
        //
        // Erase the flash block
        //
        *gpulCurAddr = FLASH_BLOCK_ERASE;
        *gpulCurAddr = FLASH_BLOCK_ERASE_RESUME;

        //
        // Read erase status.
        //
        *gpulCurAddr = FLASH_READ_STATUS;

        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(gpulCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
        if(bSuccess == FALSE)
        {
            return FALSE;
        }

        *gpulCurAddr    = FLASH_CLEAR_STATUS;
        gbUnlocked      = FALSE;

        //
        // Increment to the next block.
        //
        //gpulCurAddr += FLASH_BLOCK_SIZE>>2;
        gpulCurAddr+= sBlockInfo[gdwCurEraseRegion].block_size>>2;

		//
		//go to the next bloxk
		//
		gdwCurEraseBlock = gdwCurEraseBlock+1;
		if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
		{
			gdwCurEraseBlock=0;
			gdwCurEraseRegion=gdwCurEraseRegion+1;
			//
			//return error the current postiotn > the Flash MAX length
			//
			if(gdwCurEraseRegion>=gdwNumEraseRegion)
				return FALSE;
		}
    }

	RETAILMSG(INTELC3_DEBUG,(L"FinishEraseFlashC3_2x16 3 %x %x %x %x %x,Current=%x %x %x\r\n",
            gdwCurEraseRegion,gdwCurEraseRegion,gdwCurEraseBlock,
			sBlockInfo[gdwCurEraseRegion].block_size,
            sBlockInfo[gdwCurEraseRegion].blocks,gpulCurAddr,gdwStartAddr,gdwLength
        ));
    //
    // Erase the Flash
    //
    while((DWORD)gpulCurAddr < (gdwStartAddr + gdwLength))
    {
		RETAILMSG(INTELC3_DEBUG,(L"FinishEraseFlashC3_2x16 4 %x %x %x %x,Current=%x %x %x\r\n",
            gdwCurEraseRegion,gdwCurEraseRegion,gdwCurEraseBlock,
			sBlockInfo[gdwCurEraseRegion].block_size,
            gpulCurAddr
        ));
        //
        // Clear the lock bits if the flash block was locked.
        //
        *gpulCurAddr = FLASH_LOCK_BIT;
        *gpulCurAddr = FLASH_LOCK_CLEAR;
        *gpulCurAddr = FLASH_READ_STATUS;

        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(gpulCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
        *gpulCurAddr  = FLASH_CLEAR_STATUS;
        
        if(!bSuccess)
        {
            break;
        }
        //
        // Erase the flash block
        //
        *gpulCurAddr = FLASH_BLOCK_ERASE;
        *gpulCurAddr = FLASH_BLOCK_ERASE_RESUME;
        *gpulCurAddr = FLASH_READ_STATUS;
        
        //
        // Wait for the Flash block command to succeed.
        //
        bSuccess = WaitForReady(gpulCurAddr, 10000, EXT_STATUS_WBUFFER_READY);
        *gpulCurAddr  = FLASH_CLEAR_STATUS;
        
        if(!bSuccess)
        {
            break;
        }
        //
        // Occasionally write out a dot so they don't think
        // the system is dead.
        //
        EdbgOutputDebugString(".");
        
        //
        // Increment to the next block.
        //
        //gpulCurAddr += FLASH_BLOCK_SIZE>>2;
        gpulCurAddr+= sBlockInfo[gdwCurEraseRegion].block_size>>2;

		//
		//go to the next bloxk
		//
		gdwCurEraseBlock = gdwCurEraseBlock+1;
		if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
		{
			gdwCurEraseBlock=0;
			gdwCurEraseRegion=gdwCurEraseRegion+1;
			//
			//return error the current postiotn > the Flash MAX length
			//
			if(gdwCurEraseRegion>gdwNumEraseRegion){
				EdbgOutputDebugString("error erase regin \r\n"	);
				return FALSE;
			}
		}
    }        
    return bSuccess;
}

extern volatile int bStop;
//****************************************************************************
// WriteFlashJ3_2x16
//****************************************************************************
//  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  WriteFlashC3_2x16(DWORD dwDest, DWORD dwSource, DWORD dwLength)
{
    ULONG               ulCount;
    //ULONG               ulEndCount;
    volatile PULONG     pulBlockAddress;
    volatile PULONG     pulDest, pulSource;
    //ULONG              usWordsToWrite;
    //ULONG               ulStart;
    BOOL                bSuccess;
    //ULONG               ulAddDelay;

    ULONG ulBufferSizeLen=0;	

    ulCount     = 0;
    pulDest     = (PULONG)dwDest;
    pulSource   = (PULONG)dwSource;


	//
	//get the current region and block index
	//
	GotEraseFlashSectorIndex_C3_2X16(dwDest);

	RETAILMSG(INTELC3_DEBUG,(L"WriteFlashC3_2x16 0: %x %x %x %x %x--%x,%x\r\n",
    gdwNumEraseRegion,gdwCurEraseRegion,gdwCurEraseBlock,
	sBlockInfo[gdwCurEraseRegion].block_size,
    sBlockInfo[gdwCurEraseRegion].blocks,dwDest,dwLength));	

    while( ulCount < dwLength)
    {   
		ULONG i,j;
		ULONG ulCountCmp;
		ulCountCmp = 0;

		for(i=0;( i<(sBlockInfo[gdwCurEraseRegion].block_size/2)) && (ulCount < dwLength); i++)
		{
			pulDest[ulCount>>2] = 0x00400040;	//#define     FLASH_WRITE_WORD    0x0040

			//for p30
			for(j=0;j<100;j++){}

			pulDest[ulCount>>2] = pulSource[ulCount>>2];
			//for p30
			for(j=0;j<100;j++){}
		
			bSuccess = WaitForReady(&pulDest[ulCount>>2], 50000, EXT_STATUS_WBUFFER_READY);
			if( !bSuccess )
			{
				EdbgOutputDebugString("\r\nfail at 0x%x 0x%x\r\n.",
					(ULONG) (&pulDest[ulCount>>2]),
					(ULONG) (&pulSource[ulCount>>2]));
				while (1);
				return bSuccess;
			}
			//if( ulCount % 1023 == 0)
			//	EdbgOutputDebugString("+");
			ulCount += sizeof(ULONG);
		}

		RETAILMSG(INTELC3_DEBUG,(L"200---%x  %x\r\n",bSuccess,ulCount));
		if( bSuccess )
		{
			pulDest[ulCountCmp>>2] = FLASH_READ_MODE;

			for(i=0; (i<(sBlockInfo[gdwCurEraseRegion].block_size/2)) && (ulCountCmp < dwLength); i++)
			{
				// verify pargramed word
				unsigned long t;
				t = pulDest[ulCountCmp>>2];
				if( t != pulSource[ulCountCmp>>2] )
				{
					bSuccess = FALSE;
					EdbgOutputDebugString("\r\nmismatch at 0x%x 0x%x 0x%x != 0x%x  failed\r\n.",
						(ULONG) (&pulDest[ulCountCmp>>2]),
						(ULONG) (&pulSource[ulCountCmp>>2]),
						t,
						pulSource[ulCountCmp>>2] );
					while(1);
					return bSuccess;			
				}		
				//if( ulCountCmp % 1023 == 0)
				//	EdbgOutputDebugString("-");
				ulCountCmp += sizeof(ULONG);
			}
		}
		EdbgOutputDebugString(".");

		//
		//go to the next bloxk
		//
		gdwCurEraseBlock = gdwCurEraseBlock+1;
		if(gdwCurEraseBlock>=sBlockInfo[gdwCurEraseRegion].blocks)
		{
			gdwCurEraseBlock=0;
			gdwCurEraseRegion=gdwCurEraseRegion+1;
			//
			//return error the current postiotn > the Flash MAX length
			//
			if(gdwCurEraseRegion>=gdwNumEraseRegion)
				return FALSE;
		}
	}	 
     pulBlockAddress = (unsigned long*)PHYSICAL_ADDR_FLASH;         

    *pulBlockAddress =  FLASH_READ_MODE;
   
    return TRUE;
}



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

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

⌨️ 快捷键说明

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