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

📄 storage.c

📁 MP3 Player Source Code
💻 C
字号:
/** \file storage.c * Disk read/write routines. * Implemented Disk interface: MMC. *  * v0.5: added support for more MMC card brands, rewritten code for * better clarity. * * This module reads and writes blocks of disk data to/from a global * buffer. The logical place to define these globals is where they are * needed most: the module that contains the file system functions. * By default that means filesys.c. * These globals are needed (see filesys.h): * - sectorAddress - contains the absolute * disk sector number * - diskSect[512] for data read/write (part of diskSect union) */#include "storage.h"#include "board.h"#include "console.h"#include "mmc.h"#include "buffer.h"//#define MMCDEBUG/** Storage status flags.   * - Bit 1 (LSB): 1=Device does not support interrupted read  * - Bit 2: 1=A sector is seeked and ready for reading * - Bit 3: 1=No storage*/xdata unsigned char storageFlags = 0;   /** Initialize the storage system. * - returns 0 when successful  * - returns 1 if mmc was not properly initialized */Public unsigned char InitStorage(){  unsigned char result;  ConsoleWrite ("Init: Storage v2: supports: MMC,SD,miniSD in SPI mode\r");  result=InitMMC();  if (result==0x0e){ //ok, no support for seek-before-read    ConsoleWrite("Storage initialized in seek-and-read mode.\r");    storageFlags = 1;    return 0;  }  if (result){ //error resulted in MMC startup    ConsoleWrite("InitStorage: Can't start MMC. ");    ConsolePutHex8(result);    ConsolePutChar(13);    storageFlags = 4;    return 1; //MMC Init Error  }  ConsoleWrite("InitStorage ok.\r");  storageFlags = 0;  return 0;}Public unsigned char PrepareToReadDiskSector(unsigned long sectorN){#ifdef MMCDEBUG  ConsoleWrite("<strategy:");  ConsolePutUInt(sectorN);  ConsoleWrite(" Flags:");  ConsolePutHex8(storageFlags);#endif  if (!storageFlags){    //Storage device supports seek-before-read    if (SeekSector(sectorN)){#ifdef MMCDEBUG      ConsoleWrite("Seek Error. strategy>");      #endif      return 0x0f; //seek error code    }    storageFlags |= 0x02; //flag: a sector is seeked for reading#ifdef MMCDEBUG    ConsoleWrite("Seeked. strategy>");#endif    return 0; //ok return  }#ifdef MMCDEBUG  ConsoleWrite("strategy>");#endif  return 0; //ok return}/** Read one 512 byte disk sector to extern global char[512] diskSect. * Returns 0 when successful, error code 6 otherwise. */Public unsigned char ReadDiskSector(unsigned long sectorN){#ifdef MMCDEBUG  ConsoleWrite("<read"); //Read called (strategy, not yet actual read)#endif  //if a sector has not already been seeked, seek now.  if (!(storageFlags&0x02)){ #ifdef MMCDEBUG    ConsoleWrite("F");#endif    if (SeekSector(sectorN)) return 0x0f; //seek error  }    storageFlags &= 0xfd; //clear sector-already-seeked flag  if (ReadPhysicalSector()){    ConsoleWrite("error read>");    return 0x10; //read error  }#ifdef MMCDEBUG    ConsoleWrite("read>");#endif  return 0; /* All OK return */}/** Dump disk sector to console in hexdump form */Public void DumpDiskSector(){  unsigned int ha,la;    ConsoleWrite("\rDiskBlock ");  ConsolePutUInt(sectorAddress.l);  ConsoleWrite(":\r");  for (ha=0; ha<32; ha++){    ConsolePutHex16 ((ha<<4));    ConsoleWrite(": ");    for (la=0; la<16; la++){      ConsolePutHex8(diskSect.raw.buf[(ha<<4)+la]);      ConsolePutChar(' ');      if (la==7){ 	ConsolePutChar(' ');      }    }    ConsolePutChar(' ');    for (la=0; la<16; la++){      if ((diskSect.raw.buf[(ha<<4)+la]) > 30){	ConsolePutChar(diskSect.raw.buf[(ha<<4)+la]);      }else{	ConsolePutChar('.');      }    }    ConsolePutChar('\r');  } }/** Write one 512  byte disk sector from extern global diskSect. * Sector address (0=first 512B sector, 1=2nd. sector, etc.) * is in extern global unsigned long sectorAddress * \warning Unimplemented! */Public void WriteDiskSector(unsigned long sectorN){  sectorAddress.l = sectorN;  dataBufPtr = diskSect.raw.buf;  WritePhysicalSector();}

⌨️ 快捷键说明

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