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

📄 nandfs.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 3 页
字号:
            {                //                // There are 1024 blocks in this device.                //                sNAND.usNumBlocks = 1024;                //                // There are 32 pages per block in this device.                //                sNAND.ucPagesPerBlock = 32;                //                // Fill in the function pointers for accessing this FLASH                // device.                //                sNAND.pfnRead = NANDRead_512_3;                sNAND.pfnWrite = NANDWrite_512_3;                sNAND.pfnErase = NANDErase_32_3;                //                // We've interpreted the device ID.                //                break;            }            //            // The device capacity is 32MB.            //            case 0x75:            {                //                // There are 2048 blocks in this device.                //                sNAND.usNumBlocks = 2048;                //                // There are 32 pages per block in this device.                //                sNAND.ucPagesPerBlock = 32;                //                // Fill in the function pointers for accessing this FLASH                // device.                //                sNAND.pfnRead = NANDRead_512_3;                sNAND.pfnWrite = NANDWrite_512_3;                sNAND.pfnErase = NANDErase_32_3;                //                // We've interpreted the device ID.                //                break;            }            //            // The device capacity is 64MB.            //            case 0x76:            {                //                // There are 4096 blocks in this device.                //                sNAND.usNumBlocks = 4096;                //                // There are 32 pages pre block in this device.                //                sNAND.ucPagesPerBlock = 32;                //                // Fill in the function pointers for accessing this FLASH                // device.                //                sNAND.pfnRead = NANDRead_512_4;                sNAND.pfnWrite = NANDWrite_512_4;                sNAND.pfnErase = NANDErase_32_4;                //                // We've interpreted the device ID.                //                break;            }            //            // The device capacity is 128MB.            //            case 0x79:            {                //                // There are 8192 blocks in this device.                //                sNAND.usNumBlocks = 8192;                //                // There are 32 pages per block in this device.                //                sNAND.ucPagesPerBlock = 32;                //                // Fill in the function pointers for accessing this FLASH                // device.                //                sNAND.pfnRead = NANDRead_512_4;                sNAND.pfnWrite = NANDWrite_512_4;                sNAND.pfnErase = NANDErase_32_4;                //                // We've interpreted the device ID.                //                break;            }            //            // Either the FLASH device could not be found or it has an unknown            // device ID.            //            default:            {                //                // Return a failure.                //                sNAND.usNumBlocks = 0;                sNAND.ucPagesPerBlock = 0;                pulGPIO[HwPortABCD >> 2] |= HwPortABCD_NAND1_CS;                return(0);            }        }        //        // See if the on-board NAND FLASH is formatted.        //        if(!CheckNAND(pucScratch, pucWriteBuffer))        {            //            // The on-board NAND FLASH is not formatted, so format it now.            //            FormatNAND(pucScratch, pucWriteBuffer);        }        //        // Read the length of the file.        //        ulDeviceID = sNAND.ucPagesPerBlock - 1;        NextPage(&ulDeviceID);        (sNAND.pfnRead)(HwNANDAddress, ulDeviceID, pucScratch, pucWriteBuffer);        sNAND.ulFileLength = pucScratch[0] | (pucScratch[1] << 8) |                             (pucScratch[2] << 16) | (pucScratch[3] << 24);        //        // De-select the on-board NAND FLASH.        //        pulGPIO[HwPortABCD >> 2] |= HwPortABCD_NAND1_CS;        //        // Success.        //        return(1);    }    //    // Make sure that we were able to successfully initialize the on-board NAND    // FLASH.  Return a failure if we could not.    //    if(sNAND.usNumBlocks == 0)    {        return(0);    }    //    // Determine what to do based on the specified IOCTL.    //    switch(ulIoctl)    {        //        // Return the media unique ID.        //        case IOCTL_FS_GETMEDIAID:        {            //            // We do not support a media unique ID, so return failure.            //            return(0);        }        //        // Open the specified file.  We do not support multiple files, so we        // also don't care what the file name is...any open will work for the        // single file in the file system.        //        case IOCTL_FS_OPEN:        {            tNANDFile *pFile;            //            // We do not support writing to a file that we do not create.            //            if((ulParam2 & FS_OPEN_CREATE) && !(ulParam2 & FS_OPEN_WRITE))            {                return(0);            }            //            // Get a pointer to the file structure.            //            pFile = (tNANDFile *)ulInstance;            //            // Get the first page used to store file data.            //            pFile->ulPage = sNAND.ucPagesPerBlock - 1;            NextPage(&(pFile->ulPage));            //            // Select the on-board NAND FLASH.            //            pulGPIO[HwPortABCD >> 2] &= ~HwPortABCD_NAND1_CS;            //            // Are we reading or writing?            //            if(ulParam2 & FS_OPEN_READ)            {                //                // If the file length is zero, then there is no file in the                // on-board NAND FLASH, so return a failure.                //                if(sNAND.ulFileLength == 0)                {                    pulGPIO[HwPortABCD >> 2] |= HwPortABCD_NAND1_CS;                    return(0);                }            }            else            {                //                // Erase the first block of the on-board NAND FLASH.                //                NANDWaitTilNotBusy(HwNANDAddress);                (sNAND.pfnErase)(HwNANDAddress,                                 pFile->ulPage / sNAND.ucPagesPerBlock);                //                // Skip to the next page of the on-board NAND FLASH.                //                NextPage(&(pFile->ulPage));                //                // The initial file length is zero.                //                sNAND.ulFileLength = 0;            }            //            // Set the file position to the beginning.            //            pFile->ulFilePos = 0;            //            // De-select the on-board NAND FLASH.            //            pulGPIO[HwPortABCD >> 2] |= HwPortABCD_NAND1_CS;            //            // Success.            //            return(1);        }        //        // Create the specified file.        //        case IOCTL_FS_CREATE:        {            tNANDFile *pFile;            //            // Get a pointer to the file structure.            //            pFile = (tNANDFile *)ulInstance;            //            // Get the first page used to store file data.            //            pFile->ulPage = sNAND.ucPagesPerBlock - 1;            NextPage(&(pFile->ulPage));            //            // Select the on-board NAND FLASH.            //            pulGPIO[HwPortABCD >> 2] &= ~HwPortABCD_NAND1_CS;            //            // Erase the first block of the on-board NAND FLASH.            //            NANDWaitTilNotBusy(HwNANDAddress);            (sNAND.pfnErase)(HwNANDAddress,                             pFile->ulPage / sNAND.ucPagesPerBlock);            //            // Skip to the next page of the on-board NAND FLASH.            //            NextPage(&(pFile->ulPage));            //            // The initial file length is zero.            //            sNAND.ulFileLength = 0;            //            // Set the file position to the beginning.            //            pFile->ulFilePos = 0;            //            // De-select the on-board NAND FLASH.            //            pulGPIO[HwPortABCD >> 2] |= HwPortABCD_NAND1_CS;            //            // Success.            //            return(1);        }        //        // Read data from the currently opened file.        //        case IOCTL_FS_READ:        {            tNANDFile *pFile;            unsigned long ulCount;            //            // Make sure that the number of bytes requested is a multiple of            // 512.            //            if(ulParam2 & 511)            {                return(0);            }            //            // Get a pointer to the file structure.            //            pFile = (tNANDFile *)ulInstance;            //            // Select the on-board NAND FLASH.            //            pulGPIO[HwPortABCD >> 2] &= ~HwPortABCD_NAND1_CS;            //            // Read pages from the on-board NAND FLASH.            //            ulCount = 0;            while(ulParam2)            {                //                // Stop reading if we've reached the end of the file.                //                if(pFile->ulFilePos >= sNAND.ulFileLength)                {                    break;                }                //                // Read the next page from the on-board NAND FLASH.                //                (sNAND.pfnRead)(HwNANDAddress, NextPage(&(pFile->ulPage)),                                (unsigned char *)ulParam1, pucScratch);                //                // Increment the read buffer pointer.                //                ulParam1 += 512;                //                // Decrement the count of bytes to read.                //                ulParam2 -= 512;                //                // Increment the file position.                //                pFile->ulFilePos += 512;                //                // Increment the count of bytes read.                //                ulCount += 512;            }            //            // De-select the on-board NAND FLASH.            //            pulGPIO[HwPortABCD >> 2] |= HwPortABCD_NAND1_CS;            //            // Success.            //            return(ulCount);        }        //        // Read data from the currently opened file, performing a byte-swap.        //        case IOCTL_FS_READ_BS:        {            tNANDFile *pFile;            unsigned long ulCount, ulIdx;            //            // Make sure that the number of bytes requested is a multiple of            // 512.            //            if(ulParam2 & 511)            {                return(0);            }            //            // Get a pointer to the file structure.            //            pFile = (tNANDFile *)ulInstance;            //            // Select the on-board NAND FLASH.            //            pulGPIO[HwPortABCD >> 2] &= ~HwPortABCD_NAND1_CS;            //            // Read pages from the on-board NAND FLASH.            //            ulCount = 0;            while(ulParam2)            {                //                // Stop reading if we've reached the end of the file.                //                if(pFile->ulFilePos >= sNAND.ulFileLength)                {                    break;                }                //                // Read the next page from the on-board NAND FLASH, byte                // swapping the data as we read it.                //                (sNAND.pfnRead)(HwNANDAddress, NextPage(&(pFile->ulPage)),                                (unsigned char *)ulParam1, pucScratch);                //                // Swap the bytes in the page.                //                for(ulIdx = 0; ulIdx < 512; ulIdx += 4)                {                    unsigned long ulTemp;                    ulTemp = ((unsigned long *)ulParam1)[ulIdx >> 2];                    ulTemp = ((ulTemp << 24) & 0xff000000) |                             ((ulTemp << 8) & 0x00ff0000) |                             ((ulTemp >> 8) & 0x0000ff00) |                             ((ulTemp >> 24) & 0x000000ff);                    ((unsigned long *)ulParam1)[ulIdx >> 2] = ulTemp;                }                //                // Increment the read buffer pointer.                //                ulParam1 += 512;                //                // Decrement the count of bytes to read.                //                ulParam2 -= 512;                //                // Increment the file position.                //                pFile->ulFilePos += 512;                //                // Increment the count of bytes read.

⌨️ 快捷键说明

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