⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diskappl.c

📁 用msp430设计的MP3方案,解码芯片用VS1001K
💻 C
📖 第 1 页 / 共 3 页
字号:
  for(i=0;i<FATsectors;i++)
    {
    SM_page_read(SM_page_data,temp++);
    Flash_seg_write (SM_page_data,fptr);
    fptr+=512;
    }
  }


if(SM_info[1]==0x73)	/* 16MB */
	{
	temp=SM_log_to_phyADD1[1]<<5;	/* physical address of logical block 1 */
	temp+=10;	/* physical sector coresponding to logical sector 42 */
  FATsectors=3;//42,43,44
  fptr=(unsigned char *)SM_FAT_data;
  for(i=0;i<FATsectors;i++)
    {
    SM_page_read(SM_page_data,temp++);
    Flash_seg_write (SM_page_data,fptr);
    fptr+=512;
    }
  }


if(SM_info[1]==0x75)	/* 32MB */
	{
	temp=SM_log_to_phyADD1[1]<<5;	/* physical address of logical block 1 */
	temp+=4;	/* physical sector coresponding to logical sector 36 */
  FATsectors=6;//36,37,38,39,40,41
  fptr=(unsigned char *)SM_FAT_data;
  for(i=0;i<FATsectors;i++)
    {
    SM_page_read(SM_page_data,temp++);
    Flash_seg_write (SM_page_data,fptr);
    fptr+=512;
    }
  }

if(SM_info[1]==0x76)	/* 64MB */
	{
	temp=SM_log_to_phyADD1[1]<<5;	/* physical address of logical block 1 */
	temp+=24;	/* physical sector coresponding to logical sector 56 */
  FATsectors=12;//56,57,58,59,60,61,62,63,64,65,66,67
  fptr=(unsigned char *)SM_FAT_data;
  for(i=0;i<8;i++)//56,57,58,59,60,61,62,63
    {
    SM_page_read(SM_page_data,temp++);
    Flash_seg_write (SM_page_data,fptr);
    fptr+=512;
    }
	temp=SM_log_to_phyADD1[2]<<5;	/* physical address of logical block 2 */
  for(i=0;i<4;i++)//64,65,66,67
    {
    SM_page_read(SM_page_data,temp++);
    Flash_seg_write (SM_page_data,fptr);
    fptr+=512;
    }
  }


//hexout_uart0_int(fptr);
//putstring_uart0("press...");
//putchar_uart0(0x0d);
//putchar_uart0(0x0a);
//while (ischar_uart0()==0){}
//getchar_uart0();



//SM_page_read(SM_page_data,temp++);
//Flash_seg_write (SM_page_data,SM_FAT_data);
//SM_page_read(SM_page_data,temp++);
//Flash_seg_write (SM_page_data,SM_FAT_data+512);
//SM_page_read(SM_page_data,temp++);
//Flash_seg_write (SM_page_data,SM_FAT_data+1024);
if((SM_FAT_data[0]==0xf8)&&(SM_FAT_data[1]==0xff)) return SM_OK;
return SM_FAT_NOTFOUND;
}
/* End of SM_read_FAT *************************************/
/***********************************************************
Function:       SM_find_next_inFAT
Purpose: 				to find next cluster(block) in cluster chain
								as per FAT	
Author:  				Jan Szymanski
Original Date:  06-08-2001
Date last Mod:
Comments:											
***********************************************************/
unsigned int SM_find_next_inFAT(unsigned int cluster)
{
unsigned int temp,temp1,temp2;

//cluster++;
//return(cluster);

/* tricky algorithm here inherited from old DOS gurus */
/* these guys loved complex programming for whatever reason */
/* if n is even (0,2,...) (n/2)x3 */
/* if n is odd (1,3,...) ((n/2)x3)+2 */
temp=cluster;
if((temp&0x0001)==0x0001)	/* 1,3,... */
	{  
	temp>>=1;			/* temp/2 */
	temp1=temp;
	temp+=temp1;
	temp+=temp1;	/* (temp/2)x3 */ 
	temp+=2;			/* ((temp/2)x3)+2 */
	temp2=(unsigned char)SM_FAT_data[temp];
	temp2<<=8;
	temp2+=(unsigned char)SM_FAT_data[temp-1];
	temp2>>=4; 
//	putstring_PC((unsigned char *)"\r\nOdd...");
//	hexout_PC_int(temp2); 
//	putstring_PC((unsigned char *)"\r\n");
	return temp2;
	}
	else	/* 0,2,... */
		{
		temp>>=1;			/* temp/2 */
		temp1=temp;
		temp+=temp1;
		temp+=temp1;	/* (temp/2)x3 */ 
		temp2=(unsigned char)SM_FAT_data[temp+1];
		temp2<<=8;
		temp2+=(unsigned char)SM_FAT_data[temp];
		temp2&=0x0fff;
//		putstring_PC((unsigned char *)"\r\nEven...");
//		hexout_PC_int(temp2);
//		putstring_PC((unsigned char *)"\r\n");
		return temp2;
		}
}

/* End of SM_find_next_inFAT ******************************/

/***********************************************************
Function:       SM_play_file
Purpose: 				to read file from SmartMedia
								with name extension fileextension and output 
                to STA013	
Author:  				Jan Szymanski
Original Date:  07-08-2001
Date last Mod:
Comments:				This function returns error code defined in
								DiskAppl.h											
***********************************************************/
unsigned char SM_play_file(unsigned char *fileextension)
{ 
unsigned char errorcode;
unsigned char c;
unsigned int temp,i,j,nblocks;
unsigned int cluster;
unsigned int physicalblock,sector;
unsigned int temp1;
unsigned int logicalblock;
unsigned int totalblocks,blocknum,bpd;//number of 16k blocks

LCD_bar_start(0x0de0);

/* first create/or update address conversion table */
/* but only if doesn't exists as it is time consuming */
if(SM_flag1 == 0)
	{
	errorcode=SM_log_to_phy();
	if(errorcode!=SM_OK) 
    {
    putchar_uart0(0x0a);
    putchar_uart0(0x0d);
    putstring_uart0("Error in SM_log_to_phy: ");
    hexout_uart0(errorcode);    
    return errorcode;	/* error return */
    }
  }
// ????
totalblocks=LCD_fileblocks(SM_current_file);
blocknum=totalblocks-3;
//bpd=totalblocks/160; /* number of block per dot = totalblocks/160 */
bpd=totalblocks/112; /* number of block per dot = totalblocks/112 */

//?????
/* 8MB - root directory in logical block 2 - sectors 32-47 */
//if(SM_info[1]==0xE6) temp=SM_log_to_phyADD1[2]<<4;	/* physical address of logical sector 32 */
/* 16MB - root directory in logical block 1 - sectors 48-63 */
//if(SM_info[1]==0x73) temp=(SM_log_to_phyADD1[1]<<5) + 0x10;	/* physical address of logical sector 48 */

// WAS cluster = SM_start_cluster(temp,fileextension);	/* start cluster in FAT */
// TRY
cluster=start_block[SM_current_file];
if(cluster==0) return SM_FILE_NOTFOUND;
//if(SM_info[1]==0xE6)logicalblock = cluster+1;	/* ???? */
//if(SM_info[1]==0x73)logicalblock = cluster;	/* ???? */
logicalblock = cluster;
// adjustment here for gaps 1000-1024,2000-2024,3000-3024
if(logicalblock>=3000)logicalblock+=72;
  else
    {
    if(logicalblock>=2000)logicalblock+=48;
      else if(logicalblock>=1000)logicalblock+=24;
    }

physicalblock = SM_log_to_phyADD1[logicalblock];

//putchar_uart0(0x0a);
//putchar_uart0(0x0d);
//putstring_uart0("Blocks logical physical: ");
//hexout_uart0_int(logicalblock); 
//putchar_uart0(' ');   
//hexout_uart0_int(physicalblock); 

//if(SM_info[1]==0xE6) sector=physicalblock<<4;	/* x16 as there are 16 sectors per block for 8MB */
//if(SM_info[1]==0x73) sector=physicalblock<<5;	/* x32 as there are 32 sectors per block for 16MB */

//errorcode = SM_read_FAT();	/* first sector of FAT */
														/* (logical sector 26 for 8MB or 42 for 16MB ) is */
														/* moved to RAM, so we can follow cluster chain */ 
//putchar_uart0(' ');
//putchar_uart0('#');
//hexout_uart0(errorcode);

//if(errorcode!=SM_OK) return errorcode;	/* error return */
//!!!!!!!!!!!!!!!
firstblock=1;
//errorcode=SM_play_block(physicalblock);
firstblock=0;
//!!!!!!!!!!!!!!!!!
//putchar_uart0(' ');
//putchar_uart0('$');
//hexout_uart0(errorcode);
/* for the next blocks we need to follow cluster chain */

nblocks=0;
while(cluster!=0x0fff)	/* cluster 0x0fff indicates end */
	{ 
/* find next cluster in a cluster chain */
	temp1=SM_find_next_inFAT(cluster);
	cluster = temp1; 
// try
// WAS  if(cluster==0x0fff) break;
//putstring_uart0("cluster=");
//hexout_uart0_int(cluster);
//putchar_uart0(',');
//putchar_uart0(' ');

/* we check here for max size */
	nblocks++;
	
	//if(SM_info[1]==0xE6) temp1+=1;							/* ??? */
// try
hexout_uart0_int(blocknum--);
//putchar_uart0(0x0d);
/* for progress bar on lcd */
putchar_uart0(' ');
hexout_uart0(bpd);
putchar_uart0(' ');
hexout_uart0(bardots);
putchar_uart0(' ');
hexout_uart0_int(nblocks/bpd);
putchar_uart0(0x0d);
putchar_uart0(0x0a);

if(bardots<(nblocks/bpd)) LCD_bar_update();
/* end of lcd progress bar */
// end of try
// adjustment here for gaps 1000-1024,2000-2024,3000-3024
if(temp1>=3000)temp1+=72;
  else
    {
    if(temp1>=2000)temp1+=48;
      else if(temp1>=1000)temp1+=24;
    }
	
	physicalblock = SM_log_to_phyADD1[temp1];
  errorcode=SM_play_block(physicalblock);
// checking for key
  if(validkey==1)
    {
    switch(key)
      {
      case '2'://PAUSE
        validkey=0;
        Red_LED_state=0x0100;
        Green_LED_state=0x0001;
        /* say PAUSE on LCD */
        while(validkey==0){}
        Red_LED_state=0x0000;
        Green_LED_state=0x0101;
        /* say NOW PLAYING on LCD */
        v_reset(vol);
        break;
      case '6'://up
        //st_volume(-4); //volume up
        if(vol>5) vol-=5;
        v_volume(vol);
//        putchar_uart0(0x0a);
//        putchar_uart0(0x0d);
//        hexout_uart0(vol);
//        putchar_uart0(0x0a);
//        putchar_uart0(0x0d);
        break;
      case '7'://down
        //st_volume(4); //volume down
        if(vol<250) vol+=5;
        v_volume(vol);
//        putchar_uart0(0x0a);
//        putchar_uart0(0x0d);
//        hexout_uart0(vol);
//        putchar_uart0(0x0a);
//        putchar_uart0(0x0d);
        break;

      default: //keys '1','3','4','5'
        {
        //validkey=0;
        return SM_KEY_BREAK;
        }
      }//end of switch(key)
    validkey=0;
    }//end of if(validkey==1)
// end of key check
	}

return SM_OK;
}
/* End of SM_play_file ************************************/ 

/***********************************************************
Function:       SM_play_block
Purpose: 				to play 1 block of *.mp3 file
Author:  				Jan Szymanski
Original Date:  07-08-2001
Date last Mod:
Comments:				This function returns error code defined in
								DiskAppl.h											
***********************************************************/
unsigned char SM_play_block(unsigned int block)
{
unsigned long sector;
unsigned long startsector;
unsigned char error;
//unsigned char *ptr;
unsigned int i,j,l;
unsigned long n;
unsigned char temp,temp1,temp2;
unsigned char c;

//putstring_uart0("phyblock=");
//hexout_uart0_int(block);
//putchar_uart0(' ');

//if(SM_info[1]==0xE6) sector=block<<4;	/* x16 as there are 16 sectors per block for 8MB */
//if(SM_info[1]==0x73) sector=block<<5;	/* x32 as there are 32 sectors per block for 16MB */
sector=block<<5;

/* for first block do not play first sector - for VS1001 to work */
startsector=sector;
//if(firstblock==1) startsector=sector+4;

//for(i=sector;i<sector+SM_info[7];i++)
//	{
//	error=SM_page_read(SM_page_data,i);
  //hexout_uart0_int(i); 
//  ptr=SM_page_data;
//  for(j=0; j<512; j++)
//    putchar_uart1(*ptr++);
//  }
//return (error);

temp=(unsigned char)sector;
temp1=(sector>>8);
temp2=(sector>>16);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -