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

📄 smedia.c

📁 使用MSP430做MP3播放器的专题源码
💻 C
📖 第 1 页 / 共 2 页
字号:
SM_write(temp);
SM_write(temp1);
SM_add_latch_dis

for(i=0;i<528;i++)	SM_write(*(write_data+i));    /*Page data write*/

SM_cmd_latch_en
SM_write(SM_PAGE_PROGRAM_2C);	    /*Page Program command (10h)*/
SM_cmd_latch_dis

err_flag = SM_status_check();
if (err_flag !=PASS)
	{
	putstring_uart0("Invalid Blocks are detected... ");
	SM_chip_disable
	//RealTimeBadMark(page_add);
	return FAIL;
	}
SM_chip_disable

SM_page_read(SM_page_data,page_num);
for(i=0;i<528;i++)
	{
	if(*(write_data+i)!=*(SM_page_data+i))
		{
		err_flag=FAIL;
		break;
		}
	}
	
if(err_flag!=PASS)
	{
	putstring_uart0("\r\nInvalid Blocks are detected... ");
	//RealTimeBadMark(page_add);
	return FAIL;
	}
	
return PASS;
}
/* End of SM_page_write ***********************************/

/***********************************************************
Function:       SM_block_erase
Purpose: 				to erase one block of SmarMedia
Author:  				Jan Szymanski
Original Date:  02-07-2001
Date last Mod:
Comments:															
***********************************************************/

unsigned char SM_block_erase(unsigned int block_number)
{
unsigned char low,high;
unsigned int sector;

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

low = (unsigned char)(sector);
high = (sector>>8);

//putstring_PC((unsigned char *)"\r\nERASING BLOCK from sector... ");
//hexout_PC(high);
//hexout_PC(low);
//putstring_PC((unsigned char*)("\r\n"));

SM_chip_enable

SM_cmd_latch_en
SM_write(SM_BLOCK_ERASE_1C);	/* Block Erase command (60h) */
SM_cmd_latch_dis
SM_add_latch_en
SM_write(low);
SM_write(high);
SM_add_latch_dis

SM_cmd_latch_en
SM_write(SM_BLOCK_ERASE_2C);	/* Block Erase Confirm command (D0h) */
SM_cmd_latch_dis
if(SM_status_check()!=FAIL)	
	{
	putstring_uart0("ERASE PASS\r\n");
	SM_chip_disable
	return PASS;
	}
	else
		{
		putstring_uart0("ERASE FAIL\r\n");
		SM_chip_disable
		return  FAIL;
		}
SM_chip_disable
}
/* End of SM_block_erase **********************************/
/* the following are TI functions from slaa103.pdf */
/***********************************************************************/
/* Flash_wb */
/* programs 1 byte (8 bit) into the flash memory */
/***********************************************************************/
void Flash_wb( char *Data_ptr, char byte )
{
FCTL3 = 0x0A500; /* Lock = 0 */
FCTL1 = 0x0A540; /* WRT = 1 */
*Data_ptr=byte; /* program Flash word */
FCTL1 = 0x0A500; /* WRT = 0 */
FCTL3 = 0x0A510; /* Lock = 1 */
}
/***********************************************************************/
/* Flash_ww */
/* programs 1 word (16 bits) into the flash memory */
/***********************************************************************/
void Flash_ww( int *Data_ptr, int word )
{
FCTL3 = 0x0A500; /* Lock = 0 */
FCTL1 = 0x0A540; /* WRT = 1 */
*Data_ptr=word; /* program Flash word */
FCTL1 = 0x0A500; /* WRT = 0 */
FCTL3 = 0x0A510; /* Lock = 1 */
}
/***********************************************************************/
/* Flash_clr */
/* erases 1 Segment of flash memory */
/***********************************************************************/
void Flash_clr( int *Data_ptr )
{
FCTL3 = 0x0A500; /* Lock = 0 */
FCTL1 = 0x0A502; /* ERASE = 1 */
*Data_ptr=0; /* erase Flash segment */
}
/* end of TI functions */
void Flash_test(void)
{
unsigned int *ptr;
ptr=(unsigned int *)0xf600;
//ptr=&SM_log_to_phyADD1;
putstring_uart0("Flash_ww");
_DINT();          /* disable interrupts */
if(*ptr!=0xffff)
  {
  putstring_uart0("Flash_clr");
  Flash_clr(ptr);
  }
Flash_ww(ptr,0x0506);
_EINT();          /* start interrupts */
}
/***********************************************************
Function:       Flash_seg_write
Purpose: 				to write one segment of onboard flash
Author:  				Jan Szymanski
Original Date:  28-06-2001
Date last Mod:
Comments:															
***********************************************************/
unsigned char Flash_seg_write (unsigned char *source, unsigned char *dest)
{
unsigned char *psource;
unsigned char *pdest;
unsigned int i;
unsigned char flag;
unsigned char errorcode;
unsigned int *ptr;

// protection against killing the system

if(pdest>(unsigned char *)0xfc00)
  {
  putchar_uart0(0x0d);
  putchar_uart0(0x0a);
  putstring_uart0("NO WAY...");
  hexout_uart0_int((int)pdest);
  putchar_uart0(0x0d);
  putchar_uart0(0x0a);
  return -1;
  }

// assumed segment size = 512 bytes
// first we compare source and destination
psource=source;
pdest=dest;
flag=0;
for(i=0;i<512;i++)
  if(*psource++!=*pdest++) flag=1;
if(flag==0)
  {
  putstring_uart0("same");
  return(0);
  }
// source and destination different
putstring_uart0("different");
_DINT();          /* disable interrupts */
Flash_clr((unsigned int *)dest);// erase segment
// programme byte by byte
psource=source;
pdest=dest;
for(i=0;i<512;i++)
  Flash_wb(pdest++,*psource++);
_EINT();          /* start interrupts */
/* for debugging only */
psource=source;
pdest=dest;

//ptr=dest;
//for(i=0;i<256;i++)
//	{
//	putstring_uart0("0x");
//	hexout_uart0_int(*ptr++);
//	putchar_uart0(',');
//	}
//putchar_uart0(0x0d);
//putchar_uart0(0x0a); 
return(0);
}
/* End of Flash_seg_write *********************************/

/***********************************************************
Function:       SM_all_read
Purpose: 				to read all???	
Author:  				Jan Szymanski
Original Date:  28-06-2001
Date last Mod:
Comments:															
***********************************************************/
unsigned char	SM_all_read(unsigned char *page_data,unsigned int page_num)
{
unsigned char c;
unsigned long i;
unsigned int j;
unsigned char temp,temp1;
unsigned char *ptr;
unsigned int smth;

temp=(unsigned char)page_num;
temp1=(page_num>>8);

SM_chip_enable
//reset();
SM_cmd_latch_en
SM_write(SM_READ1_C);	/*Main area data read command(00h)*/
SM_cmd_latch_dis
SM_add_latch_en

SM_write(0x00);
SM_write(temp);
SM_write(temp1);
SM_add_latch_dis

for(smth=0;smth<32768;smth++)
{	
// waiting for R/B
for(i=0; i<10000; i++)
	{ 
	//if(P4.PORT.BIT.B5==0) putchar_PC('0');
	//	else putchar_PC('1');
	if((P1IN &0x20)==0x20) break; /* P15 is R/B input */
	}	// waiting for ready 
/* short delay here */
//for(i=0; i<100; i++){nop;}

/* this part for debugging only */		
//putstring_PC((unsigned char*)("\r\n"));	
//hexout_PC(temp1);
//hexout_PC(temp);
//putstring_PC((unsigned char*)("\r\n"));	
/* end of debugging part */		 

//	for(i=0;i<SM_info[4];i++)
ptr=page_data;
for (j=0;j<528;j++)
	{
	c = SM_read();
	//hexout_uart0(c);
	*ptr++ = c;    /*Page data Read*/
  //*(page_data+j)=c;
	}
ptr=SM_page_data;
  for(j=0; j<512; j++)
    // if necessary wait for DATA_R to be high
    //while((P5IN&0x01)==0){}
    putchar_uart1(*ptr++);
}//end of for...
SM_chip_disable
return PASS;
}
/* End of SM_all_read ************************************/

/***********************************************************
Function:       SM_extra_read
Purpose: 				to read extra 16 bytes from one page of SmartMedia	
Author:  				Jan Szymanski
Original Date:  28-06-2001
Date last Mod:
Comments:															
***********************************************************/
unsigned char	SM_extra_read(unsigned char *page_data,unsigned long page_num)
{
unsigned char c;
unsigned long i;
unsigned int j;
unsigned char temp,temp1,temp2;
unsigned char *ptr;

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

//hexout_uart0(temp);
//hexout_uart0(temp1);
//hexout_uart0(temp2);
//putchar_uart0(',');


SM_chip_enable
//reset();
SM_cmd_latch_en
SM_write(SM_READ3_C);	/* Extra area data read command(0x50)*/
SM_cmd_latch_dis
SM_add_latch_en

SM_write(0x00);
SM_write(temp);
SM_write(temp1);
if(SM_info[11]>=64)
  {
//  putchar_uart0('E');
  SM_write(temp2);//another address cycle
  }
SM_add_latch_dis
	
// waiting for R/B
for(i=0; i<10000; i++)
	{ 
	//if(P4.PORT.BIT.B5==0) putchar_PC('0');
	//	else putchar_PC('1');
	if((P1IN &0x20)==0x20) break; /* P15 is R/B input */
	}	// waiting for ready 
/* short delay here */
//for(i=0; i<100; i++){nop;}

/* this part for debugging only */		
//putstring_PC((unsigned char*)("\r\n"));	
//hexout_PC(temp1);
//hexout_PC(temp);
//putstring_PC((unsigned char*)("\r\n"));	
/* end of debugging part */		 

//	for(i=0;i<SM_info[4];i++)
ptr=page_data;
ptr+=512;
for (j=0;j<16;j++)
	{
	c = SM_read();
//	hexout_uart0(c);
//  putchar_uart0(' ');
	*ptr++ = c;    /*Page data Read*/
  //*(page_data+j)=c;
	}

//putstring_uart0(" press,");
//while(ischar_uart0()==0){}
//getchar_uart0();
//putchar_uart0(0x0d);
//putchar_uart0(0x0a);
//end of for debugging
SM_chip_disable
return PASS;
}
/* End of SM_extra_read ************************************/

/**********************************************************/
/* End of file: SmartMedia.c                              */
/**********************************************************/

⌨️ 快捷键说明

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