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

📄 smartmed.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************//// SMARTMED.C - File system driver for the SmartMedia card.//// Copyright (c) 2000,2001 Cirrus Logic, Inc.////****************************************************************************#include "globals.h"#include "../hwport.h"#include "../hwdefs.h"#include "fat/fat.h"#include "ftl/ftl.h"//****************************************************************************//// The name of this drive.////****************************************************************************static const unsigned short pusDriveName[] ={    'S', 'm', 'a', 'r', 't', 'M', 'e', 'd', 'i', 'a', ' ', 'C',    'a', 'r', 'd', '\0'};//****************************************************************************//// The persistent state of the SmartMedia driver.////****************************************************************************static struct{    //    // The persistent state of the FTL layer used for the SmartMedia card.    //    tFTL sFTL;    //    // The persistent state of the FAT layer used for the SmartMedia card.    //    tFAT sFAT;    //    // Flags indicating the state of the SmartMedia FLASH driver.    //    unsigned long ulFlags;} sSmartMedia;//****************************************************************************//// The set of flags that indicate the state of the SmartMedia FLASH driver.////****************************************************************************#define FLAG_CARD_INSERTED                      0x00000001#define FLAG_CARD_INITIALIZED                   0x00000002#define FLAG_IS_BUSY                            0x80000000//****************************************************************************//// The FLASH driver IOCTL entry point for the SmartMedia card.////****************************************************************************static unsigned longSMFLASHIoctl(unsigned long ulIoctl, unsigned long ulParam1,             unsigned long ulParam2, unsigned long ulParam3,             unsigned long ulParam4){    volatile unsigned long *pulGPIO = (unsigned long *)HwBaseAddress;    //    // Select the SmartMedia card.    //    pulGPIO[HwPortABCD >> 2] &= ~HwPortABCD_SmartMedia_CS;    //    // If the SmartMedia card could be busy, then wait until it is not.    //    if(sSmartMedia.ulFlags & FLAG_IS_BUSY)    {        //        // Wait until the SmartMedia card is not busy.        //        NANDWaitTilNotBusy(HwNANDAddress);        //        // Indicate that the SmartMedia card is not busy.        //        DisableIRQ();        sSmartMedia.ulFlags &= ~FLAG_IS_BUSY;        EnableIRQ();    }    //    // Determine what to do based on the requested IOCTL.    //    switch(ulIoctl)    {        //        // Get the ID of the SmartMedia card.        //        case IOCTL_FLASH_GETID:        {            unsigned long *pulDeviceID = (unsigned long *)ulParam1;            //            // Read the device ID from the SmartMedia card.            //            *pulDeviceID = NANDGetID(HwNANDAddress);            //            // We're done with this request.            //            break;        }        //        // Read a page of data from the SmartMedia card.        //        case IOCTL_FLASH_READ:        {            //            // Read the page of data from the SmartMedia card.            //#ifdef SUPPORT_TINY_MEDIA            if(ulParam4 & FLASH_PS256)            {                //                // This SmartMedia card has 256 bytes per page.                //                NANDRead_256(HwNANDAddress, ulParam1 << 1,                             (unsigned char *)ulParam2,                             (unsigned char *)ulParam3);            }            else#endif            if(ulParam4 & FLASH_ADDR_4_CYCLE)            {                //                // This SmartMedia card has 512 bytes per page and requires 4                // address cycles.                //                NANDRead_512_4(HwNANDAddress, ulParam1,                               (unsigned char *)ulParam2,                               (unsigned char *)ulParam3);            }            else            {                //                // This SmartMedia card has 512 bytes per page and requires 3                // address cycles.                //                NANDRead_512_3(HwNANDAddress, ulParam1,                               (unsigned char *)ulParam2,                               (unsigned char *)ulParam3);            }            //            // We're done with this request.            //            break;        }        //        // Write a page of data to the SmartMedia card.        //        case IOCTL_FLASH_WRITE:        {            //            // Write the page of data to the SmartMedia card.            //#ifdef SUPPORT_TINY_MEDIA            if(ulParam4 & FLASH_PS256)            {                //                // This SmartMedia card has 256 bytes per page.                //                NANDWrite_256(HwNANDAddress, ulParam1 << 1,                              (unsigned char *)ulParam2,                              (unsigned char *)ulParam3);                NANDWrite_256(HwNANDAddress, (ulParam1 << 1) + 1,                              (unsigned char *)ulParam2 + 256,                              (unsigned char *)ulParam3 + 8);            }            else#endif            if(ulParam4 & FLASH_ADDR_4_CYCLE)            {                //                // This SmartMedia card has 512 bytes per page and requires 4                // address cycles.                //                NANDWrite_512_4(HwNANDAddress, ulParam1,                                (unsigned char *)ulParam2,                                (unsigned char *)ulParam3);            }            else            {                //                // This SmartMedia card has 512 bytes per page and requires 3                // address cycles.                //                NANDWrite_512_3(HwNANDAddress, ulParam1,                                (unsigned char *)ulParam2,                                (unsigned char *)ulParam3);            }            //            // Indicate that the SmartMedia card is busy.            //            DisableIRQ();            sSmartMedia.ulFlags |= FLAG_IS_BUSY;            EnableIRQ();            //            // We're done with this request.            //            break;        }        //        // Erase a block of the SmartMedia card.        //        case IOCTL_FLASH_ERASE:        {            //            // Erase this block of the SmartMedia card.            //            if(ulParam2 & FLASH_BS16)            {                //                // This SmartMedia card has 16 pages per block.                //                NANDErase_16(HwNANDAddress, ulParam1);            }            else if(ulParam2 & FLASH_ADDR_4_CYCLE)            {                //                // This SmartMedia card has 32 pages per block and requires 4                // address cycles.                //                NANDErase_32_4(HwNANDAddress, ulParam1);            }            else            {                //                // This SmartMedia card has 32 pages per block and requires 3                // address cycles.                //                NANDErase_32_3(HwNANDAddress, ulParam1);            }            //            // Indicate that the SmartMedia card is busy.            //            DisableIRQ();            sSmartMedia.ulFlags |= FLAG_IS_BUSY;            EnableIRQ();            //            // We're done with this request.            //            break;        }        //        // Read the redundant data from a page of the SmartMedia card.        //        case IOCTL_FLASH_READ_REDT:        {            //            // Read the redundant data from the SmartMedia card.            //#ifdef SUPPORT_TINY_MEDIA            if(ulParam3 & FLASH_PS256)            {                //                // This SmartMedia card has 256 bytes per page.                //                NANDReadRedt_256(HwNANDAddress, ulParam1 << 1,                                 (unsigned char *)ulParam2);            }            else#endif            if(ulParam3 & FLASH_ADDR_4_CYCLE)            {                //                // This SmartMedia card has 512 bytes per page and requires 4                // address cycles.                //                NANDReadRedt_512_4(HwNANDAddress, ulParam1,                                   (unsigned char *)ulParam2);            }            else            {                //                // This SmartMedia card has 512 bytes per page and requires 3                // address cycles.                //                NANDReadRedt_512_3(HwNANDAddress, ulParam1,                                   (unsigned char *)ulParam2);            }            //            // We're done with this request.            //            break;        }        //        // Write the redundant data to a page of the SmartMedia card.        //        case IOCTL_FLASH_WRITE_REDT:        {            //            // Write the redundant data to the SmartMedia card.            //#ifdef SUPPORT_TINY_MEDIA            if(ulParam3 & FLASH_PS256)            {                //                // This SmartMedia card has 256 bytes per page.                //                NANDWriteRedt_256(HwNANDAddress, ulParam1 << 1,                                  (unsigned char *)ulParam2);                NANDWriteRedt_256(HwNANDAddress, (ulParam1 << 1) + 1,                                  (unsigned char *)ulParam2 + 8);            }            else#endif

⌨️ 快捷键说明

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