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

📄 amd29lvmtd.c

📁 VxWorks5.5版本下的TrueFFS文件系统demo源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
LOCAL STATUS flashProgram32Bits    (    FLFlash* pVol,    volatile UINT32* pData,    UINT32 data,    BOOL upper    )    {    BOOL programmed = FALSE;    int timeout;    flashUnlock(pVol, upper);    flashRegWrite32Bits(pVol, 0x555, 0x00a000a0, upper);    DEBUG_PRINT(DEBUG_PROG32, ("Programming 0x%08x to %p, upper = %d\n",                data, pData, upper));    *pData = data;    CACHE_PIPE_FLUSH();    for (timeout = flMsecCounter + 3000; flMsecCounter < timeout;)        {        if (*pData == data)            {            programmed = TRUE;            break;            }        taskDelay(0);        }    if (!programmed)        {        DEBUG_PRINT(DEBUG_ALWAYS, ("Timeout\n"));        return(ERROR);        }    return(OK);    }/******************************************************************************** flashHalfSectorErase - Erase lower or upper half of sector.** RETURNS: OK or ERROR**/LOCAL STATUS flashHalfSectorErase    (    FLFlash* pVol,    int sectorNum,    BOOL upper    )    {    BOOL erased = FALSE;    int timeout = sysClkRateGet() * 5;    UINT32 offset;    UINT32 size;    volatile UINT32* pFlash;    UINT32 sectorAddr;    if (pVol->type == 0x1C4)			/* amd29LV160BT */	{	/* Sectors 31 - 34 are funky sizes */	switch (sectorNum)	    {	    case 31:	        offset = 0x7c0000;	        size   = 0x20000;	        sectorAddr = 0xf8000;	        break;	    case 32:	        offset = 0x7e0000;	        size   = 0x8000;	        sectorAddr = 0xfc000;	        break;	    case 33:	        offset = 0x7e8000;	        size   = 0x8000;	        sectorAddr = 0xfd000;	        break;	    case 34:	        offset = 0x7f0000;	        size   = 0x10000;	        sectorAddr = 0xfe000;	        break;	    default:	        offset = sectorNum * AMD29LV_MTD_SECTOR_SIZE;	        size = AMD29LV_MTD_SECTOR_SIZE;	        sectorAddr = (sectorNum << 15);	    }	}    else					 /* amd29LV323CT */	{	/* Sectors 63 - 70 are 1/8th size of other sectors */	if (sectorNum < AMD29LV_323_LAST_SECTOR_NUM)	    {	    offset     = sectorNum * AMD29LV_MTD_SECTOR_SIZE;	    size       = AMD29LV_MTD_SECTOR_SIZE;	    sectorAddr = (sectorNum << 15);	    }	else	    {	    offset  = AMD29LV_323_LAST_SECTOR_NUM * AMD29LV_MTD_SECTOR_SIZE;	    offset += (sectorNum - AMD29LV_323_LAST_SECTOR_NUM) *	              AMD29LV_323_LAST_SECTOR_SIZE;	    size    = AMD29LV_323_LAST_SECTOR_SIZE;	    sectorAddr  = (AMD29LV_323_LAST_SECTOR_NUM << 15);	    sectorAddr += ((sectorNum - AMD29LV_323_LAST_SECTOR_NUM) << 12);	    }	}    DEBUG_PRINT(DEBUG_ERASE, ("Erasing sector %d, 0x%02x, upper = %d\n",                sectorNum, sectorAddr, upper));    /* Erase the sector half */    flashUnlock(pVol, upper);    flashRegWrite32Bits(pVol, 0x555, 0x00800080, upper);    flashUnlock(&vol, upper);    flashRegWrite32Bits(pVol, sectorAddr, 0x00300030, upper);    pFlash = (volatile UINT32*) pVol->map(pVol, offset, size);    if (upper)        pFlash++;    /* Sector's  upper/lower half erased?  If not, return ERROR */    for (timeout = flMsecCounter + 5000; flMsecCounter < timeout;)        {        if (*pFlash == 0xffffffff)            {            erased = TRUE;            break;            }        }    if (!erased)        {        DEBUG_PRINT(DEBUG_ALWAYS, ("Sector erase timeout, %p\n", pFlash));        return(ERROR);        }    return(OK);    }/******************************************************************************** flashRegWrite32Bits - Write 32 bits to 4 byte aligned address.** RETURNS: N/A**/LOCAL void flashRegWrite32Bits    (    FLFlash* pVol,    UINT32 addr,    UINT32 data,    BOOL   upper    )    {    UINT32 flashBaseAddr = (pVol->socket->window.baseAddress << 12);    /* Adjust addr for amd29LV323 */    addr = flashBaseAddr + 8 * addr;    if (upper)        addr += 4;    DEBUG_PRINT(DEBUG_WRITE, ("Writing 0x%08x to 0x%08x\n", data, addr));    /* Write */    *((volatile UINT32*) addr) = data;    CACHE_PIPE_FLUSH();    }/******************************************************************************** flashRegRead16Bits - Read 16 bits from 2 byte aligned address.** RETURNS: data at specified address**/LOCAL UINT16 flashRegRead16Bits    (    FLFlash* pVol,    UINT32 addr,    BOOL   upper    )    {    UINT16 data;    UINT32 flashBaseAddr = (pVol->socket->window.baseAddress << 12);    addr = flashBaseAddr + 8 * addr;    if (upper)        addr += 4;    data = *((volatile UINT16*) addr);    DEBUG_PRINT(DEBUG_READ, ("Read 0x%08x from 0x%08x\n", data, addr));    CACHE_PIPE_FLUSH();    return(data);    }/******************************************************************************** flashIdGet - Get flash man. and device codes.** RETURNS: N/A**/LOCAL void flashIdGet    (    FLFlash* pVol,    UINT16* manCode,    UINT16* devCode    )    {    flashUnlock(pVol, FALSE);    flashRegWrite32Bits(pVol, 0x555, 0x00900090, FALSE);    *manCode = flashRegRead16Bits(pVol, 0x00, FALSE);    *devCode = flashRegRead16Bits(pVol, 0x01, FALSE);    flashReset(pVol, FALSE);    }/******************************************************************************** flashUnlock - Write unlock sequence to upper or lower flash section.** RETURNS: N/A**/LOCAL void flashUnlock    (    FLFlash* pVol,    BOOL upper    )    {    flashRegWrite32Bits(pVol, 0x555, 0x00aa00aa, upper);    flashRegWrite32Bits(pVol, 0x2aa, 0x00550055, upper);    }/******************************************************************************** flashReset - Write reset sequence to upper or lower flash section.** RETURNS: N/A**/LOCAL void flashReset    (    FLFlash* pVol,    BOOL upper    )    {    flashRegWrite32Bits(pVol, 0, 0x00f000f0, upper);    }#define FLASH_TEST#undef FLASH_TEST#ifdef FLASH_TEST#include "tffs/flsocket.h"LOCAL FLFlash testVol;LOCAL FLSocket testSocket;/* Make sure this functions are NOT static (LOCAL) in sysTffs.c */IMPORT void simmSetWindow (FLSocket vol);IMPORT void simmSetMappingContext (FLSocket vol, unsigned page);IMPORT FLBoolean simmWriteProtected (FLSocket vol);/* Initialize */LOCAL void FAR0 *flashMap(FLFlash vol, CardAddress address, int length){  return flMap(vol.socket,address);}void fsinit()    {    FLStatus rc;    testSocket.window.baseAddress = tffsFlashBaseAdrs >> 12;    testSocket.window.currentPage = UNDEFINED_MAPPING;    testSocket.setWindow = simmSetWindow;    testSocket.setMappingContext = simmSetMappingContext;    testSocket.setMappingContext = simmSetMappingContext;    testSocket.writeProtected = simmWriteProtected;    testVol.socket = &testSocket;    testVol.map = flashMap;    rc = amd29lvMTDIdentify(&testVol);    if (rc != flOK)        {        printf("identify fails\n");        }    }/* Show */void fsshow()    {    printf("Type 0x%04x\n", testVol.type);    printf("Eraseable block size 0x%08lx\n", testVol.erasableBlockSize);    }/* Erase */STATUS fse    (    UINT8 sectorNum,    UINT8 numSectors    )    {    FLStatus rc;    if (sectorNum <= 3)        {        printf("Sector contains bootrom!\n");        return(ERROR);        }    rc = testVol.erase(&testVol, sectorNum, numSectors);    return(rc);    }/* Program */STATUS fprog    (    UINT32 offset,    UINT32 bufSize,    UINT8  pattern    )    {    FLStatus rc;    UINT32* pBuf;    UINT32 sectorNum = offset / AMD29LV_MTD_SECTOR_SIZE;    if (sectorNum <= 3)        {        printf("Sector contains bootrom!\n");        return(ERROR);        }    if (bufSize == 0)        bufSize = 4;    if ((bufSize & 0x03) != 0)        bufSize += 4 - (bufSize & 0x03);    pBuf = memalign(4, bufSize);    if (pBuf == 0)        return(ERROR);    memset(pBuf, pattern, bufSize);    rc = testVol.write(&testVol, offset, pBuf, bufSize, FALSE);    free(pBuf);    return(rc == flOK ? OK : ERROR);    }#endif

⌨️ 快捷键说明

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