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 File Reference

Disk read/write routines. More...

#include "storage.h"
#include "board.h"
#include "console.h"
#include "mmc.h"
#include "buffer.h"

Include dependency graph for storage.c:

Include dependency graph

Go to the source code of this file.

Functions

Public unsigned char InitStorage ()
 Initialize the storage system.

Public unsigned char PrepareToReadDiskSector (unsigned long sectorN)
 Give a hint to the storage that the next sector we will read is sectorN.

Public unsigned char ReadDiskSector (unsigned long sectorN)
 Read a disk sector to global buffer.

Public void DumpDiskSector ()
 Do a hex dump on console of current sector in memory.

Public void WriteDiskSector (unsigned long sectorN)
 Write current buffer memory to sectorN.


Variables

xdata unsigned char storageFlags = 0
 Storage status flags.


Detailed Description

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):

Definition in file storage.c.


Function Documentation

Public void DumpDiskSector  ) 
 

Do a hex dump on console of current sector in memory.

Definition at line 141 of file storage.c.

References DiskBlock::Raw::buf, diskSect, Address::l, Public, DiskBlock::raw, and sectorAddress.

00141 { 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 }

Public unsigned char InitStorage  ) 
 

Initialize the storage system.

  • returns 0 when successful
  • returns 1 if mmc was not properly initialized

Definition at line 43 of file storage.c.

References InitMMC(), Public, and storageFlags.

Referenced by InitFileSystem().

00043 { 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 }

Here is the call graph for this function:

Public unsigned char PrepareToReadDiskSector unsigned long  sectorN  ) 
 

Give a hint to the storage that the next sector we will read is sectorN.

If the storage device supports performing a separate seek before the data is read (for instance MMC card that can be taken off-line between seek and read), storage seeks in this function. The user should not need to worry about this and calling PrepareToReadDiskSector is voluntary.

Definition at line 71 of file storage.c.

References Public, SeekSector(), and storageFlags.

Referenced by PlayDiskSectors().

00071 { 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 }

Here is the call graph for this function:

Public unsigned char ReadDiskSector unsigned long  sectorN  ) 
 

Read a disk sector to global buffer.

Returns 0 when successful, error code 6 otherwise.

Definition at line 110 of file storage.c.

References Public, ReadPhysicalSector(), SeekSector(), and storageFlags.

Referenced by BuildFragmentTable(), FGetChar(), GetAVIBlock(), GetFatEntry(), GetNextSector(), InitFileSystem(), LoadNextSector(), OpenFile(), PlayAvi(), PlayDiskSectors(), Record(), and WriteClusterChain().

00110 { 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 }

Here is the call graph for this function:

Public void WriteDiskSector unsigned long  sectorN  ) 
 

Write current buffer memory to sectorN.

Sector address (0=first 512B sector, 1=2nd. sector, etc.) is in extern global unsigned long sectorAddress

Warning:
Unimplemented!

Definition at line 183 of file storage.c.

References DiskBlock::Raw::buf, dataBufPtr, diskSect, Address::l, Public, DiskBlock::raw, sectorAddress, and WritePhysicalSector().

Referenced by OpenFile(), Record(), and WriteClusterChain().

00183 { 00184 sectorAddress.l = sectorN; 00185 dataBufPtr = diskSect.raw.buf; 00186 WritePhysicalSector(); 00187 }

Here is the call graph for this function:


Variable Documentation

xdata unsigned char storageFlags = 0
 

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

Definition at line 34 of file storage.c.

Referenced by InitStorage(), PrepareToReadDiskSector(), and ReadDiskSector().


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