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

📄 nandflsh.c

📁 Cirrus Logic EP7312处理器部分控制程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
    // Make sure that we know the layout of the SmartMedia card.
    //
    if(!SMGetSize(0, 0, 0, 0))
    {
        return(0);
    }

    //
    // Select the SmartMedia card.
    //
    *pucPortB |= HwPortBSMCS;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the read1 command.
    //
    *pulPtr = 0x00;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Assert ALE.
    //
    *pucPortB |= HwPortBALE;

    //
    // Write the address.
    //
    *pulPtr = 0x00;
    lIdx = ulPage & 0xFF;
    *pulPtr = lIdx;
    lIdx = (ulPage >> 8) & 0xFF;
    *pulPtr = lIdx;

    //
    // Deassert ALE.
    //
    *pucPortB &= ~HwPortBALE;

    //
    // Wait for a while for the row to copy from the cell array.  The spec.
    // for this delay varies from device to device, so we wait what should be
    // a long enough time for the slowest device.
    //
    for(lIdx = 0; lIdx < 1024; lIdx++)
    {
    }

    //
    // Read the data from this page.
    //
    for(lIdx = 0; lIdx < ulSMPageSize; lIdx++)
    {
        pucBuffer[lIdx] = *pulPtr & 255;
    }

    //
    // Read the spare area if requested.
    //
    if(bReadSpare)
    {
        for(lIdx = 0; lIdx < (ulSMPageSize / 32); lIdx++)
        {
            pucBuffer[ulSMPageSize + lIdx] = *pulPtr & 255;
        }
    }

    //
    // De-select the SmartMedia card.
    //
    *pucPortB &= ~HwPortBSMCS;

    //
    // Success.
    //
    return(1);
}

//****************************************************************************
//
// SMEraseBlock erases the specified block of the SmartMedia card.
//
//****************************************************************************
long
SMEraseBlock(unsigned long ulBlock)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwNANDAddress;
    unsigned char * volatile pucPortB = (unsigned char *)(HwBaseAddress +
                                                          HwPortB);
    long lIdx;

    //
    // Make sure that we know the layout of the SmartMedia card.
    //
    if(!SMGetSize(0, 0, 0, 0))
    {
        return(0);
    }

    //
    // Convert the block number into the page number of the first page of the
    // block.  This is dependent on the number of pages per block.
    //
    switch(ulSMPagesPerBlock)
    {
        case 16:
        {
            ulBlock <<= 4;
            break;
        }

        case 32:
        {
            ulBlock <<= 5;
            break;
        }
    }

    //
    // Select the SmartMedia card.
    //
    *pucPortB |= HwPortBSMCS;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the auto block erase setup command.
    //
    *pulPtr = 0x60;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Assert ALE.
    //
    *pucPortB |= HwPortBALE;

    //
    // Write the address.
    //
    lIdx = ulBlock & 0xFF;
    *pulPtr = lIdx;
    lIdx = (ulBlock >> 8) & 0xFF;
    *pulPtr = lIdx;

    //
    // Deassert ALE.
    //
    *pucPortB &= ~HwPortBALE;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the erase command.
    //
    *pulPtr = 0xd0;

    //
    // Write the read status command.
    //
    *pulPtr = 0x70;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Wait until the erase has completed.
    //
    while((*pulPtr & 0x40) != 0x40)
    {
        for(lIdx = 0; lIdx < 1024; lIdx++)
        {
        }
    }

    //
    // Deselect the SmartMedia card.
    //
    *pucPortB &= ~HwPortBSMCS;

    //
    // Success.
    //
    return(1);
}

//****************************************************************************
//
// SMWritePage writes data to the specified page of the SmartMedia card.
//
//****************************************************************************
long
SMWritePage(unsigned long ulPage, int bWriteSpare, unsigned char *pucBuffer)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwNANDAddress;
    unsigned char * volatile pucPortB = (unsigned char *)(HwBaseAddress +
                                                          HwPortB);
    long lIdx;

    //
    // Make sure that we know the layout of the SmartMedia card.
    //
    if(!SMGetSize(0, 0, 0, 0))
    {
        return(0);
    }

    //
    // Select the SmartMedia card.
    //
    *pucPortB |= HwPortBSMCS;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the sequential data input command.
    //
    *pulPtr = 0x80;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Assert ALE.
    //
    *pucPortB |= HwPortBALE;

    //
    // Write the address.
    //
    *pulPtr = 0x00;
    lIdx = ulPage & 0xFF;
    *pulPtr = lIdx;
    lIdx = (ulPage >> 8) & 0xFF;
    *pulPtr = lIdx;

    //
    // Deassert ALE.
    //
    *pucPortB &= ~HwPortBALE;

    //
    // Write the data to this page.
    //
    for(lIdx = 0; lIdx < ulSMPageSize; lIdx++)
    {
        *pulPtr = pucBuffer[lIdx];
    }

    //
    // Write data for the spare area if requested.
    //
    if(bWriteSpare)
    {
        for(lIdx = 0; lIdx < (ulSMPageSize / 32); lIdx++)
        {
            *pulPtr = pucBuffer[ulSMPageSize + lIdx];
        }
    }

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the program command.
    //
    *pulPtr = 0x10;

    //
    // Write the read status command.
    //
    *pulPtr = 0x70;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Wait until the program has completed.
    //
    while((*pulPtr & 0x40) != 0x40)
    {
        for(lIdx = 0; lIdx < 1024; lIdx++)
        {
        }
    }

    //
    // Deselect the SmartMedia card.
    //
    *pucPortB &= ~HwPortBSMCS;

    //
    // Success.
    //
    return(1);
}
#endif

long
SMReadPage(unsigned long ulPage, int bReadSpare, unsigned char *pucBuffer)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwNANDAddress;
    unsigned char * volatile pucPortB = (unsigned char *)(HwBaseAddress +
                                                          HwPortB);
    long lIdx;

    //
    // Make sure that we know the layout of the SmartMedia card.
    //
    if(!SMGetSize(0, 0, 0, 0))
    {
        return(0);
    }

    //
    // Select the SmartMedia card.
    //
    *pucPortB |= HwPortBSMCS;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the read1 command.
    //
    *pulPtr = 0x00;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Assert ALE.
    //
    *pucPortB |= HwPortBALE;

    //
    // Write the address.
    //
    *pulPtr = 0x00;
    *pulPtr = ulPage & 0xFF;
    *pulPtr = (ulPage >> 8) & 0xFF;

    //
    // Deassert ALE.
    //
    *pucPortB &= ~HwPortBALE;

    //
    // Wait for a while for the row to copy from the cell array.  The spec.
    // for this delay varies from device to device, so we wait what should be
    // a long enough time for the slowest device.
    //
    for(lIdx = 0; lIdx < 1024; lIdx++)
    {
    }

    //
    // Read the data from this page.
    //
    for(lIdx = 0; lIdx < ulSMPageSize; lIdx++)
    {
        pucBuffer[lIdx] = *pulPtr & 255;
    }

    //
    // Read the spare area if requested.
    //
    if(bReadSpare)
    {
        for(lIdx = 0; lIdx < (ulSMPageSize / 32); lIdx++)
        {
            pucBuffer[ulSMPageSize + lIdx] = *pulPtr & 255;
        }
    }

    //
    // De-select the SmartMedia card.
    //
    *pucPortB &= ~HwPortBSMCS;

    //
    // Success.
    //
    return(1);
}

long
SMEraseBlock(unsigned long ulBlock)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwNANDAddress;
    unsigned char * volatile pucPortB = (unsigned char *)(HwBaseAddress +
                                                          HwPortB);
    long lIdx;

    //
    // Make sure that we know the layout of the SmartMedia card.
    //
    if(!SMGetSize(0, 0, 0, 0))
    {
        return(0);
    }

    //
    // Convert the block number into the page number of the first page of the
    // block.  This is dependent on the number of pages per block.
    //
    switch(ulSMPagesPerBlock)
    {
        case 16:
        {
            ulBlock <<= 4;
            break;
        }

        case 32:
        {
            ulBlock <<= 5;
            break;
        }
    }

    //
    // Select the SmartMedia card.
    //
    *pucPortB |= HwPortBSMCS;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the auto block erase setup command.
    //
    *pulPtr = 0x60;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Assert ALE.
    //
    *pucPortB |= HwPortBALE;

    //
    // Write the address.
    //
    *pulPtr = ulBlock & 0xFF;
    *pulPtr = (ulBlock >> 8) & 0xFF;

    //
    // Deassert ALE.
    //
    *pucPortB &= ~HwPortBALE;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the erase command.
    //
    *pulPtr = 0xd0;

    //
    // Write the read status command.
    //
    *pulPtr = 0x70;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Wait until the erase has completed.
    //
    while((*pulPtr & 0x40) != 0x40)
    {
        for(lIdx = 0; lIdx < 1024; lIdx++)
        {
        }
    }

    //
    // Deselect the SmartMedia card.
    //
    *pucPortB &= ~HwPortBSMCS;

    //
    // Success.
    //
    return(1);
}

//****************************************************************************
//
// SMWritePage writes data to the specified page of the SmartMedia card.
//
//****************************************************************************
long
SMWritePage(unsigned long ulPage, int bWriteSpare, unsigned char *pucBuffer)
{
    unsigned long * volatile pulPtr = (unsigned long *)HwNANDAddress;
    unsigned char * volatile pucPortB = (unsigned char *)(HwBaseAddress +
                                                          HwPortB);
    long lIdx;

    //
    // Make sure that we know the layout of the SmartMedia card.
    //
    if(!SMGetSize(0, 0, 0, 0))
    {
        return(0);
    }

    //
    // Select the SmartMedia card.
    //
    *pucPortB |= HwPortBSMCS;

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the sequential data input command.
    //
    *pulPtr = 0x80;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Assert ALE.
    //
    *pucPortB |= HwPortBALE;

    //
    // Write the address.
    //
    *pulPtr = 0x00000000;
    *pulPtr = ulPage & 0xFF;
    *pulPtr = (ulPage >> 8) & 0xFF;

    //
    // Deassert ALE.
    //
    *pucPortB &= ~HwPortBALE;

    //
    // Write the data to this page.
    //
    for(lIdx = 0; lIdx < ulSMPageSize; lIdx++)
    {
        *pulPtr = pucBuffer[lIdx];
    }

    //
    // Write data for the spare area if requested.
    //
    if(bWriteSpare)
    {
        for(lIdx = 0; lIdx < (ulSMPageSize / 32); lIdx++)
        {
            *pulPtr = pucBuffer[ulSMPageSize + lIdx];
        }
    }

    //
    // Assert CLE.
    //
    *pucPortB |= HwPortBCLE;

    //
    // Write the program command.
    //
    *pulPtr = 0x10;

    //
    // Write the read status command.
    //
    *pulPtr = 0x70;

    //
    // Deassert CLE.
    //
    *pucPortB &= ~HwPortBCLE;

    //
    // Wait until the program has completed.
    //
    while((*pulPtr & 0x40) != 0x40)
    {
        for(lIdx = 0; lIdx < 1024; lIdx++)
        {
        }
    }

    //
    // Deselect the SmartMedia card.
    //
    *pucPortB &= ~HwPortBSMCS;

    //
    // Success.
    //
    return(1);
}

⌨️ 快捷键说明

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