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

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

vs10xx.h File Reference

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

#include "board.h"

Include dependency graph for vs10xx.h:

Include dependency graph

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

Included by dependency graph

Go to the source code of this file.

Defines

#define VS_WRITE_COMMAND   0x02
 VS10xx SCI Write Command byte is 0x02.

#define VS_READ_COMMAND   0x03
 VS10xx SCI Read Command byte is 0x03.

#define SPI_MODE   0x0 /**< VS10xx register */
 VS10xx register.

#define SPI_STATUS   0x1 /**< VS10xx register */
 VS10xx register.

#define SPI_BASS   0x2 /**< VS10xx register */
 VS10xx register.

#define SPI_CLOCKF   0x3 /**< VS10xx register */
 VS10xx register.

#define SPI_DECODE_TIME   0x4 /**< VS10xx register */
 VS10xx register.

#define SPI_AUDATA   0x5 /**< VS10xx register */
 VS10xx register.

#define SPI_WRAM   0x6 /**< VS10xx register */
 VS10xx register.

#define SPI_WRAMADDR   0x7 /**< VS10xx register */
 VS10xx register.

#define SPI_HDAT0   0x8 /**< VS10xx register */
 VS10xx register.

#define SPI_HDAT1   0x9 /**< VS10xx register */
 VS10xx register.

#define SPI_AIADDR   0xa /**< VS10xx register */
 VS10xx register.

#define SPI_VOL   0xb /**< VS10xx register */
 VS10xx register.

#define SPI_AICTRL0   0xc /**< VS10xx register */
 VS10xx register.

#define SPI_AICTRL1   0xd /**< VS10xx register */
 VS10xx register.

#define SPI_AICTRL2   0xe /**< VS10xx register */
 VS10xx register.

#define SPI_AICTRL3   0xf /**< VS10xx register */
 VS10xx register.

#define SM_DIFF   0x01 /**< VS10xx register */
 VS10xx register.

#define SM_JUMP   0x02 /**< VS10xx register */
 VS10xx register.

#define SM_RESET   0x04 /**< VS10xx register */
 VS10xx register.

#define SM_OUTOFWAV   0x08 /**< VS10xx register */
 VS10xx register.

#define SM_PDOWN   0x10 /**< VS10xx register */
 VS10xx register.

#define SM_TESTS   0x20 /**< VS10xx register */
 VS10xx register.

#define SM_STREAM   0x40 /**< VS10xx register */
 VS10xx register.

#define SM_PLUSV   0x80 /**< VS10xx register */
 VS10xx register.

#define SM_DACT   0x100 /**< VS10xx register */
 VS10xx register.

#define SM_SDIORD   0x200 /**< VS10xx register */
 VS10xx register.

#define SM_SDISHARE   0x400 /**< VS10xx register */
 VS10xx register.

#define SM_SDINEW   0x800 /**< VS10xx register */
 VS10xx register.

#define SM_ADPCM   0x1000 /**< VS10xx register */
 VS10xx register.

#define SM_ADPCM_HP   0x2000 /**< VS10xx register */
 VS10xx register.

#define Mp3WriteRegister(addressbyte, highbyte, lowbyte)
 Write VS10xx register.

#define Mp3SetVolume(leftchannel, rightchannel)
 Set VS10xx Volume Register.


Functions

void VsSineTest ()
 Execute VS1011/VS1002 Sine Test Function.

void Mp3Reset ()
 Reset VS10xx.

void Mp3SoftReset ()
 Soft Reset of VS10xx (Between songs).

unsigned int Mp3ReadRegister (unsigned char addressbyte)
 Read the 16-bit value of a VS10xx register.

void SendZerosToVS10xx ()
 Send 2048 zeros.

unsigned char PlayDiskSectors (unsigned int nSectorsToPlay)
 Play disk sectors from disk.

void AvailableProcessorTime ()
 This is called when there is free processor time, implement externally.


Variables

xdata unsigned char playingState
 Playing State Global, 0=normal playing, 1=abort playing.


Detailed Description

Headers for interfacing with the mp3 player chip.

Interfacing the New Way, not handling BSYNC -> not compatible with VS1001.

Definition in file vs10xx.h.


Define Documentation

#define Mp3SetVolume leftchannel,
rightchannel   ) 
 

Value:

{\ Mp3WriteRegister(11,(leftchannel),(rightchannel));}
Set VS10xx Volume Register.

Definition at line 78 of file vs10xx.h.

Referenced by AvailableProcessorTime(), and Mp3Reset().

#define Mp3WriteRegister addressbyte,
highbyte,
lowbyte   ) 
 

Value:

{ \ Mp3SelectControl(); \ SPIPutCharWithoutWaiting(VS_WRITE_COMMAND); \ SPIPutChar((addressbyte)); \ SPIPutChar((highbyte)); \ SPIPutChar((lowbyte)); \ SPIWait(); \ Mp3DeselectControl();}
Write VS10xx register.

Definition at line 68 of file vs10xx.h.

Referenced by AvailableProcessorTime(), LoadPatch(), Mp3Reset(), Mp3SoftReset(), PlayCurrentFile(), PlayDiskSectors(), and Record().

#define SM_ADPCM   0x1000 /**< VS10xx register */
 

VS10xx register.

Definition at line 48 of file vs10xx.h.

#define SM_ADPCM_HP   0x2000 /**< VS10xx register */
 

VS10xx register.

Definition at line 49 of file vs10xx.h.

#define SM_DACT   0x100 /**< VS10xx register */
 

VS10xx register.

Definition at line 44 of file vs10xx.h.

#define SM_DIFF   0x01 /**< VS10xx register */
 

VS10xx register.

Definition at line 36 of file vs10xx.h.

#define SM_JUMP   0x02 /**< VS10xx register */
 

VS10xx register.

Definition at line 37 of file vs10xx.h.

#define SM_OUTOFWAV   0x08 /**< VS10xx register */
 

VS10xx register.

Definition at line 39 of file vs10xx.h.

Referenced by PlayCurrentFile().

#define SM_PDOWN   0x10 /**< VS10xx register */
 

VS10xx register.

Definition at line 40 of file vs10xx.h.

#define SM_PLUSV   0x80 /**< VS10xx register */
 

VS10xx register.

Definition at line 43 of file vs10xx.h.

#define SM_RESET   0x04 /**< VS10xx register */
 

VS10xx register.

Definition at line 38 of file vs10xx.h.

#define SM_SDINEW   0x800 /**< VS10xx register */
 

VS10xx register.

Definition at line 47 of file vs10xx.h.

#define SM_SDIORD   0x200 /**< VS10xx register */
 

VS10xx register.

Definition at line 45 of file vs10xx.h.

#define SM_SDISHARE   0x400 /**< VS10xx register */
 

VS10xx register.

Definition at line 46 of file vs10xx.h.

#define SM_STREAM   0x40 /**< VS10xx register */
 

VS10xx register.

Definition at line 42 of file vs10xx.h.

#define SM_TESTS   0x20 /**< VS10xx register */
 

VS10xx register.

Definition at line 41 of file vs10xx.h.

#define SPI_AIADDR   0xa /**< VS10xx register */
 

VS10xx register.

Definition at line 29 of file vs10xx.h.

#define SPI_AICTRL0   0xc /**< VS10xx register */
 

VS10xx register.

Definition at line 31 of file vs10xx.h.

Referenced by Record().

#define SPI_AICTRL1   0xd /**< VS10xx register */
 

VS10xx register.

Definition at line 32 of file vs10xx.h.

Referenced by AvailableProcessorTime(), and Record().

#define SPI_AICTRL2   0xe /**< VS10xx register */
 

VS10xx register.

Definition at line 33 of file vs10xx.h.

Referenced by PlayDiskSectors().

#define SPI_AICTRL3   0xf /**< VS10xx register */
 

VS10xx register.

Definition at line 34 of file vs10xx.h.

#define SPI_AUDATA   0x5 /**< VS10xx register */
 

VS10xx register.

Definition at line 24 of file vs10xx.h.

Referenced by Mp3Reset().

#define SPI_BASS   0x2 /**< VS10xx register */
 

VS10xx register.

Definition at line 21 of file vs10xx.h.

Referenced by AvailableProcessorTime().

#define SPI_CLOCKF   0x3 /**< VS10xx register */
 

VS10xx register.

Definition at line 22 of file vs10xx.h.

Referenced by Mp3Reset(), Mp3SoftReset(), and Record().

#define SPI_DECODE_TIME   0x4 /**< VS10xx register */
 

VS10xx register.

Definition at line 23 of file vs10xx.h.

Referenced by Record(), and ScreenSetPlayTime().

#define SPI_HDAT0   0x8 /**< VS10xx register */
 

VS10xx register.

Definition at line 27 of file vs10xx.h.

Referenced by Record().

#define SPI_HDAT1   0x9 /**< VS10xx register */
 

VS10xx register.

Definition at line 28 of file vs10xx.h.

Referenced by PlayDiskSectors(), and Record().

#define SPI_MODE   0x0 /**< VS10xx register */
 

VS10xx register.

Definition at line 19 of file vs10xx.h.

Referenced by Mp3SoftReset(), PlayCurrentFile(), and Record().

#define SPI_STATUS   0x1 /**< VS10xx register */
 

VS10xx register.

Definition at line 20 of file vs10xx.h.

#define SPI_VOL   0xb /**< VS10xx register */
 

VS10xx register.

Definition at line 30 of file vs10xx.h.

#define SPI_WRAM   0x6 /**< VS10xx register */
 

VS10xx register.

Definition at line 25 of file vs10xx.h.

#define SPI_WRAMADDR   0x7 /**< VS10xx register */
 

VS10xx register.

Definition at line 26 of file vs10xx.h.

#define VS_READ_COMMAND   0x03
 

VS10xx SCI Read Command byte is 0x03.

Definition at line 16 of file vs10xx.h.

Referenced by Mp3ReadRegister().

#define VS_WRITE_COMMAND   0x02
 

VS10xx SCI Write Command byte is 0x02.

Definition at line 13 of file vs10xx.h.


Function Documentation

void AvailableProcessorTime  ) 
 

This is called when there is free processor time, implement externally.

The basic task of this function is to implement the player user interface.

Local variables:

  • volume: Current volume setting

  • bass: Current bass enhancer setting

  • treble: Current treble enhancer setting

  • reclevel: Current recording level setting

  • uiReturnDelay: Counts down to returning to UI mode 0 (title screen)

Bass/Treble setting calculation

There are 2 or 4 adjustments possible:

  • Bass Frequency (1011B/E, 1002, 10x3) : 2..15 -> 20..1500 Hz
  • Bass boost (1011B/E, 1002, 10x3) : 0..15 -> 0ff..+15dB)
  • Treble Frequency (1011E, 10x3) : 0..15 -> 0..15kHz
  • Treble level (1011E, 10x3) : -8..+7 -> -12..+10.5dB

In this software, all are adjusted based from a single setting (0..128) for bass and another for treble. You may wish to allow user to control frequency and level separately or set fixed frequencies for a known speaker type. This algorithm increases the frequency range of adjustment with the increasing level.

Definition at line 327 of file player.c.

References displayStyle, displayTitle, displayValue, DS_NO_YES, DS_PERCENTAGE, DS_RAWTEXT, DS_TEXT, KEY_BUTTON, KEY_FARLEFT, KEY_FARRIGHT, lcdFont_barchars, lcdFont_vertical_barchars, LcdReset(), LcdSelectFont(), Mp3ReadRegister(), Mp3SetVolume, Mp3WriteRegister, playingState, PS_CUE, PS_END_OF_SONG, PS_NEXT_SONG, PS_NORMAL, PS_PREVIOUS_SONG, PS_RECORDING, PS_REWIND, ScreenSetPlayTime(), SPI_AICTRL1, SPI_BASS, SPIPutChar, SPIWait, UI_BASS, UI_CUE, UI_END_OF_MODES, UI_INFO, UI_RECLEVEL, UI_RETURN_DELAY, UI_SPEC, UI_STOP, UI_TITLE, UI_TREBLE, UI_VOLUME, uiMode, UpdateDisplay(), and userInterfaceDelayElapsed.

Referenced by GetAVIBlock(), PlayDiskSectors(), and Record().

00327 { 00328 00332 static xdata unsigned char volume = 20; 00333 00335 static xdata unsigned char bass = 0; 00336 00338 static xdata unsigned char treble = 64; //middle setting = 0 00339 00341 static xdata unsigned char reclevel = 50; 00342 00343 unsigned int i; //temp variable 00344 00345 static bit bassUpdateNeeded; 00346 00350 static unsigned char uiReturnDelay=0; 00351 00352 if (!userInterfaceDelayElapsed){ 00353 return; /* Not yet time to do user interface stuff */ 00354 } 00355 00356 userInterfaceDelayElapsed = 0; 00357 00358 00359 // User Interface Modes 00360 // Return to UI_TITLE after long period of button inactivity 00361 00362 if (uiReturnDelay == 0){ 00363 if ((uiMode != UI_SPEC)&&(uiMode != UI_CUE)) 00364 uiMode = UI_TITLE; 00365 else{ 00366 } 00367 }else{ 00368 uiReturnDelay--; 00369 } 00370 00371 #ifndef VS1003 00372 if (uiMode==UI_SPEC) //Only VS1003 has spectrum analyzer 00373 uiMode++; 00374 if (uiMode==UI_RECLEVEL) //Only record in VS1003 chips 00375 uiMode++; 00376 #endif 00377 00378 if (uiMode==UI_INFO) 00379 uiMode++; //Nothing interesting currently in screen UI_INFO. 00380 if (uiMode==UI_STOP) 00381 uiMode++; //Nothing interesting currently in screen UI_STOP. 00382 00383 /* Screen updates */ 00384 switch(uiMode){ 00385 00386 case UI_TITLE: //Playing time, song title 00387 00388 displayStyle = DS_TEXT; 00389 ScreenSetPlayTime(); 00390 00391 if (playingState==PS_RECORDING){ 00392 displayStyle = DS_PERCENTAGE; 00393 } 00394 00395 break; 00396 00397 case UI_STOP: //Ask if the user wants to stop 00398 displayStyle = DS_NO_YES; 00399 strcpy (displayTitle, "Stop? "); 00400 break; 00401 00402 case UI_CUE: //Ask if the user wants to fast forward or rewind 00403 displayStyle = DS_RAWTEXT; 00404 strcpy (displayTitle, "REW/CUE <- ->"); 00405 00406 //i = Mp3ReadRegister(SPI_HDAT1); 00407 //displayTitle[5] = lcd_hexchars[i>>12]; 00408 //displayTitle[6] = lcd_hexchars[(i>>8)&0x0f]; 00409 //displayTitle[7] = lcd_hexchars[(i>>4)&0x0f]; 00410 //displayTitle[8] = lcd_hexchars[i&0x0f]; 00411 00412 break; 00413 00414 case UI_VOLUME: //Show volume bar 00415 LcdSelectFont(lcdFont_barchars); 00416 displayStyle = DS_PERCENTAGE; 00417 strcpy(displayTitle,"Volume: "); 00418 displayValue = (100-(volume>>1)); 00419 if (displayValue<0) displayValue = 0; 00420 break; 00421 00422 case UI_BASS: //Show bass bar 00423 LcdSelectFont(lcdFont_barchars); 00424 displayStyle = DS_PERCENTAGE; 00425 strcpy(displayTitle,"Bass: "); 00426 displayValue = (bass/5)*4; 00427 if (displayValue<1) displayValue = 1; 00428 break; 00429 00430 case UI_TREBLE: //Show treble bar 00431 LcdSelectFont(lcdFont_barchars); 00432 displayStyle = DS_PERCENTAGE; 00433 strcpy(displayTitle,"Treble: "); 00434 displayValue = (treble/5)*4; 00435 if (displayValue<1) displayValue = 1; 00436 break; 00437 00438 case UI_RECLEVEL: //Show recording level 00439 00440 if (playingState==PS_RECORDING){ 00441 LcdSelectFont(lcdFont_barchars); 00442 displayStyle = DS_PERCENTAGE; 00443 strcpy(displayTitle,"RecLevel"); 00444 displayValue = (reclevel); 00445 if (reclevel==0){ 00446 strcpy(displayTitle,"RecLevel <Auto> "); 00447 displayStyle = DS_RAWTEXT; //Reveal the "auto" text 00448 } 00449 }else{ 00450 //Not in recording 00451 displayStyle = DS_NO_YES; 00452 strcpy (displayTitle, "Record? "); 00453 } 00454 break; 00455 00456 00457 case UI_SPEC: // Spectrum analyzer 00458 00459 if (playingState == PS_RECORDING){ 00460 uiMode++; //Don't show specana when recording 00461 } 00462 00463 LcdSelectFont(lcdFont_vertical_barchars); 00464 displayStyle = DS_RAWTEXT; 00465 ScreenSetPlayTime(); 00466 00467 // Request to read Spectrum Analyzer register 00468 Mp3WriteRegister(7, 0x18, 0x04); 00469 00470 // Read Spectrum Analyzer registers 00471 { 00472 for (i=0;i<8;i++) { //for each band i in [0..7] 00473 signed char thisband = Mp3ReadRegister(6); 00474 00475 /* thisband now has spectrum value 0..63. We adjust it a little 00476 for best image on the evakit LCD. You also get peak values 00477 etc from the chip but we don't use them in the evakit screen. 00478 we use 8 bands, but up to 23 are obtainable from the chip. */ 00479 00480 thisband &= 63; /* mask all but level info */ 00481 thisband >>= 1; /* LCD resolution is not high */ 00482 thisband -= 3; /* base offset */ 00483 if (i==0) thisband -= 2; /* decrease bass bar level */ 00484 if (i==6) thisband += 1; /* increase treble bar level */ 00485 if (i==7) thisband += 1; /* increase treble bar level */ 00486 if (thisband>7) thisband = 7; /* high limit */ 00487 if (thisband<0) thisband =' '; /* low limit */ 00488 00489 displayTitle[i+8] = thisband; //Store to display mem 00490 00491 }//for each band 00492 } 00493 break; 00494 00495 } //switch(uiMode) 00496 00497 // Buttons handler 00498 // Perform mode-dependent button handling 00499 00500 if ((KEY_BUTTON) && (uiReturnDelay < UI_RETURN_DELAY-20)){ 00501 LcdReset(); 00502 uiMode++; 00503 uiReturnDelay = UI_RETURN_DELAY; 00504 } 00505 00506 switch(uiMode){ 00507 00508 case UI_TITLE: 00509 case UI_SPEC: 00510 00511 if (KEY_FARRIGHT){ 00512 playingState = PS_NEXT_SONG; /* Request */ 00513 } 00514 if (KEY_FARLEFT){ 00515 playingState = PS_PREVIOUS_SONG; /* Request */ 00516 } 00517 break; 00518 00519 00520 case UI_VOLUME: 00521 00522 if (KEY_FARLEFT){ 00523 uiReturnDelay = UI_RETURN_DELAY; 00524 if (volume++ == 254) volume = 254; //Change + limit to 254 (minimum vol) 00525 Mp3SetVolume(volume,volume); 00526 } 00527 00528 if (KEY_FARRIGHT){ 00529 uiReturnDelay = UI_RETURN_DELAY; 00530 if (volume-- == 0) volume = 0; //Change + limit to 0 (maximum volume) 00531 Mp3SetVolume(volume,volume); 00532 } 00533 break; // UI_VOLUME 00534 00535 case UI_BASS: 00536 case UI_TREBLE: //BASS and TREBLE use the same VS10xx register 00537 bassUpdateNeeded = 0; 00538 00539 //First let's see if a key is pressed; does the user want to set level? 00540 00541 if (uiMode==UI_BASS){ //BASS screen is active 00542 00543 if (KEY_FARLEFT){ 00544 bassUpdateNeeded = 1; 00545 if (bass-- == 0) bass = 0; //Change + limit to 0 (OFF setting) 00546 } 00547 if (KEY_FARRIGHT){ 00548 bassUpdateNeeded = 1; 00549 if (bass++ == 127) bass = 127; //Change + limit to 127 (max setting) 00550 } 00551 00552 }else{ //TREBLE screen is active 00553 00554 if (KEY_FARLEFT){ 00555 bassUpdateNeeded = 1; //SCI_BASS is for both bass and treble 00556 if (treble-- == 0) treble = 0; //Change + limit to 0 (OFF setting) 00557 } 00558 if (KEY_FARRIGHT){ 00559 bassUpdateNeeded = 1; //SCI_BASS is for both bass and treble 00560 if (treble++ == 127) treble = 127; //Change + limit to 127 (max) 00561 } 00562 00563 } 00564 00565 00566 if (bassUpdateNeeded){ 00567 unsigned int newBassRegister; 00568 00569 //User has pushed button to alter bass/treble register 00570 //calculate new value 00571 00587 //Let's start from bass frequency setting. 00588 //min(0) should give 2 (20Hz), max(127) should give 15 (150Hz) 00589 newBassRegister = (bass + 23) / 10; //into bits 3..0, clear hibits 00590 00591 //Bass boost level. 00592 //min(0) should give 0, max(127) should give 15 00593 newBassRegister |= (bass>>3)<<4; //insert to bits 7..4 00594 00595 //Then the treble frequency 00596 //min(0) should give 15(15kHx), max(127) should give 2(2kHz) 00597 newBassRegister |= (((148-treble)>>3)+2)<<8; //insert into bits 11..8 00598 00599 //Finally the treble value (-8..7) 00600 //min(0) should give -8, max(127) should give 7; 00601 newBassRegister |= ((treble>>3)-8)<<12; //insert into bits 15..12 00602 00603 00604 uiReturnDelay = UI_RETURN_DELAY; 00605 00606 if (Mp3ReadRegister(SPI_BASS)!=newBassRegister){ 00607 Mp3WriteRegister(SPI_BASS,newBassRegister>>8,newBassRegister&0xff); 00608 } 00609 00610 //i = newBassRegister; 00611 //displayTitle[4] = lcd_hexchars[i>>12]; 00612 //displayTitle[5] = lcd_hexchars[(i>>8)&0x0f]; 00613 //displayTitle[6] = lcd_hexchars[(i>>4)&0x0f]; 00614 //displayTitle[7] = lcd_hexchars[i&0x0f]; 00615 00616 00617 } 00618 00619 break; // UI_BASS and UI_TREBLE 00620 00621 00622 case UI_RECLEVEL: 00623 00624 if (playingState==PS_RECORDING){ 00625 if (KEY_FARRIGHT){ 00626 uiReturnDelay = UI_RETURN_DELAY; 00627 if (reclevel++ == 100){ 00628 reclevel = 100; 00629 } 00630 Mp3WriteRegister(SPI_AICTRL1, 00631 ((int)reclevel*32)>>8,((int)reclevel*32)&0xff); 00632 SPIPutChar(0);SPIWait(); 00633 } 00634 00635 if (KEY_FARLEFT){ 00636 uiReturnDelay = UI_RETURN_DELAY; 00637 if (reclevel-- == 0){ 00638 reclevel = 0; 00639 } 00640 Mp3WriteRegister(SPI_AICTRL1, 00641 ((int)reclevel*32)>>8,((int)reclevel*32)&0xff); 00642 SPIPutChar(0);SPIWait(); 00643 } 00644 }else{ 00645 //Not in recording 00646 if (KEY_FARRIGHT){ 00647 //Enter recording mode 00648 playingState=PS_RECORDING; //request to record 00649 } 00650 } 00651 break; // UI_RECLEVEL 00652 00653 case UI_STOP: 00654 00655 if (KEY_FARRIGHT){ 00656 playingState = PS_END_OF_SONG; /* Request to abort playing */ 00657 } 00658 break; // UI_STOP 00659 00660 case UI_CUE: 00661 00662 if (playingState == PS_NORMAL){ /* Only control when PS_NORMAL */ 00663 if (KEY_FARRIGHT){ 00664 uiReturnDelay = UI_RETURN_DELAY; /* Don't go back to title just yet */ 00665 playingState = PS_CUE; /* Request */ 00666 } 00667 if (KEY_FARLEFT){ 00668 uiReturnDelay = UI_RETURN_DELAY; 00669 playingState = PS_REWIND; /* Request */ 00670 } 00671 } 00672 00673 break; // UI_SKIP 00674 00675 case UI_END_OF_MODES: 00676 uiMode = UI_TITLE; 00677 break; // UI_END_OF_MODES 00678 00679 00680 } //End Switch 00681 00682 00683 // Draw screen 00684 UpdateDisplay(); 00685 }

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, SPI_RESULT_BYTE, SPIPutChar, SPIPutCharWithoutWaiting, SPIWait, and VS_READ_COMMAND.

Referenced by AvailableProcessorTime(), PlayDiskSectors(), Record(), and ScreenSetPlayTime().

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 69 of file vs10xx.c.

References Delay(), MP3_DREQ, Mp3DeselectControl, Mp3DeselectData, Mp3PutInReset, Mp3ReleaseFromReset, Mp3SetVolume, Mp3SoftReset(), Mp3WriteRegister, SPI_AUDATA, SPI_CLOCKF, SPIPutCharWithoutWaiting, and SPISetFastClock.

Referenced by main(), and Record().

00069 { 00070 00071 Mp3PutInReset(); 00072 Delay(1); 00073 00074 /* Send dummy SPI byte to initialize SPI */ 00075 SPIPutCharWithoutWaiting(0xFF); 00076 00077 /* Un-reset MP3 chip */ 00078 Mp3DeselectControl(); 00079 Mp3DeselectData(); 00080 Mp3ReleaseFromReset(); 00081 Mp3SetVolume(0xff,0xff); 00082 00083 /* Set clock register, doubler etc. */ 00084 #ifdef VS1003 00085 Mp3WriteRegister(SPI_CLOCKF, 0xa6, 0x6c); 00086 #else 00087 Mp3WriteRegister(SPI_CLOCKF, 156, 204); 00088 #endif 00089 00090 /* Wait for DREQ */ 00091 while (!MP3_DREQ) 00092 ; 00093 00094 /* Slow sample rate for slow analog part startup */ 00095 Mp3WriteRegister(SPI_AUDATA, 0, 10); /* 10 Hz */ 00096 Delay(100); 00097 00098 /* Switch on the analog parts */ 00099 Mp3SetVolume(0xfe,0xfe); 00100 Mp3WriteRegister (SPI_AUDATA, 31, 64); /* 8kHz */ 00101 Mp3SetVolume(20,20); 00102 Mp3SoftReset(); 00103 SPISetFastClock(); 00104 00105 00106 ConsoleWrite ("Init: VS10XX\r"); 00107 00108 }

Here is the call graph for this function:

void Mp3SoftReset  ) 
 

Soft Reset of VS10xx (Between songs).

Definition at line 35 of file vs10xx.c.

References Delay(), MP3_DREQ, Mp3DeselectData, Mp3SelectData, Mp3WriteRegister, SPI_CLOCKF, SPI_MODE, SPIPutChar, SPIPutCharWithoutWaiting, and SPIWait.

Referenced by main(), and Mp3Reset().

00035 { 00036 00037 /* Soft Reset of VS10xx */ 00038 Mp3WriteRegister (SPI_MODE, 0x08, 0x04); /* Newmode, Reset, No L1-2 */ 00039 00040 Delay(1); /* One millisecond delay */ 00041 while (!MP3_DREQ) /* wait for startup */ 00042 ; 00043 00044 /* Set clock register, doubler etc. */ 00045 #ifdef VS1003 00046 Mp3WriteRegister(SPI_CLOCKF, 0xa6, 0x96); 00047 #else 00048 Mp3WriteRegister(SPI_CLOCKF, 156, 204); 00049 #endif 00050 00051 Delay(1); /* One millisecond delay */ 00052 00053 00054 /* Send null bytes to data interface */ 00055 Mp3SelectData(); 00056 SPIPutCharWithoutWaiting(0); 00057 SPIPutChar(0); 00058 SPIPutChar(0); 00059 SPIPutChar(0); 00060 SPIWait(); 00061 Mp3DeselectData(); 00062 00063 }

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.

How many sectors to send between ff/rew commands

Definition at line 202 of file vs10xx.c.

References AvailableProcessorTime(), DiskBlock::Raw::buf, dataBufPtr, diskSect, GREEN_LED, Address::l, LED_OFF, LED_ON, MP3_DREQ, Mp3DeselectData, Mp3ReadRegister(), Mp3SelectData, Mp3WriteRegister, PlayAvi(), playingState, PrepareToReadDiskSector(), PS_CUE, PS_CUE_ACTION, PS_CUE_WAIT1003, PS_END_OF_SONG, PS_FALLBACK_1, PS_FALLBACK_N, PS_NEXT_SONG, PS_NORMAL, PS_PREVIOUS_SONG, PS_RECORDING, PS_REW_WAIT1003, PS_REWIND, DiskBlock::raw, ReadDiskSector(), sectorAddress, SendZerosToVS10xx(), SPI_AICTRL2, SPI_HDAT1, SPIPutChar, SPIPutCharWithoutWaiting, and SPIWait.

Referenced by PlayCurrentFile().

00202 { 00203 00205 unsigned char fallbackCount = 0; 00206 00207 00208 #ifdef AVIPLAY 00209 if (!PlayAvi()) return 0; //try to play AVI file soundtrack starting from 00210 //current sector, if avifile is played, return. 00211 #endif 00212 00213 00214 PrepareToReadDiskSector(sectorAddress.l); 00215 while (nSectorsToPlay--){ 00216 00217 AvailableProcessorTime(); 00218 00219 ReadDiskSector(sectorAddress.l); 00220 00221 /* If playing state is something else than "play normally", 00222 exit returning the request number. */ 00223 if ((playingState==PS_END_OF_SONG)|| 00224 (playingState==PS_NEXT_SONG)|| 00225 (playingState==PS_RECORDING)|| 00226 (playingState==PS_PREVIOUS_SONG)){ 00227 return playingState; 00228 } 00229 00230 00231 /* === REWIND / FAST FORWARD FUNCTIONALITY CODE BEGINS === */ 00232 /* If you don't implement rewind / fast forward, leave these lines out */ 00233 00234 if (playingState==PS_FALLBACK_N){ 00235 if ((--fallbackCount)==0){ 00236 playingState=PS_NORMAL; 00237 } 00238 } 00239 00240 if (playingState==PS_FALLBACK_1){ 00241 /* Now we should have brand new sector in memory ready for sending to 00242 VS1003, so let's send zeroes between old and new data. */ 00243 ConsoleWrite("(Zeros)"); 00244 SendZerosToVS10xx(); 00245 ConsoleWrite("->Fallback to normal"); 00246 fallbackCount = 24; 00247 playingState = PS_FALLBACK_N; 00248 } 00249 00250 00251 if (playingState==PS_CUE){ //Request to start fast forward 00252 if (Mp3ReadRegister(SPI_HDAT1)==((int)'W'<< 8)+'m'){ 00253 ConsoleWrite("\rWmCUE->Wait"); 00254 Mp3WriteRegister(SPI_AICTRL2, 0x12, 0x34); 00255 playingState = PS_CUE_WAIT1003; 00256 }else{ 00257 playingState = PS_CUE_ACTION; 00258 } 00259 } 00260 00261 if (playingState==PS_CUE_WAIT1003){ //Wait for permission to break data flow 00262 if (Mp3ReadRegister(SPI_AICTRL2)==0x2345){ //permission granted 00263 ConsoleWrite("->Action"); 00264 playingState = PS_CUE_ACTION; 00265 } 00266 } 00267 00268 if (playingState==PS_CUE_ACTION){ 00269 if (nSectorsToPlay>128){ 00270 sectorAddress.l += 128; //Skip sectors 00271 nSectorsToPlay -= 128; 00272 //adjust vs1003 song left 00273 ConsoleWrite("->Fallback(5)"); 00274 playingState = PS_FALLBACK_1; //Sector already in memory still goes. 00275 } 00276 } 00277 00278 if (playingState==PS_REWIND){ //Request to start fast forward 00279 Mp3WriteRegister(SPI_AICTRL2, 0x12, 0x34); 00280 playingState = PS_REW_WAIT1003; 00281 } 00282 00283 if (playingState==PS_REW_WAIT1003){ //Wait for permission to break data flow 00284 if (1){ 00285 if (1 || (Mp3ReadRegister(SPI_AICTRL2)==0x2345)){ //permission granted 00286 sectorAddress.l -= 128; 00287 nSectorsToPlay += 128; 00288 playingState = PS_FALLBACK_1; //Sector already in memory still goes. 00289 } 00290 } 00291 } 00292 00293 00294 /* === END OF REWIND / FAST FORWARD FUNCTIONALITY CODE === */ 00295 00296 00297 00298 sectorAddress.l++; 00299 if (nSectorsToPlay){ 00300 /*Do not seek after the last sector*/ 00301 PrepareToReadDiskSector(sectorAddress.l); 00302 } 00303 00304 Mp3SelectData(); 00305 00306 dataBufPtr = diskSect.raw.buf; 00307 while (dataBufPtr < diskSect.raw.buf+512){ 00308 00309 if (!MP3_DREQ){ 00310 GREEN_LED = LED_ON; 00311 while (!MP3_DREQ){ 00312 Mp3DeselectData(); 00313 AvailableProcessorTime(); 00314 Mp3SelectData(); 00315 } 00316 } 00317 GREEN_LED = LED_OFF; 00318 00319 /* Send 32 octets of disk block data to VS10xx */ 00320 SPIPutCharWithoutWaiting(*dataBufPtr++); 00321 SPIWait(); 00322 SPIPutChar(*dataBufPtr++); 00323 SPIPutChar(*dataBufPtr++); 00324 SPIPutChar(*dataBufPtr++); 00325 SPIPutChar(*dataBufPtr++); 00326 SPIPutChar(*dataBufPtr++); 00327 SPIPutChar(*dataBufPtr++); 00328 SPIPutChar(*dataBufPtr++); 00329 SPIPutChar(*dataBufPtr++); 00330 SPIPutChar(*dataBufPtr++); 00331 SPIPutChar(*dataBufPtr++); 00332 SPIPutChar(*dataBufPtr++); 00333 SPIPutChar(*dataBufPtr++); 00334 SPIPutChar(*dataBufPtr++); 00335 SPIPutChar(*dataBufPtr++); 00336 SPIPutChar(*dataBufPtr++); 00337 SPIPutChar(*dataBufPtr++); 00338 SPIPutChar(*dataBufPtr++); 00339 SPIPutChar(*dataBufPtr++); 00340 SPIPutChar(*dataBufPtr++); 00341 SPIPutChar(*dataBufPtr++); 00342 SPIPutChar(*dataBufPtr++); 00343 SPIPutChar(*dataBufPtr++); 00344 SPIPutChar(*dataBufPtr++); 00345 SPIPutChar(*dataBufPtr++); 00346 SPIPutChar(*dataBufPtr++); 00347 SPIPutChar(*dataBufPtr++); 00348 SPIPutChar(*dataBufPtr++); 00349 SPIPutChar(*dataBufPtr++); 00350 SPIPutChar(*dataBufPtr++); 00351 SPIPutChar(*dataBufPtr++); 00352 SPIPutChar(*dataBufPtr++); 00353 SPIWait(); 00354 } 00355 00356 00357 SPIWait(); 00358 Mp3DeselectData(); 00359 } 00360 00361 00362 return 0; //OK Exit 00363 }

Here is the call graph for this function:

void SendZerosToVS10xx  ) 
 

Send 2048 zeros.

Todo:
Timeouts for all DREQ busy loop waits!

Definition at line 178 of file vs10xx.c.

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

Referenced by PlayCurrentFile(), and PlayDiskSectors().

00178 { 00179 Mp3SelectData(); 00180 SPIPutCharWithoutWaiting(0); 00181 for (temp.i=0; temp.i<1048; temp.i++){ /* TESTING 1048 TESTING */ 00182 while (!MP3_DREQ) 00183 ; 00184 SPIPutChar(0); 00185 } 00186 SPIWait(); 00187 Mp3DeselectData(); 00188 }

void VsSineTest  ) 
 

Execute VS1011/VS1002 Sine Test Function.

Definition at line 112 of file vs10xx.c.

References Delay(), GREEN_LED, LED_OFF, LED_ON, MP3_DREQ, Mp3DeselectControl, Mp3DeselectData, Mp3PutInReset, Mp3ReleaseFromReset, Mp3SelectControl, Mp3SelectData, RED_LED, SPIPutChar, SPIPutCharWithoutWaiting, and SPIWait.

00112 { 00113 00114 /* Reset MP3 chip */ 00115 Mp3PutInReset(); /* Pull xRESET low -> hardware reset */ 00116 Delay(100); /* 100 ms delay */ 00117 00118 /* Send dummy SPI byte to initialize SPI of Atmel microcontroller */ 00119 SPIPutCharWithoutWaiting(0xFF); 00120 00121 /* Un-reset MP3 chip */ 00122 Mp3DeselectControl(); /* Pull xCS high */ 00123 Mp3DeselectData(); /* Pull xDCS high */ 00124 Mp3ReleaseFromReset(); /* Pull xRESET high */ 00125 Delay(100); /* 100 ms delay */ 00126 00127 GREEN_LED = LED_ON; 00128 RED_LED = LED_ON; 00129 00130 /* VS10xx Application Notes, chapter 4.8 ---------------------------------*/ 00131 /* As an example, let's write value 0x0820 to register 00 byte by byte */ 00132 Mp3SelectControl(); /* Now SPI writes go to SCI port */ 00133 SPIPutChar(0x02); /* Send SPI Byte, then wait for byte to be sent. */ 00134 SPIPutChar(0x00); /* 0x02 was WRITE command, 0x00 is register number */ 00135 SPIPutChar(0x08); /* This byte goes to MSB */ 00136 SPIPutChar(0x20); /* ..and this is LSB. (0x20=Allow Test Mode) */ 00137 SPIWait(); /* Wait until Atmel MCU signals SPI write complete */ 00138 Mp3DeselectControl(); /* Now SPI writes don't go to SCI port */ 00139 00140 while (!MP3_DREQ) /* Wait for DREQ = 1 */ 00141 ; /* Do nothing while waiting for DREQ = 1 */ 00142 00143 /* Send a Sine Test Header to Data port */ 00144 Mp3SelectData(); /* Now SPI writes go to SDI port */ 00145 00146 SPIPutChar(0x53); /* - This is a special VLSI Solution test header - */ 00147 SPIPutChar(0xef); /* - that starts a sine sound. It's good for - */ 00148 SPIPutChar(0x6e); /* - testing your code, the chip and also for - */ 00149 SPIPutChar(0x44); /* - seeing if your MP3 decoder was manufactured - */ 00150 SPIPutChar(0x00); /* - by VLSI Solution oy. ------------------------ */ 00151 SPIPutChar(0x00); 00152 SPIPutChar(0x00); 00153 SPIPutChar(0x00); 00154 SPIWait(); 00155 Mp3DeselectData(); 00156 00157 RED_LED = LED_OFF; 00158 Delay (500); /* 500 ms delay */ 00159 GREEN_LED = LED_OFF; 00160 00161 /* Stop the sine test sound */ 00162 Mp3SelectData(); 00163 SPIPutChar(0x45); 00164 SPIPutChar(0x78); 00165 SPIPutChar(0x69); 00166 SPIPutChar(0x74); 00167 SPIPutChar(0x00); 00168 SPIPutChar(0x00); 00169 SPIPutChar(0x00); 00170 SPIPutChar(0x00); 00171 SPIWait(); 00172 Mp3DeselectData(); 00173 00174 Delay(500); /* 500 ms delay */ 00175 }

Here is the call graph for this function:


Variable Documentation

xdata unsigned char playingState
 

Playing State Global, 0=normal playing, 1=abort playing.

Definition at line 53 of file vs10xx.h.

Referenced by AvailableProcessorTime(), main(), PlayCurrentFile(), PlayDiskSectors(), Record(), and ScreenSetPlayTime().


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