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

📄 i28f256p30mtd16bit.c

📁 vxworks下intelp30flash的驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    DEBUG_PRINT(DEBUG_ALWAYS, ("flash(0x%04x), fail to write to(f): addr 0x%08x, length %d\n",
                                pVol->type, (UINT32)pSectorAddr, nLenTemp));
        return rv;
    }

    while(nLength > 0)
    {
        nLenTemp = nLength>=FLASH_BUF_CNT?FLASH_BUF_CNT:nLength;
        pSectorAddr = i28fxxxjMap(pVol, addrTemp, 0);
        //printf("pSectorAddr = 0x%x,pBuf = 0x%x,nLenTemp = %d\n",pSectorAddr,pBuf,nLenTemp);
		
        rv = i28fxxxjFlashWriteBuf(pSectorAddr, (UINT16 *)pBuf, nLenTemp);

        if(rv==flOK)
        {
            //printf("write :succed write to 0x%0x\n", (UINT32)pSectorAddr );
            nLength-= nLenTemp;
            addrTemp += nLenTemp;
            pBuf += nLenTemp;
        }
        else
        {
            DEBUG_PRINT(DEBUG_ALWAYS, ("flash(0x%04x), fail to write to: addr 0x%08x, length %d\n",
                                pVol->type, (UINT32)pSectorAddr, nLenTemp));
            return rv;
        }
    }
   
    return flOK;
}

FLStatus i28fxxxjErase(FLFlash* pVol, int firstErasableBlock, int numOfErasableBlocks)
{
    FlashWPTR pSectorAddr;
    int i = 0;
    FLStatus rv;


//    firstErasableBlock  +=64;
    
#if 0
if(pVol)
{
    printf("\npVol->chipSize = 0x%x pVol->erasableBlockSize = 0x%x\n firstErasableBlock = %d,numOfErasableBlocks = %d\n",(UINT32)pVol->chipSize,(UINT32)pVol->erasableBlockSize,firstErasableBlock,numOfErasableBlocks);
}
#endif
    
    if (firstErasableBlock + numOfErasableBlocks > (pVol->chipSize / pVol->erasableBlockSize))
    {
	    DEBUG_PRINT(DEBUG_ALWAYS, ("flash(0x%04x), Invalid sector range: %d-%d\n",
                       pVol->type,
	                firstErasableBlock, 
	                firstErasableBlock + numOfErasableBlocks -1));
        
        return flSectorNotFound;
    }
#if 0
    printf( "erase: firstErasableBlock is %d, number is %d\n", firstErasableBlock,numOfErasableBlocks );
#endif
    for(i =0; i<numOfErasableBlocks; i++)
    {
        int j;
        FlashWPTR pTmp;

        taskLock();
        pSectorAddr = i28fxxxjMap(pVol, (firstErasableBlock+i)*pVol->erasableBlockSize, 0);
#if 0
        printf("erase: pSecotorAddrs is 0x%0x\n", (UINT32)pSectorAddr);
#endif
        taskUnlock();
        rv =  i28fxxxjEraseSector(pSectorAddr);
        if (rv != flOK)
        {
            DEBUG_PRINT(DEBUG_ALWAYS, ("flashSectorErase return %d\n", rv));
            return rv;
        }

        pTmp = pSectorAddr;
        for(j=0; j<(pVol->erasableBlockSize/2); j++)
        {
        	if(*pTmp++ != 0xffff)
            {
            
                DEBUG_PRINT(DEBUG_ALWAYS, (" flash(0x%04x): sector %d erase check error!*pTmp = 0x%x,pTmp=0x%x,pVol->erasableBlockSize = %d\n", pVol->type, i,*pTmp,pTmp,pVol->erasableBlockSize));
                return flIncomplete;
            }
        }
    }
    
    return flOK;
}

FLStatus i28fxxxjIdGet(FLFlash* pVol, UINT8* uManCode, UINT8* uDevId)
{
    FlashWPTR pSectorAddr = i28fxxxjMap(pVol, 0, 0);
    UINT32 timeout;
    FLStatus rv = flTimedOut;

    pSectorAddr = i28fxxxjMap(pVol, 0, 0);
    *pSectorAddr = CLEAR_STATUS;
    IOSync();
    *pSectorAddr = READ_ID;
    IOSync();

    for (timeout = (volatile unsigned long)flMsecCounter + 3000; (volatile unsigned long)flMsecCounter < timeout;)
    {
        if((*pSectorAddr&FLASH_STATUS_READY) == FLASH_STATUS_READY)
        {
            rv = flOK;
            break;
        }        
    }
    
    if(flOK!=rv)
    {
        return flIncomplete;
    }

    pSectorAddr = i28fxxxjMap(pVol, 2, 0);
    *uManCode = (*pSectorAddr>>8) & 0xff;
	*uDevId = *pSectorAddr & 0xff;
    
    *pSectorAddr = READ_ARRAY;

    return rv;
}


#ifdef INTEL_FLASH8_BASEADR
#undef INTEL_FLASH8_BASEADR
#endif


#define INTEL_FLASH8_BASEADR 0xf4000000


UINT i28fxxxjSectorAddr(UINT uSectorIndex)
{
    assert(uSectorIndex>=0);

    if(uSectorIndex <= 127)
    {
        return (uSectorIndex*volume.erasableBlockSize);
    }

    return 0xffffffff;
}


int flashTestWrite(UCHAR *Data,UINT Addr,int Len)
{
    int i,toBlock;
    
    volume.socket->window.baseAddress = (INTEL_FLASH8_BASEADR)>>12;

    toBlock = volume.chipSize/volume.erasableBlockSize;
    
    for(i = 0; i < toBlock; i++)
    {
        if(i28fxxxjSectorAddr(i)==Addr)
        {
            break;
        }
    }
    
    if (i > toBlock)
    {
        printf("i28fxxxjWrite() address error!\n");
        return 3;
    }

    i28fxxxjErase(&volume, i, 2);
    /*printf("Data = 0x%x,Len = 0x%x",(int)Data,Len);*/
    return i28fxxxjWrite(&volume, Addr, Data, Len, 1);
           
}
int flashwrite()
{
    unsigned int buffer[512];
    FLStatus rv = flTimedOut;
    UINT32 timeout, i;
	FlashDPTR pFlashAddr = (FlashDPTR)0xf40a0000;
    
    for(i=0;i<512;i++)
    {
        buffer[i] = (unsigned char)i;
    }
    i28fxxxjErase(&volume, 128, 1);
    
    i28fxxxjWrite(&volume, 128, (const void FAR1 *)&buffer[0], 255, 1);

	for(i=0;i<0x10000;i++)
	{
	*pFlashAddr = 0x00500050;
	IOSync();
	*pFlashAddr = 0x00400040;
	IOSync();
	*pFlashAddr = 0x23232323;
	for (timeout = (volatile unsigned long)flMsecCounter + 3000; (volatile unsigned long)flMsecCounter < timeout;)
    {
        if((*pFlashAddr&FLASH_STATUS_READY) == FLASH_STATUS_READY)
        {
            rv = flOK;
            break;
        }
    }

    if(rv != flOK)
    {
    	printf("i28fxxxjFlashWriteBuf reture1 \n");
        return rv;
    }
	*pFlashAddr = 0x00500050;
	IOSync();
	*pFlashAddr = 0xffffffff;

	pFlashAddr++;
	}
	
    return OK;
}

int flashwrite2()
{
    unsigned char buffer[256];
    int i;
        
    for(i=0;i<256;i++)
    {
        buffer[i] = (unsigned char)i;
    }
    i28fxxxjErase(&volume2, 0, 1);
    
    i28fxxxjWrite(&volume2, 0, buffer, 256, 1);

    for(i=0;i<256;i++)
    {
        printf("value 0x%x vs 0x%x\n", buffer[i],*(UCHAR *)( (0x7c000000) + (i)) );
    }
    
    return OK;
}


int  flashTestRead()
{
    return OK;
}
int flashTestErase()
{
    volume.socket->window.baseAddress = (INTEL_FLASH8_BASEADR)>>12;
    
    return i28fxxxjErase(&volume,4,252);
}

int flashTestIdentify()
{
    memset(&volume, 0, sizeof(FLFlash));
    
    volume.socket = (FLSocket *)malloc(sizeof(FLSocket));
    volume.socket->window.baseAddress = (INTEL_FLASH8_BASEADR)>>12;

    return i28fxxxjMTDIdentify(&volume);
}
 
int i28fxxxjUnlockAllBlocks(void)
{
   FlashWPTR ulTmpAddr;
   int rc = OK;
   int i;
   #define FLASH_BLOCK_NUM 512/*1024*/
   #define FLASH_BASE_ADDR 0x7c000000
   #define GET_FLASH_BLOCK_BASE(BLOCK_NUM)         (BLOCK_NUM * 0x10000 + FLASH_BASE_ADDR)

   for(i = 0; i < FLASH_BLOCK_NUM; i++)
   {
      ulTmpAddr = (FlashWPTR)GET_FLASH_BLOCK_BASE(i);
      *ulTmpAddr = LOCK_BITCLEAR;                    /* UNLOCK */
      *ulTmpAddr = RESUME_BLOCK;                /* UNLOCK Confirm */
      *ulTmpAddr = CLEAR_STATUS;
   }
   
   return(rc);
}
FLStatus i28fxxxjMTDIdentify(FLFlash* pVol)
{
    UINT8 uManCode = 0;
    UINT8 uDevId = 0;
    FLStatus rv;
    int i;
	
    if(flOK != (rv=i28fxxxjIdGet(pVol, &uManCode, &uDevId)))
    {
        DEBUG_PRINT(DEBUG_ALWAYS, (" ERROR: fail to get intel flash ID!\n"));
        return rv;
    }

    for(i=0; i<gNoOfChipType; i++)
    {
        if(uManCode==gIntelChip[i].uManCode
            &&uDevId==gIntelChip[i].uDevId)
        {
            pVol->type = uManCode<<8 | uDevId;
            pVol->erasableBlockSize = gIntelChip[i].uBlockSize;
            pVol->chipSize = gIntelChip[i].uChipSize;
            pVol->noOfChips = I28FXXXJ_MTD_CHIP_CNT;
            pVol->interleaving = I28FXXXJ_MTD_INTERLEAVE;
            pVol->write = i28fxxxjWrite;
            pVol->erase = i28fxxxjErase;
            pVol->map = i28fxxxjMap;

            sysFlashSize = pVol->chipSize;
           // printf ("uManCode is 0x%x, devid is 0x%x\n", uManCode, uDevId );
            
            break;
        }
    }

    if(i>=gNoOfChipType)
    {
        DEBUG_PRINT(DEBUG_ID, ("i28fxxxjMTDIdentify() fail: ManId 0x%02x, DevId 0x%02x\n", uManCode, uDevId));
        return(flUnknownMedia);
    }
    else
    {
    	i28fxxxjUnlockAllBlocks();
        DEBUG_PRINT(DEBUG_ID, ("i28fxxxjMTDIdentify() succeeds!\n"));
        return(flOK);
    }
}

⌨️ 快捷键说明

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