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 332 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().

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

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, 0x96); //oli 0xa66c 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