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

📄 cfiscs.c

📁 MPC8560 for vxwork BSP
💻 C
📖 第 1 页 / 共 5 页
字号:
        cmdBuffer |= QUERY << (8 * ix);    flashPtr[0x55 * thisCFI->multiplier] = cmdBuffer;    /* NOTE: The address wrap around technique used here works only if the flash     * size was declared correctly in the socket driver. At some point the MTD     * should be discovering flash size and exporting it to the socket driver.      */    for (vol.noOfChips = 1 * vol.interleaving;       /* Scan the chips */        vol.noOfChips < 2000;  /* Big enough ? */        vol.noOfChips += vol.interleaving)        {#ifdef SAVE_NVRAM_REGION        if (vol.interleaving == 1)  /* wrSbc85xx boot flash only */            {            /* Reinstate the NVRAM region */            flashPtr = (FlashPTR) flMap(vol.socket, vol.noOfChips *                                         (vol.chipSize +                                          (vol.erasableBlockSize / vol.interleaving)));            }        else            {            flashPtr = (FlashPTR) flMap(vol.socket, vol.noOfChips * vol.chipSize);            }#else        flashPtr = (FlashPTR) flMap(vol.socket, vol.noOfChips * vol.chipSize);#endif#ifdef DEBUG_PRINT        DEBUG_PRINT("Debug: Looking for Flash device at base 0x%x\n", (UINT32) flashPtr);#endif        if ((flashPtr[0x10 * thisCFI->multiplier])             == (unsigned char)queryIdStr[0] &&            (flashPtr[0x11 * thisCFI->multiplier])             == (unsigned char)queryIdStr[1] &&            (flashPtr[0x12 * thisCFI->multiplier])             == (unsigned char)queryIdStr[2])            {            goto noMoreChips;      /* Wrapped around */            }        /* Confirm this is also a CFI part */        *(UCHAR *)(flashPtr + (0x55 * thisCFI->multiplier))        = (UCHAR)(QUERY);        if (flashPtr[0x10 * thisCFI->multiplier]            != (unsigned char)queryIdStr[0] ||            flashPtr[0x11 * thisCFI->multiplier]            != (unsigned char)queryIdStr[1] ||            flashPtr[0x12 * thisCFI->multiplier]            != (unsigned char)queryIdStr[2])            {            /* Should not happen !! */            goto noMoreChips;   /* Not a CFI Flash part */            }        flashPtr[0x55 * thisCFI->multiplier]         = (UCHAR)(CLEAR_STATUS);        flashPtr[0x55 * thisCFI->multiplier]         = (UCHAR)(READ_ARRAY);        }    /* We should never get here. */#ifdef DEBUG_PRINT    DEBUG_PRINT("Debug: Device count overflow\n");#endif  /* DEBUG_PRINT */    return flGeneralFailure;    noMoreChips:    flashPtr = (FlashPTR) flMap(vol.socket, 0);    /* Switch to READ_ARRAY mode */    cmdBuffer = 0x0;    for (ix = 0; ix < thisCFI->multiplier; ix++)        cmdBuffer |= READ_ARRAY << (8 * ix);    flashPtr[0x55 * thisCFI->multiplier] = cmdBuffer;    return flOK;    }/******************************************************************************* cfiscsByteWrite - byte write routine** This routine is intended to be registered as the write routine in systems* that have byte wide devices interleaved or devices that are in byte mode.** RETURNS:** ERRNO:** \NOMANUAL*/LOCAL FLStatus cfiscsByteWrite    (    FLFlash vol,               /* Pointer identifying drive     */    CardAddress address,       /* Card address to write to      */    const void FAR1 *buffer,   /* Address of data to write      */    int length,                /* Number of bytes to write      */    int mode                   /* write mode (overwrite yes/no) */    )    {    FLStatus status = flOK;    FlashPTR flashPtr;    unsigned int i, from, eachWrite;    const char FAR1 *temp = (const char FAR1 *)buffer;    /* Set timeout to 20 seconds from now */    unsigned long writeTimeout = flMsecCounter + 20000;    printf ("CFISCS: writing bytes to flash offset 0x%x\n", address);    if (flWriteProtected(vol.socket))        return flWriteProtect;#ifdef SOCKET_12_VOLTS    if (thisCFI->vpp)        checkStatus(flNeedVpp(vol.socket));#endif    if (thisCFI->maxBytesWrite > 1) /* multi-byte write supported */        eachWrite = thisCFI->maxBytesWrite * vol.interleaving;    else        eachWrite = vol.interleaving;    for (from = 0; (int)from < length && status == flOK; from += eachWrite)        {        int thisLength = length - from;        FlashPTR currPtr;        unsigned tailBytes, lengthByte;        if (thisLength > (int)eachWrite)            thisLength = eachWrite;        lengthByte = thisLength / vol.interleaving;        tailBytes = thisLength % vol.interleaving;        flashPtr = (FlashPTR) flMap(vol.socket, address + from);        for (i = 0, currPtr = flashPtr;            ((int)i < vol.interleaving) && ((int)i < thisLength);            i++, currPtr++)            {            do                 {                *currPtr = WRITE_TO_BUFFER;                } while (!(*currPtr & SR_READY) &&                          (flMsecCounter < writeTimeout));            if (!(*currPtr & SR_READY))                {#ifdef DEBUG_PRINT                DEBUG_PRINT("Debug: timeout error in CFISCS write.\n");#endif                status = flWriteFault;                }            *currPtr = i < tailBytes ? lengthByte : lengthByte - 1;            }        tffscpy((unsigned long FAR0 *) flashPtr,temp + from,thisLength);        for (i = 0, currPtr = flashPtr;            ((int)i < vol.interleaving) && ((int)i < thisLength);            i++, currPtr++)            *currPtr = CONFIRM_WRITE;        for (i = 0, currPtr = flashPtr;            ((int)i < vol.interleaving) && ((int)i < thisLength);            i++, currPtr++)            {            while (!(*currPtr & SR_READY) && (flMsecCounter < writeTimeout))                ;            if (!(*currPtr & SR_READY))                {#ifdef DEBUG_PRINT                DEBUG_PRINT("Debug: timeout error in CFISCS write.\n");#endif                status = flWriteFault;                }            if (*currPtr & WSM_ERROR)                {#ifdef DEBUG_PRINT                DEBUG_PRINT("Debug: error in CFISCS write.\n");#endif                status = (*currPtr & SR_VPP_ERROR) ?                          flVppFailure : flWriteFault;                *currPtr = CLEAR_STATUS;                }            *currPtr = READ_ARRAY;            }        }#ifdef SOCKET_12_VOLTS    if (thisCFI->vpp)        flDontNeedVpp(vol.socket);#endif    flashPtr = (FlashPTR) flMap(vol.socket, address);    /* verify the data */    if (status == flOK && tffscmp((void FAR0 *) flashPtr,buffer,length))        {#ifdef DEBUG_PRINT        DEBUG_PRINT("Debug: CFISCS byte write failed in verification.\n");#endif        status = flWriteFault;        }    return status;    }/****************************************************************************** cfiscsWordWrite - write routine for 16 bit devices *                                                                     * Write a block of bytes to Flash in a word-mode.                    *                                                                   * This routine will be registered as the MTD flash.write routine   *                                                                                                                          * RETURNS:                                                *      FLStatus        : 0 on success, failed otherwise  ** ERRNO:** \NOMANUAL*/LOCAL FLStatus cfiscsWordWrite    (    FLFlash vol,               /* Pointer identifying drive     */    CardAddress address,       /* Card address to write to      */    const void FAR1 *buffer,   /* Address of data to write      */    int length,                /* Number of bytes to write      */    int mode                   /* write mode (overwrite yes/no) */    )    {    FLStatus status = flOK;    FlashWPTR flashPtr;    int from, eachWrite;    const char FAR1 *temp = (const char FAR1 *)buffer;    /* Set timeout to 5 seconds from now */    unsigned long writeTimeout = flMsecCounter + 5000;#ifdef DEBUG_PRINT    DEBUG_PRINT("Debug: entering CFISCS word write routine.\n");#endif    if (flWriteProtected(vol.socket))        return flWriteProtect;    if ((length & 1) || (address & 1)) /* Only write words on word-boundary */        return flBadParameter;#ifdef SOCKET_12_VOLTS    if (thisCFI->vpp)        checkStatus(flNeedVpp(vol.socket));#endif    if (thisCFI->maxBytesWrite > 1) /* multi-byte write supported */        eachWrite = thisCFI->maxBytesWrite / 2;   /* we are counting words */    else        eachWrite = 1;    /* we assume that the interleaving is 1. */    for (from = 0; (from < length / 2) && (status == flOK); from += eachWrite)        {        int thisLength = (length / 2) - from;        if (thisLength > eachWrite)            thisLength = eachWrite;        flashPtr = (FlashWPTR)flMap(vol.socket, address + from * 2);        if (thisLength == 1)            {            *flashPtr = PROGRAM ;            *flashPtr = * ( (FlashWPTR) (temp + from * 2) ) ;            }        else            {            /* count > 1 so do a multiple write */            do                 {                *flashPtr = WRITE_TO_BUFFER;                } while (!(*flashPtr & SR_READY) && (flMsecCounter < writeTimeout));            if (!(*flashPtr & SR_READY))                {#ifdef DEBUG_PRINT                DEBUG_PRINT("Debug: timeout error in CFISCS write.\n");#endif                status = flWriteFault;                }            *flashPtr = thisLength - 1;            tffscpyWords((unsigned long FAR0 *) flashPtr, temp + from * 2,                          thisLength * 2);            *flashPtr = CONFIRM_WRITE;            }        while (!(*flashPtr & SR_READY) && (flMsecCounter < writeTimeout))            ;        if (!(*flashPtr & SR_READY))            {#ifdef DEBUG_PRINT            DEBUG_PRINT("Debug: timeout error in CFISCS write.\n");#endif            status = flWriteFault;            }        if (*flashPtr & WSM_ERROR)            {#ifdef DEBUG_PRINT            DEBUG_PRINT("Debug: CFISCS write error.\n");#endif            status = (*flashPtr & SR_VPP_ERROR) ? flVppFailure : flWriteFault;            *flashPtr = CLEAR_STATUS;            }        *flashPtr = READ_ARRAY;        }#ifdef SOCKET_12_VOLTS    if (thisCFI->vpp)        flDontNeedVpp(vol.socket);#endif    flashPtr = (FlashWPTR) flMap(vol.socket, address);    /* verify the data */    if (status == flOK && tffscmp((void FAR0 *) flashPtr,buffer,length))        {#ifdef DEBUG_PRINT        DEBUG_PRINT("Debug: CFISCS word write failed in verification.\n");#endif        status = flWriteFault;        }    return status;    }/******************************************************************************* cfiscsInterleavedWordWrite - write routine 16 bit interleaved devices*                                                                 * This routine will be registered as the MTD flash.write routine      *                                                                                                                                 * RETURNS:                                                   *      FLStatus        : 0 on success, failed otherwise     ** ERRNO:** \NOMANUAL*/LOCAL FLStatus cfiscsInterleavedWordWrite    (    FLFlash vol,                /* Pointer identifying drive     */    CardAddress address,        /* Card address to write to      */    const void FAR1 *buffer,    /* Address of data to write      */    int length,                 /* Number of bytes to write      */    int mode                    /* write mode (overwrite yes/no) */    )                               {    FLStatus status = flOK;    FlashWPTR flashPtr;    unsigned long maxWordsPerWrite,  /* Number of words per WRITE/WRITE_BUFFER 					command. */                wordsWritten,      /* total written so far */                wordsRemaining,    /* number of words left to go */                wordsThisWrite;    /* number of words */ #ifdef DEBUG_PRINT    DEBUG_PRINT("Debug: entering CFISCS interleaved word write routine.\n");#endif

⌨️ 快捷键说明

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