VLSI Solution Oy VLSI Solution Oy Evaluation MP3 Player Source Code Documentation

Main Page | Class List | File List | Class Members | File Members | Related Pages

storage.c

Go to the documentation of this file.
00001 00019 #include "storage.h" 00020 #include "board.h" 00021 #include "console.h" 00022 #include "mmc.h" 00023 #include "buffer.h" 00024 00025 00026 //#define MMCDEBUG 00027 00028 00034 xdata unsigned char storageFlags = 0; 00035 00036 00037 00043 Public unsigned char InitStorage(){ 00044 00045 unsigned char result; 00046 00047 ConsoleWrite ("Init: Storage v2: supports: MMC,SD,miniSD in SPI mode\r"); 00048 00049 result=InitMMC(); 00050 if (result==0x0e){ //ok, no support for seek-before-read 00051 ConsoleWrite("Storage initialized in seek-and-read mode.\r"); 00052 storageFlags = 1; 00053 return 0; 00054 } 00055 00056 if (result){ //error resulted in MMC startup 00057 ConsoleWrite("InitStorage: Can't start MMC. "); 00058 ConsolePutHex8(result); 00059 ConsolePutChar(13); 00060 storageFlags = 4; 00061 return 1; //MMC Init Error 00062 } 00063 00064 ConsoleWrite("InitStorage ok.\r"); 00065 storageFlags = 0; 00066 return 0; 00067 00068 } 00069 00070 00071 Public unsigned char PrepareToReadDiskSector(unsigned long sectorN){ 00072 00073 #ifdef MMCDEBUG 00074 ConsoleWrite("<strategy:"); 00075 ConsolePutUInt(sectorN); 00076 ConsoleWrite(" Flags:"); 00077 ConsolePutHex8(storageFlags); 00078 #endif 00079 00080 if (!storageFlags){ 00081 //Storage device supports seek-before-read 00082 if (SeekSector(sectorN)){ 00083 00084 #ifdef MMCDEBUG 00085 ConsoleWrite("Seek Error. strategy>"); 00086 #endif 00087 00088 return 0x0f; //seek error code 00089 } 00090 storageFlags |= 0x02; //flag: a sector is seeked for reading 00091 00092 #ifdef MMCDEBUG 00093 ConsoleWrite("Seeked. strategy>"); 00094 #endif 00095 00096 return 0; //ok return 00097 } 00098 00099 #ifdef MMCDEBUG 00100 ConsoleWrite("strategy>"); 00101 #endif 00102 00103 return 0; //ok return 00104 } 00105 00106 00110 Public unsigned char ReadDiskSector(unsigned long sectorN){ 00111 00112 00113 #ifdef MMCDEBUG 00114 ConsoleWrite("<read"); //Read called (strategy, not yet actual read) 00115 #endif 00116 00117 //if a sector has not already been seeked, seek now. 00118 if (!(storageFlags&0x02)){ 00119 #ifdef MMCDEBUG 00120 ConsoleWrite("F"); 00121 #endif 00122 if (SeekSector(sectorN)) return 0x0f; //seek error 00123 } 00124 00125 storageFlags &= 0xfd; //clear sector-already-seeked flag 00126 if (ReadPhysicalSector()){ 00127 ConsoleWrite("error read>"); 00128 return 0x10; //read error 00129 } 00130 00131 #ifdef MMCDEBUG 00132 ConsoleWrite("read>"); 00133 #endif 00134 00135 return 0; /* All OK return */ 00136 } 00137 00138 00139 00141 Public void DumpDiskSector(){ 00142 unsigned int ha,la; 00143 00144 ConsoleWrite("\rDiskBlock "); 00145 ConsolePutUInt(sectorAddress.l); 00146 ConsoleWrite(":\r"); 00147 for (ha=0; ha<32; ha++){ 00148 ConsolePutHex16 ((ha<<4)); 00149 ConsoleWrite(": "); 00150 for (la=0; la<16; la++){ 00151 ConsolePutHex8(diskSect.raw.buf[(ha<<4)+la]); 00152 ConsolePutChar(' '); 00153 if (la==7){ 00154 ConsolePutChar(' '); 00155 } 00156 } 00157 ConsolePutChar(' '); 00158 for (la=0; la<16; la++){ 00159 if ((diskSect.raw.buf[(ha<<4)+la]) > 30){ 00160 ConsolePutChar(diskSect.raw.buf[(ha<<4)+la]); 00161 }else{ 00162 ConsolePutChar('.'); 00163 } 00164 } 00165 ConsolePutChar('\r'); 00166 } 00167 } 00168 00169 00170 00171 00172 00173 00174 00175 00176 00183 Public void WriteDiskSector(unsigned long sectorN){ 00184 sectorAddress.l = sectorN; 00185 dataBufPtr = diskSect.raw.buf; 00186 WritePhysicalSector(); 00187 }

All software copyright 2000-2004 VLSI Solution OY. Redistribution of these software modules are limited to promotional use only and only with the VS1011 / VS1002 / VS1003 MP3-Evakit evaluation boards. Free or commercial use of these software modules in MP3 players is ok if the product includes MP3 decoder chip(s) from VLSI. You can request the complete (compilable) package from mp3@vlsi.fi