VS1000 Developer Board problem whith example code

Writing software that controls the system and peripherals such as displays, SD cards, Buttons, LEDs, Serial Ports etc.
Post Reply
ilamar
User
Posts: 4
Joined: Tue 2015-11-10 14:16

VS1000 Developer Board problem whith example code

Post by ilamar » Tue 2015-11-10 16:40

Hi
I tried to run the example code to my developer Board (vs10000)

Code: Select all

// Filename.c : An example of finding a file based on the file name.

/* This example installs own keyboard handler MyIdleHook, which sets
   player.currentfile to be the number of key pressed (e.g. first
   key sets player.currentfile to 1, 2nd key to 2 etc.).

   The main loop plays a file from the filesystem based on that
   keypress: key 1 plays SWEEP.OGG, keys 2 and 3 play COMPIL~2.OGG,
   key 4 plays 50SIN1K.OGG and other keys play the 3rd .OGG file
   on the filesystem.
*/


#include <stdlib.h>
#include <stdio.h>
#include <vs1000.h>
#include <minifat.h>
#include <player.h>
#include <codec.h>
#include <audio.h>
#include <usb.h>
#include <vsNand.h>
#include <mappertiny.h>
#include <string.h>



//-------- debug output routine ---------
#define CONSOLE_DEBUG 1
#if CONSOLE_DEBUG
__y const char hex[] = "0123456789abcdef";
// Note: VS1000A can't have inited y-vars in NAND boot
void puthex(u_int16 a) {
  char tmp[8];
  tmp[0] = hex[(a>>12)&15];
  tmp[1] = hex[(a>>8)&15];
  tmp[2] = hex[(a>>4)&15];
  tmp[3] = hex[(a>>0)&15];
  tmp[4] = ' ';
  tmp[5] = '\0';
  fputs(tmp, stdout);
}
#endif
//---------------------------------------


// Expose some interfaces in ROM, do not alter!
extern struct FsNandPhys fsNandPhys;
extern struct FsPhysical *ph;
extern struct FsMapper *map;
extern struct CodecServices cs;



// ----- NEW KEYBOARD HANDLER -----
u_int16 oldPins;
// This gets called whenever there is some free CPU time
void MyIdleHook(void){
  u_int16 pins = ReadGPIO() & 0x1f; //Read GPIO0 bits 0..4  
  if (pins && (pins != oldPins)) { //a new key is pressed
    int i;
    for (i=0; i<5; i++){ // For GPIO0[0 to 4]...
      if (pins & (1 << i)){ // if pin connected to GPIO0[i] is pressed...
	player.currentFile = (i + 1); // a change of file is requested
	cs.cancel = 1; // request player to cancel current song
      }
    }
  }
  oldPins = pins;
}
// ---------------------------------





// Function: OpenNamedFile (packed string name, integer extension_tag);
/// Opens a file based on its 8.3 (MS-DOS) name and extension.
/// To conserve instruction RAM on chip, the parameters need to
/// be given as separate packed 8-character name and an extension tag.
/// Example: if you want to open file "SWEEP.OGG":
/// instead of calling OpenNamedFile("SWEEP.OGG"); //wrong!! ...
/// you must call OpenNamedFile("\pSWEEP   ",FAT_MKID('O','G','G'));
/// Remember to fill the file name with spaces up to 8 characters.
u_int16 OpenNamedFile(const u_int32 *fileName, u_int32 extension){
  u_int32 allowedExtensions[] = {0,0};
  register u_int16 i;
  allowedExtensions[0] = extension;
  minifatInfo.supportedSuffixes = allowedExtensions;
  for (i=0; OpenFile(i)<0; i++){
    if ((((__y u_int32 *)minifatInfo.fileName)[0] == fileName[0]) 
	&& (((__y u_int32 *)minifatInfo.fileName)[1] == fileName[1])){
      return 1; // File Found
    }
  }
  return 0; //File Not Found
}

// This version opens an .ogg file based on the packed 8-character
// filename. Example: OpenNamedOggFile("\pSWEEP   "); // Opens SWEEP.OGG file
u_int16 OpenNamedOggFile(const u_int32 *fileName){
  register u_int16 i;
  minifatInfo.supportedSuffixes=&defSupportedFiles[1]; //only .ogg
  for (i=0; OpenFile(i)<0; i++){
    if ((((__y u_int32 *)minifatInfo.fileName)[0] == fileName[0]) 
	&& (((__y u_int32 *)minifatInfo.fileName)[1] == fileName[1])){
	 puts("File found");
      return 1; // File Found
    }
  }
  return 0; //File Not Found
}







void main(void){
  //ph = &fsNandPhys.p; // physical disk is nand flash ROM handler

  //ph.FsPhNandReinitialize(ph);
  map = FsMapTnCreate(ph, 0); // logical disk mapper is ROM tiny mapper (read only)
  player.currentFile = 0;
    
  if (InitFileSystem()) {

    // File System Not Found, play low sine wave as an "error message"
    register u_int16 *g = (u_int16*) g_yprev0; // get ptr to sintest params
    *g++ = 4; *g++ = 44100; *g++ = 0x5050; *g++ = 120; *g++ = 200;
    //puts("NO FAT");
    SinTest(); //Exit to SinTest: Play weird tone at low volume
    
  } else {


    // Filesystem OK, play

    minifatInfo.supportedSuffixes = supportedFiles; // play '.ogg' files
    player.totalFiles = OpenFile(0xffffU);

    SetHookFunction((u_int16)IdleHook, MyIdleHook);

    while (1) { // player loop

      if (player.currentFile){
	u_int16 codecResult;
	
	if (player.currentFile == 1){
	  OpenNamedFile("\pSWEEP   ",FAT_MKID('O','G','G'));
	}else if (player.currentFile == 2){
	  OpenNamedFile("\pCOMPIL~2",FAT_MKID('O','G','G'));
	}else if (player.currentFile == 3){
	  OpenNamedFile("\pCOMPIL~2",FAT_MKID('O','G','G'));
	}else if (player.currentFile == 4){
	  OpenNamedFile("\p50SIN1K ",FAT_MKID('O','G','G'));
	}else OpenFile(3);


	{
	  int i;
	  char tmp[8];
	  for (i=0; i<6; i++){
	    tmp[0] = minifatInfo.fileName[i] >> 8;
	    tmp[1] = minifatInfo.fileName[i] & 0xff;
	    tmp[2] = '\0';
	    fputs(tmp, stdout);	    
	  }
	  puts("=fileName");
	}
	
	cs.cancel = 0; 
	 puts("flag1");
	codecResult = PlayCurrentFile();
	puts("flag2");
	if (codecResult != ceCancelled){ //The file played until the end..
	  player.currentFile = 0; //.. so don't play anything
	}       	
      } else {
	MyIdleHook(); // Nothing is playing, call the idle hook.
      }

    } //end of player loop
  } 
}

When i run the program with VSIDE software I get this output:

Code: Select all

SWEEP   OGG =fileName
flag1
but no audio plays and I never get the output "flag2".

where is the problem?

User avatar
pasi
VLSI Staff
Posts: 1416
Joined: Thu 2010-07-15 16:04

Re: VS1000 Developer Board problem whith example code

Post by pasi » Wed 2015-11-18 17:41

What value does OpenNamedFile() return?
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook

ilamar
User
Posts: 4
Joined: Tue 2015-11-10 14:16

Re: VS1000 Developer Board problem whith example code

Post by ilamar » Mon 2015-11-23 12:02

Thanks, now work!!

Post Reply