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

vs10xx.c File Reference

Functions for interfacing with the mp3 player chip. More...

#include "vs10xx.h"
#include "lcd.h"
#include "filesys.h"
#include "storage.h"
#include "ui.h"

Include dependency graph for vs10xx.c:

Include dependency graph

Go to the source code of this file.

Functions

unsigned int Mp3ReadRegister (unsigned char addressbyte)
 Read the 16-bit value of a VS10xx register.
void LoadPatch ()
 Load a patch code to VS10xx.
void StartPatch ()
 Start patch code.
void Vs1103SetMode ()
void Mp3SoftReset ()
 Soft Reset of VS10xx (Between songs).
void Mp3Reset ()
 Reset VS10xx.
void VsSineTest ()
 Execute VS1011/VS1002 Sine Test Function.
void SendZerosToVS10xx ()
 Send 2048 zeros.
unsigned char PlayDiskSectors (unsigned int nSectorsToPlay)
 Play disk sectors from disk.
void Mp3SetMixerVolume (unsigned char gain1, unsigned char gain2, unsigned char gainInput)
void Vs1103B_SetMidiTranspose (int transpose)
 VS1103B specific function: set MasterTranspose.
void Vs1103B_SetChannelMask (unsigned int newMask)
 VS1103B specific function: select MIDI channels.
void Vs1103SetMicGain (unsigned char gain)
 Set MIC analog amplifier value.
void Vs1103CancelWave ()
 Terminate wave stream playing.
void Vs1103CancelMidi ()
 Terminate MIDI stream playing.

Variables

bit vs1103_recording_active
 VS1103 MODE bit.
bit vs1103_record_mixer
 VS1103 MODE bit.
bit vs1103_use_line_input
 VS1103 MODE bit.
bit vs1103_do_reset
 VS1103 MODE bit.
bit vs1103_mono_output
 VS1103 MODE bit.
bit vs1103_terminate
 VS1103 MODE bit.
bit vs1103_earSpkHi
 VS1103 MODE bit.
bit vs1103_earSpkLo
 VS1103 MODE bit.
bit vs1103_real_time_midi
 VS1103 MODE bit.
unsigned char currentMicGain


Detailed Description

Functions for interfacing with the mp3 player chip.

Todo:
safe rewind

VS1003 WMA "wma-bytes-left" variable adjustment at ff/rew

Definition in file vs10xx.c.


Function Documentation

void LoadPatch  ) 
 

Load a patch code to VS10xx.

Definition at line 157 of file player.c.

References ConsoleWrite, Delay(), Temp::i, Mp3WriteRegister, and temp.

Referenced by Mp3Reset(), and SetMidiFromUART().

00157                 {
00158 #if 1
00159   ConsoleWrite ("Loading patch.\r");
00160   for (temp.i=0; temp.i < CODELEN; temp.i++) {    
00161     while (!MP3_DREQ)
00162       ;
00163     Mp3WriteRegister(atab[temp.i], dtab[temp.i]>>8, dtab[temp.i]&0xff);
00164     while (!MP3_DREQ)
00165       ;
00166    }
00167   Delay(10);
00168 #endif
00169 }

Here is the call graph for this function:

unsigned int Mp3ReadRegister unsigned char  addressbyte  ) 
 

Read the 16-bit value of a VS10xx register.

Definition at line 17 of file vs10xx.c.

References Mp3DeselectControl, Mp3SelectControl, SPIPutChar, SPIPutCharWithoutWaiting, SPIWait, and VS_READ_COMMAND.

Referenced by AvailableProcessorTime(), main(), PlayerTaskHandler(), UpdateDisplay(), and Vs1103CancelWave().

00017                                                         {
00018   unsigned int resultvalue = 0;
00019 
00020   Mp3SelectControl();
00021   SPIPutCharWithoutWaiting(VS_READ_COMMAND);
00022   SPIPutChar((addressbyte));
00023   SPIPutChar(0xff);
00024   SPIWait();
00025   resultvalue = (SPI_RESULT_BYTE) << 8;
00026   SPIPutCharWithoutWaiting(0xff);
00027   SPIWait();
00028   resultvalue |= (SPI_RESULT_BYTE);
00029   Mp3DeselectControl();
00030   return resultvalue;
00031 }

void Mp3Reset  ) 
 

Reset VS10xx.

Definition at line 136 of file vs10xx.c.

References ConsoleWrite, Delay(), LoadPatch(), Mp3DeselectControl, Mp3DeselectData, Mp3PutInReset, Mp3ReleaseFromReset, Mp3SetMixerVolume(), Mp3SetVolume, Mp3SoftReset(), Mp3WriteRegister, SCI_CLOCKF, SPIPutCharWithoutWaiting, SPISetFastClock, SPISetSlowClock, volume, vs1103_do_reset, vs1103_earSpkHi, vs1103_earSpkLo, vs1103_mono_output, vs1103_real_time_midi, vs1103_record_mixer, vs1103_recording_active, vs1103_terminate, vs1103_use_line_input, and Vs1103SetMode().

Referenced by main().

00136                {
00137 
00138   vs1103_recording_active = 0;
00139   vs1103_record_mixer = 1;
00140   vs1103_use_line_input = 1;
00141   vs1103_do_reset = 0;
00142   vs1103_mono_output = 0;
00143   vs1103_terminate = 0;
00144   vs1103_earSpkHi = 0;
00145   vs1103_earSpkLo = 0;
00146   vs1103_real_time_midi = 0;
00147   
00148   SPISetSlowClock();
00149 
00150   Mp3PutInReset();
00151   Delay(1);
00152 
00153   /* Send dummy SPI byte to initialize SPI */
00154   SPIPutCharWithoutWaiting(0xFF);
00155 
00156   /* Un-reset MP3 chip */
00157   Mp3DeselectControl();
00158   Mp3DeselectData();
00159   Mp3ReleaseFromReset();
00160 
00161   Delay(1);
00162   while(!MP3_DREQ);
00163   /* Start up analog with no sound */
00164   Mp3SetVolume(0xfe,0xfe);
00165   Mp3SetMixerVolume(0,0,0);
00166   LoadPatch();
00167   Vs1103SetMode();
00168 
00169   /* Set clock register, doubler etc. */
00170   Mp3WriteRegister(SCI_CLOCKF, 0xa6, 0x96); //oli 0xa66c
00171 
00172 
00173   Delay(500);
00174 
00175   Mp3SetMixerVolume(1,1,1);
00176   //ConsoleWrite("Mixer111 ");
00177   //Delay(1000);
00178   //Mp3SetVolume(0xfe,0xfe);
00179   //ConsoleWrite("Mixer 1,1,1 SecondDelay");
00180   //Delay(2000);
00181   Mp3SetVolume(volume,volume);
00182 
00183   SPISetFastClock();
00184 
00185   Mp3SoftReset();
00186 
00187   //ConsoleWrite("Clock:");ConsolePutHex16(Mp3ReadRegister(SCI_CLOCKF));
00188   ConsoleWrite ("\rInit: VS10XX\r");
00189 
00190 }

Here is the call graph for this function:

void Mp3SetMixerVolume unsigned char  gain1,
unsigned char  gain2,
unsigned char  gainInput
 

Definition at line 303 of file vs10xx.c.

References Mp3WriteRegister, and SCI_MIXERVOL.

Referenced by AvailableProcessorTime(), EchoEnable(), main(), Mp3Reset(), and Mp3SoftReset().

00305                                                {
00306   unsigned int i;
00307 
00308   i=0x8000; // Mixer Mode On
00309   i |= (gainInput << 10);
00310   i |= (gain2 << 5);
00311   i |= (gain1);
00312 
00313   Mp3WriteRegister(SCI_MIXERVOL, (i >> 8), (i & 0xff));
00314 
00315 }

void Mp3SoftReset  ) 
 

Soft Reset of VS10xx (Between songs).

Definition at line 97 of file vs10xx.c.

References Delay(), Mp3DeselectData, Mp3SelectData, Mp3SetMixerVolume(), Mp3WriteRegister, SCI_ADPCMRECCTL, SPIPutChar, SPIPutCharWithoutWaiting, SPIWait, USE_512_BYTE_DREQ, vs1103_do_reset, and Vs1103SetMode().

Referenced by Mp3Reset().

00097                    {
00098 
00099   /* Soft Reset of VS10xx */
00100   vs1103_do_reset = 1;
00101   Vs1103SetMode();
00102   vs1103_do_reset = 0;
00103  
00104   Delay(1); /* One millisecond delay */
00105   while (!MP3_DREQ) /* wait for startup */
00106     ;
00107   
00108   Mp3SetMixerVolume(25,25,25);
00109 
00110   Delay(1);
00111   //Mp3WriteRegister(SCI_CLOCKF, 0xa6, 0x96);
00112 
00113 
00114   // Set default microphone gain
00115   Delay(1);
00116   Mp3WriteRegister(SCI_ADPCMRECCTL, USE_512_BYTE_DREQ, 0x00 | 20);
00117   
00118   
00119   Delay(1); /* One millisecond delay */
00120   
00121   /* Send null bytes to data interface */
00122   Mp3SelectData();
00123   SPIPutCharWithoutWaiting(0);
00124   SPIPutChar(0);
00125   SPIPutChar(0);
00126   SPIPutChar(0);
00127   SPIWait();
00128   Mp3DeselectData();
00129 
00130 }

Here is the call graph for this function:

unsigned char PlayDiskSectors unsigned int  nSectorsToPlay  ) 
 

Play disk sectors from disk.

Starting from current value in global variable sectorAddress, sends a number of disk sectors to vs10xx and returns.

Definition at line 276 of file vs10xx.c.

References AvailableProcessorTime(), Address::l, playingState, sectorAddress, and TransferSectorSDI().

00276                                                            {
00277 
00278   while (nSectorsToPlay){
00279 
00280     if (MP3_DREQ){
00281       TransferSectorSDI(sectorAddress.l);
00282       sectorAddress.l++;
00283       nSectorsToPlay--;
00284     }
00285 
00286     AvailableProcessorTime(); //Call the User Interface handler
00287 
00288     /* If playing state is something else than "play normally",
00289        exit returning the request number. */
00290     if ((playingState==PS_END_OF_SONG)||
00291         (playingState==PS_NEXT_SONG)||
00292         (playingState==PS_RECORDING)||
00293         (playingState==PS_PREVIOUS_SONG)){
00294       return playingState;
00295     }
00296     
00297   }
00298   return 0; //OK Exit
00299 }

Here is the call graph for this function:

void SendZerosToVS10xx  ) 
 

Send 2048 zeros.

Todo:
Timeouts for all DREQ busy loop waits!

Definition at line 260 of file vs10xx.c.

References Temp::i, Mp3DeselectData, Mp3SelectData, SPIPutChar, SPIPutCharWithoutWaiting, SPIWait, and temp.

00260                         {
00261   Mp3SelectData();
00262   SPIPutCharWithoutWaiting(0);
00263   for (temp.i=0; temp.i<2048; temp.i++){ /* TESTING 1048 TESTING */
00264     while (!MP3_DREQ)
00265       ;
00266     SPIPutChar(0);
00267   }
00268   SPIWait();
00269   Mp3DeselectData();
00270 }  

void StartPatch  ) 
 

Start patch code.

Definition at line 172 of file player.c.

References ConsoleWrite, Mp3WriteRegister, and SCI_AIADDR.

Referenced by Vs1103SetMode().

00173 {
00174   ConsoleWrite("Start Patch.\r");
00175     while (!MP3_DREQ)
00176       ;
00177 #if 1
00178   Mp3WriteRegister(SCI_AIADDR, 0x00, 0x30);
00179     while (!MP3_DREQ)
00180       ;
00181 #endif
00182 }

void Vs1103B_SetChannelMask unsigned int  newMask  ) 
 

VS1103B specific function: select MIDI channels.

Definition at line 323 of file vs10xx.c.

References Mp3WriteRegister, SCI_WRAM, and SCI_WRAMADDR.

Referenced by AvailableProcessorTime(), and SelectMidiFile().

00323                                                  {
00324   Mp3WriteRegister(SCI_WRAMADDR, 0x17, 0x15);
00325   while (!MP3_DREQ);
00326   Mp3WriteRegister(SCI_WRAM,(newMask >> 8),(newMask));
00327 }

void Vs1103B_SetMidiTranspose int  transpose  ) 
 

VS1103B specific function: set MasterTranspose.

Definition at line 317 of file vs10xx.c.

References Mp3WriteRegister, SCI_WRAM, SCI_WRAMADDR, and transpose.

Referenced by AvailableProcessorTime().

00317                                             {
00318   Mp3WriteRegister(SCI_WRAMADDR, 0x11, 0x32);
00319   while (!MP3_DREQ);
00320   Mp3WriteRegister(SCI_WRAM,(transpose >> 8),(transpose));
00321 }

void Vs1103CancelMidi  ) 
 

Terminate MIDI stream playing.

Definition at line 343 of file vs10xx.c.

References vs1103_terminate, and Vs1103SetMode().

Referenced by CancelMidi().

00343                        {
00344   vs1103_terminate = 1;
00345   Vs1103SetMode();        
00346   vs1103_terminate = 0;
00347   // The below lines are recommended but take a little
00348   // too much time for our non-multitasking 8051 
00349   // architecture:
00350   //while (Mp3ReadRegister(SCI_MODE) & SM_OUTOFMIDI)
00351   //  ;
00352 
00353 }

Here is the call graph for this function:

void Vs1103CancelWave  ) 
 

Terminate wave stream playing.

Definition at line 335 of file vs10xx.c.

References currentMicGain, Mp3ReadRegister(), Mp3WriteRegister, SCI_ADPCMRECCTL, and USE_512_BYTE_DREQ.

Referenced by CancelWave(), and SelectWaveFile().

00335                        {
00336   Mp3WriteRegister(SCI_ADPCMRECCTL, USE_512_BYTE_DREQ, 0x80 | currentMicGain);
00337 
00338   while (Mp3ReadRegister(SCI_ADPCMRECCTL) & 0x0080)
00339     ;
00340 }

Here is the call graph for this function:

void Vs1103SetMicGain unsigned char  gain  ) 
 

Set MIC analog amplifier value.

Definition at line 329 of file vs10xx.c.

References currentMicGain, Mp3WriteRegister, SCI_ADPCMRECCTL, and USE_512_BYTE_DREQ.

Referenced by AvailableProcessorTime(), and main().

00329                                          {
00330   if (gain>31) gain=31;
00331   currentMicGain = gain;
00332   Mp3WriteRegister(SCI_ADPCMRECCTL, USE_512_BYTE_DREQ, 0x40 | gain);
00333 }

void Vs1103SetMode  ) 
 

Definition at line 48 of file vs10xx.c.

References ConsolePutChar, ConsolePutHex8, ConsoleWrite, Mp3WriteRegister, SCI_MODE, SCI_WRAM, SCI_WRAMADDR, and StartPatch().

Referenced by CancelRecord(), EchoEnable(), main(), Mp3Reset(), Mp3SoftReset(), SelectRecordFile(), SetMidiFromFile(), SetMidiFromUART(), and Vs1103CancelMidi().

00048                     {
00049   unsigned char hiMode, loMode;
00050   
00051   hiMode = SM_SDINEW;
00052   loMode = SM_SDI_ADPCM;
00053 
00054   if (vs1103_use_line_input) hiMode |= SM_LINE_IN;
00055   if (vs1103_recording_active) hiMode |= SM_RECORD_ADPCM;
00056   if (vs1103_earSpkLo) hiMode |= SM_EARSPK_1;
00057   if (vs1103_earSpkHi) hiMode |= SM_EARSPK_2;
00058   
00059   if (vs1103_do_reset) loMode |= SM_RESET;
00060   if (vs1103_mono_output) loMode |= SM_DIFF;
00061   if (vs1103_record_mixer) loMode |= SM_RECORD_MIXER;
00062   if (vs1103_terminate) loMode |= SM_OUTOFMIDI;
00063   if (vs1103_real_time_midi) loMode |= SM_RT_MIDI;
00064 
00065   if (vs1103_real_time_midi){
00066     //Enable VS1103 UART interrupt
00067     Mp3WriteRegister(SCI_WRAMADDR, 0xc0, 0x1a);
00068     Mp3WriteRegister(SCI_WRAM, 0x00, 0x3f);
00069   }
00070 
00071   Mp3WriteRegister (SCI_MODE, hiMode, loMode);
00072   ConsoleWrite("SetMode: ");
00073   ConsolePutHex8(hiMode);
00074   ConsolePutHex8(loMode);
00075   ConsolePutChar(13);
00076 
00077   
00078   while (!MP3_DREQ)
00079     ;//wait for operation to complete
00080 
00081 
00082   if (!vs1103_real_time_midi){
00083     //When real-time midi input is not active,
00084     //Uart RX goes to monitor interrupt. To prevent
00085     //from falling to the monitor, disable RX interrupt
00086     //now
00087     Mp3WriteRegister(SCI_WRAMADDR, 0xc0, 0x1a);
00088     Mp3WriteRegister(SCI_WRAM, 0x00, 0x0f);
00089   } 
00090   
00091   StartPatch();
00092   
00093 }

Here is the call graph for this function:

void VsSineTest  ) 
 

Execute VS1011/VS1002 Sine Test Function.

Definition at line 194 of file vs10xx.c.

References Delay(), Mp3DeselectControl, Mp3DeselectData, Mp3PutInReset, Mp3ReleaseFromReset, Mp3SelectControl, Mp3SelectData, SPIPutChar, SPIPutCharWithoutWaiting, and SPIWait.

00194                  {
00195 
00196   /* Reset MP3 chip */
00197   Mp3PutInReset();       /* Pull xRESET low -> hardware reset */
00198   Delay(100);            /* 100 ms delay */
00199 
00200   /* Send dummy SPI byte to initialize SPI of Atmel microcontroller */
00201   SPIPutCharWithoutWaiting(0xFF);
00202 
00203   /* Un-reset MP3 chip */
00204   Mp3DeselectControl();  /* Pull xCS high    */
00205   Mp3DeselectData();     /* Pull xDCS high   */
00206   Mp3ReleaseFromReset(); /* Pull xRESET high */
00207   Delay(100);            /* 100 ms delay     */
00208 
00209   //GREEN_LED = LED_ON;
00210   //RED_LED = LED_ON;
00211 
00212   /* VS10xx Application Notes, chapter 4.8 ---------------------------------*/
00213   /* As an example, let's write value 0x0820 to register 00 byte by byte    */
00214   Mp3SelectControl();    /* Now SPI writes go to SCI port                   */
00215   SPIPutChar(0x02);      /* Send SPI Byte, then wait for byte to be sent.   */
00216   SPIPutChar(0x00);      /* 0x02 was WRITE command, 0x00 is register number */
00217   SPIPutChar(0x08);      /* This byte goes to MSB                           */
00218   SPIPutChar(0x20);      /* ..and this is LSB. (0x20=Allow Test Mode)       */
00219   SPIWait();             /* Wait until Atmel MCU signals SPI write complete */
00220   Mp3DeselectControl();  /* Now SPI writes don't go to SCI port             */
00221 
00222   while (!MP3_DREQ)      /* Wait for DREQ = 1                               */
00223     ;                    /* Do nothing while waiting for DREQ = 1           */
00224 
00225   /* Send a Sine Test Header to Data port                                   */
00226   Mp3SelectData();       /* Now SPI writes go to SDI port                   */
00227 
00228   SPIPutChar(0x53);      /* - This is a special VLSI Solution test header - */
00229   SPIPutChar(0xef);      /* - that starts a sine sound. It's good for     - */
00230   SPIPutChar(0x6e);      /* - testing your code, the chip and also for    - */
00231   SPIPutChar(0x44);      /* - seeing if your MP3 decoder was manufactured - */
00232   SPIPutChar(0x00);      /* - by VLSI Solution oy. ------------------------ */
00233   SPIPutChar(0x00);
00234   SPIPutChar(0x00);
00235   SPIPutChar(0x00);
00236   SPIWait();
00237   Mp3DeselectData();
00238   
00239   //RED_LED = LED_OFF;
00240   Delay (500);           /* 500 ms delay */
00241   //GREEN_LED = LED_OFF;
00242 
00243   /* Stop the sine test sound */
00244   Mp3SelectData();
00245   SPIPutChar(0x45);
00246   SPIPutChar(0x78);
00247   SPIPutChar(0x69);
00248   SPIPutChar(0x74);
00249   SPIPutChar(0x00);
00250   SPIPutChar(0x00);
00251   SPIPutChar(0x00);
00252   SPIPutChar(0x00);
00253   SPIWait();
00254   Mp3DeselectData();
00255 
00256   Delay(500);            /* 500 ms delay */
00257 }  

Here is the call graph for this function:


Variable Documentation

unsigned char currentMicGain
 

Definition at line 43 of file vs10xx.c.

Referenced by Vs1103CancelWave(), and Vs1103SetMicGain().

bit vs1103_do_reset
 

VS1103 MODE bit.

Definition at line 36 of file vs10xx.c.

Referenced by Mp3Reset(), and Mp3SoftReset().

bit vs1103_earSpkHi
 

VS1103 MODE bit.

Definition at line 39 of file vs10xx.c.

Referenced by Mp3Reset().

bit vs1103_earSpkLo
 

VS1103 MODE bit.

Definition at line 40 of file vs10xx.c.

Referenced by Mp3Reset().

bit vs1103_mono_output
 

VS1103 MODE bit.

Definition at line 37 of file vs10xx.c.

Referenced by Mp3Reset().

bit vs1103_real_time_midi
 

VS1103 MODE bit.

Definition at line 41 of file vs10xx.c.

Referenced by main(), Mp3Reset(), SetMidiFromFile(), and SetMidiFromUART().

bit vs1103_record_mixer
 

VS1103 MODE bit.

Definition at line 34 of file vs10xx.c.

Referenced by EchoDisable(), EchoEnable(), main(), Mp3Reset(), and SelectRecordFile().

bit vs1103_recording_active
 

VS1103 MODE bit.

Definition at line 33 of file vs10xx.c.

Referenced by CancelRecord(), EchoEnable(), main(), Mp3Reset(), and SelectRecordFile().

bit vs1103_terminate
 

VS1103 MODE bit.

Definition at line 38 of file vs10xx.c.

Referenced by Mp3Reset(), and Vs1103CancelMidi().

bit vs1103_use_line_input
 

VS1103 MODE bit.

Definition at line 35 of file vs10xx.c.

Referenced by Mp3Reset().


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.