VLSI Solution Oy VS1103 VLSI Solution Karaoke, MIDI and ADPCM Player Source Code Documentation

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

storage.h File Reference

Disk read/write routines. More...

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

unsigned char InitStorage ()
 Initialize the storage system.
unsigned char ReadDiskSector (unsigned long sectorN)
 Read a disk sector to global buffer.
void DumpDiskSector ()
 Do a hex dump on console of current sector in memory.
void WriteDiskSector (unsigned long sectorN)
 Write current buffer memory to sectorN.
void WriteDiskSectorRec (unsigned long sectorN)
unsigned char TransferSectorSDI (unsigned long sectorN)
unsigned char TransferSectorSCI (unsigned long sectorN)


Detailed Description

Disk read/write routines.

Implemented Disk interface: MMC. 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.h.


Function Documentation

void DumpDiskSector  ) 
 

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

Definition at line 308 of file storage.c.

References DiskBlock::Raw::buf, ConsolePutChar, ConsolePutHex16, ConsolePutHex8, ConsolePutUInt, ConsoleWrite, diskSect, Address::l, Public, DiskBlock::raw, and sectorAddress.

00308                             {
00309   unsigned int ha,la;
00310   
00311   ConsoleWrite("\rDiskBlock ");
00312   ConsolePutUInt(sectorAddress.l);
00313   ConsoleWrite(":\r");
00314   for (ha=0; ha<32; ha++){
00315     ConsolePutHex16 ((ha<<4));
00316     ConsoleWrite(": ");
00317     for (la=0; la<16; la++){
00318       ConsolePutHex8(diskSect.raw.buf[(ha<<4)+la]);
00319       ConsolePutChar(' ');
00320       if (la==7){ 
00321         ConsolePutChar(' ');
00322       }
00323     }
00324     ConsolePutChar(' ');
00325     for (la=0; la<16; la++){
00326       if ((diskSect.raw.buf[(ha<<4)+la]) > 30){
00327         ConsolePutChar(diskSect.raw.buf[(ha<<4)+la]);
00328       }else{
00329         ConsolePutChar('.');
00330       }
00331     }
00332     ConsolePutChar('\r');
00333   } 
00334 }

unsigned char InitStorage  ) 
 

Initialize the storage system.

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

Definition at line 36 of file storage.c.

References ConsolePutChar, ConsolePutHex8, ConsoleWrite, InitMMC(), MOSI_TO_MMC, and Public.

Referenced by RealInitFileSystem().

00036                                   {
00037 
00038   unsigned char result;
00039 
00040   MOSI_TO_MMC = YES;
00041   ConsoleWrite ("Init: Storage: MMC/SD in SPI mode.\r");
00042 
00043   result=InitMMC();
00044   if (result==0x0e){ //ok, no support for seek-before-read
00045     return 0;
00046   }
00047 
00048   if (result){ //error resulted in MMC startup
00049     ConsoleWrite("Can't start MMC: ");
00050     ConsolePutHex8(result);
00051     ConsolePutChar(13);
00052     return 1; //MMC Init Error
00053   }
00054 
00055   ConsoleWrite("InitStorage ok.\r");
00056   return 0;
00057 
00058 }

Here is the call graph for this function:

unsigned char ReadDiskSector unsigned long  sectorN  ) 
 

Read a disk sector to global buffer.

Returns 0 when successful, error code 6 otherwise.

Definition at line 64 of file storage.c.

References ConsoleWrite, MOSI_TO_MMC, Public, ReadPhysicalSector(), and SeekSector().

Referenced by BuildFragmentTable(), FGetChar(), GetFatEntry(), GetNextSector(), LoadNextSector(), OpenFile(), RealInitFileSystem(), and SelectMidiFile().

00064                                                           {
00065   MOSI_TO_MMC = YES;
00066   //ConsolePutChar('s');
00067   if (SeekSector(sectorN)) return 0x0f; //seek error
00068   //ConsolePutChar('S');
00069   if (ReadPhysicalSector()){
00070     ConsoleWrite(" Read Error ");
00071     return 0x10; //read error
00072   }
00073   return 0; /* All OK return */
00074 }

Here is the call graph for this function:

unsigned char TransferSectorSCI unsigned long  sectorN  ) 
 

Definition at line 254 of file storage.c.

References ApplyMidiMap(), DiskBlock::Raw::buf, dataBufPtr, diskSect, MMCDeselect, MMCSelect, MmcWaitForData(), MOSI_TO_MMC, Mp3DeselectControl, Mp3DeselectData, Mp3SelectControl, PerformBlockRead(), DiskBlock::raw, SCI_IN0, SeekSector(), SPI8Clocks(), SPIPutCharWithoutWaiting, SPIWait, and VS_WRITE_COMMAND.

Referenced by PlayerTaskHandler().

00254                                                       {  
00255 
00256 
00257   MOSI_TO_MMC = YES;
00258   Mp3DeselectControl(); //Just in case
00259   Mp3DeselectData(); //Just in case
00260   
00261   if (SeekSector(sectorN)) return 0x0f; //seek error
00262   
00263   
00264   // code from mmc.c: unsigned char ReadPhysicalSector(){
00265   MMCSelect();
00266   MmcWaitForData();
00267   
00268   //GREEN_LED = LED_ON;
00269   PerformBlockRead();  
00270   //GREEN_LED = LED_OFF;
00271   
00272   SPI8Clocks(4); //Send 8*4=32 clocks (4 ff's) to MMC to be nice.
00273   MMCDeselect();
00274   SPI8Clocks(4); //Again, give the poor MMC some clocks, it likes them.
00275   
00276   ApplyMidiMap();
00277   
00278   //GREEN_LED = LED_ON;
00279   Mp3DeselectData(); //Just In Case
00280   // BlockTransmit in C
00281   dataBufPtr = diskSect.raw.buf;
00282   // Use global pointer and unrolled loop for speed
00283   while (dataBufPtr < diskSect.raw.buf+512){
00284     Mp3SelectControl();
00285     SPIPutCharWithoutWaiting(VS_WRITE_COMMAND);SPIWait();
00286     SPIPutCharWithoutWaiting(SCI_IN0);SPIWait();
00287     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait();
00288     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait(); 
00289     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait(); //SciMultiWrite
00290     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait(); 
00291     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait(); //SciMultiWrite
00292     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait(); 
00293     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait(); //SciMultiWrite
00294     SPIPutCharWithoutWaiting(*dataBufPtr++);SPIWait(); 
00295     Mp3DeselectControl();
00296   }
00297   //GREEN_LED = LED_OFF;
00298   
00299   return 0; //ok return
00300 }

Here is the call graph for this function:

unsigned char TransferSectorSDI unsigned long  sectorN  ) 
 

Definition at line 78 of file storage.c.

References DiskBlock::Raw::buf, dataBufPtr, diskSect, MMCDeselect, MMCSelect, MmcWaitForData(), MOSI_TO_MMC, Mp3DeselectControl, Mp3DeselectData, Mp3SelectData, PerformBlockRead(), DiskBlock::raw, SeekSector(), SPI8Clocks(), SPIPutCharWithoutWaiting, and SPIWait.

Referenced by PlayDiskSectors(), and PlayerTaskHandler().

00078                                                       {  
00079 
00080 
00081   MOSI_TO_MMC = YES;
00082   Mp3DeselectControl(); //Just in case
00083   Mp3DeselectData(); //Just in case
00084   
00085   if (SeekSector(sectorN)) return 0x0f; //seek error
00086   // code from mmc.c: unsigned char ReadPhysicalSector(){
00087   MMCSelect();
00088   MmcWaitForData();
00089 
00090 
00091 #if 0
00092   PerformBlockRead();  
00093 
00094   SPI8Clocks(4); //Send 8*4=32 clocks (4 ff's) to MMC to be nice.
00095   MMCDeselect();
00096   SPI8Clocks(4); //Again, give the poor MMC some clocks, it likes them.
00097   
00098   Mp3SelectData();
00099   // BlockTransmit in C
00100   dataBufPtr = diskSect.raw.buf;
00101   // Use global pointer and unrolled loop for speed
00102   while (dataBufPtr < diskSect.raw.buf+512){
00103     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00104     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00105     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00106     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00107     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00108     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00109     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00110     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00111     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00112     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00113     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00114     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00115     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00116     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00117     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00118     SPIPutCharWithoutWaiting(*dataBufPtr++); 
00119   }
00120   Mp3DeselectData();
00121 #else
00122   // FAST DIRECT TRANSFER VERSION
00123   
00124   MOSI_TO_MMC = NO; //force MMC data in to be "1"
00125   SPIPutCharWithoutWaiting(0xff);
00126   SPIWait();
00127   Mp3SelectData();
00128 
00129 #if 0
00130   // C version
00131   {
00132     unsigned int i;
00133     unsigned char c = SPI_RESULT_BYTE;
00134     for (i=0; i<512; i++){
00135       SPIPutCharWithoutWaiting(c);
00136       SPIWait();
00137       c = SPI_RESULT_BYTE;
00138     }
00139   }
00140 #else
00141   // ASM version
00142 
00143 
00144 
00145 
00146 
00147    // BlockRead in Assembler
00148 
00149    _asm
00150         //asm prologue start
00151         push    psw
00152         push    acc
00153         mov     a,r2
00154         push    acc
00155         mov     a,r1
00156         push    acc
00157         //prologue end
00158      
00159      mov r2, #0 // put 256 to r2
00160 3106$:
00161 
00162 3122$:
00163      
00164      mov R1, _SPDAT
00165      mov _SPDAT, R1
00166      nop
00167      mov A, _SPSTA
00168      mov A, _SPSTA
00169      mov A, _SPSTA
00170      
00171 
00172 
00173      mov R1, _SPDAT
00174      mov _SPDAT, R1
00175      nop
00176      mov A, _SPSTA
00177      djnz R2, 3122$
00178 
00179 3108$:        
00180         //asm epilogue start
00181         pop     acc
00182         mov     r1,a
00183         pop     acc
00184         mov     r2,a
00185         pop     acc
00186         pop     psw     
00187         //epilogue end
00188    _endasm;
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 #endif
00198 
00199   Mp3DeselectData();
00200   MOSI_TO_MMC = YES;
00201   SPI8Clocks(4); //Send 8*4=32 clocks (4 ff's) to MMC to be nice.
00202   MMCDeselect();
00203   SPI8Clocks(4); //Again, give the poor MMC some clocks, it likes them.
00204   
00205 #endif
00206 
00207 
00208 
00209   
00210   //RED_LED = LED_OFF;
00211   
00212   return 0; //ok return
00213 }

Here is the call graph for this function:

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 350 of file storage.c.

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

Referenced by PlayerTaskHandler(), and SelectRecordFile().

00350                                                   {
00351   MOSI_TO_MMC = YES;
00352   sectorAddress.l = sectorN;
00353   dataBufPtr = diskSect.raw.buf;
00354   WritePhysicalSector();
00355 }

Here is the call graph for this function:

void WriteDiskSectorRec unsigned long  sectorN  ) 
 


All software copyright 2000-2004 VLSI Solution OY. Redistribution of these software modules is limited to VLSI Solution Oy chip promotional use only. Free or commercial use of these software modules in MP3 players is ok if the product includes chip(s) from VLSI. You can request the complete (compilable) package from mp3@vlsi.fi. This exampe code is provided with good faith to assist You in code development, but under no circumstances will VLSI offer any guarantees on the usability or functionality of any example software or its fitness for any purpose.