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

📄 xflash.c

📁 富士通单片机内部FLASH的操作,富士通单片机的资料网上极少,希望对大家有所帮助 XFlash_V1.0.zip
💻 C
字号:
/*** COPYRIGHT 2002 STMicroelectronics ****************************************

Source File Name : XFLASH.c 
Documentations   : 
Group            : CMG
Author           : M.MASTOURI
Version          : Final
Date             : 10/20/2002        	   	   	      	       		        
******************************************************************************/

#include "XFLASH.h"
#ifdef COSMIC
#include "Map_72264.c"
#endif 
#ifdef HIWARE
#include "Map_72264.h"
#endif 
/****************************************************************************

                       XFLASH SUB-ROUTINE
It should be copied and executed into RAM : xFlash is not accessible when 
programming
*****************************************************************************/
void XFlashWrite(void)  
{ 	

 FCSR |= 0x02;          
#ifdef COSMIC
 #asm                         			 	
      LD X,0xFD
      DEC X 
      Latchloading:
		LD A,([0xFB.w],X)
		LD ([0xF9.w],X),A
		DEC X
		JRPL Latchloading
 #endasm
#endif
#ifdef HIWARE
 #asm                         			 	
      LD X,IapDataNb
      DEC X 
      Latchloading:
		LD A,([IapDataPtr.w],X)
		LD ([IapFlashPtr.w],X),A
		DEC X
		JRPL Latchloading
 #endasm
#endif
 FCSR |= 0x01; 
 while (FCSR & 0x01) {};
}

/******************************************************************************
ROUTINE NAME : RASS_Disable
INPUT/OUTPUT : none
DESCRIPTION  : Write RASS key in FCSR to unprotect the Flash memory
******************************************************************************/     
void RASS_Disable(unsigned char key1,unsigned char key2)
{
  FCSR = key1;   // First RASS key
  FCSR = key2;   // Second RASS key
}
  
/*****************************************************************************
ROUTINE NAME : XFlashWriteBlock
INPUT/OUTPUT : Ram Start, Flash Start, Byte Number,
DESCRIPTION  : Write a block and return the status :1 success, 0 fail
******************************************************************************/     
unsigned char  XFlashWriteBlock(unsigned char *Buffer, unsigned int Flash, unsigned char ByteNb )
{
  
  unsigned char BytesLeft,BufferOffset=0,BlockBytes=0;
  #ifdef COSMIC
  @near unsigned char *ptrSrc;
  @near unsigned char  *ptrDest;
  #endif
  #ifdef HIWARE
  unsigned char *far ptrSrc;
  unsigned char *far ptrDest;
  #endif
  /******** initialize ptr ****/ 
  IAP_FLASH_PTR = Flash ;
  IAP_DATA_PTR 	=(unsigned int)&(unsigned char)*Buffer ;
  IAP_DATA_NB   = ByteNb;
  IAP_CODE_PTR  = STACK_END;
  /****************************/
  #ifdef COSMIC		
      #asm        
      SIM             
      LD A,S          
      LD 0xFF,A	
      #endasm 
  #endif
  #ifdef HIWARE		
      #asm        
      SIM             
      LD A,S          
      LD IapCodeLsb,A	
      #endasm 
  #endif
/******************* Copy XFlashWriter into Dynamic Buffer in Stack ***************/
  
  IAP_CODE_PTR =STACK_END-CODE_SIZE-7;
  #ifdef COSMIC
  ptrSrc =  (@near unsigned char *) &XFlashWrite;   
  ptrDest = (@near unsigned char *) IAP_CODE_PTR;
  #endif
  #ifdef HIWARE
  ptrSrc = (unsigned char far*)&XFlashWrite;
  ptrDest = (unsigned char far*) IAP_CODE_PTR;
  #endif
     
  for ( BytesLeft =0 ; BytesLeft < CODE_SIZE ; BytesLeft++)  	             
     *(ptrDest +BytesLeft) = *(ptrSrc+ BytesLeft);
/**********************************************************************************/  		
  BytesLeft=ByteNb;
    do  
    {	
       /********************* USER Funcion ****************************************/
       #asm
       RIM
       #endasm
       UserWhileWriteBlock();      
       #asm
       SIM
       #endasm 
       /***************************************************************************/
       if ( BytesLeft <= 32 ) BlockBytes = BytesLeft;
       else BlockBytes = 32; 
       
       IAP_FLASH_PTR    = Flash + BufferOffset;  	
       IAP_DATA_PTR 	= (unsigned int)&(unsigned char)*Buffer + BufferOffset;  	
       IAP_DATA_NB      = BlockBytes;    
       #ifdef COSMIC		
       #asm
       	call [0xFE.w]
       #endasm  
       #endif     
       #ifdef HIWARE
       #asm
       	call [IapCodeMsb.w]
       #endasm  
       #endif
       BytesLeft-=32;
       BufferOffset+=BlockBytes;
                
     } while (BytesLeft > 0 &&  BytesLeft < ByteNb );
       
       #asm
       RIM
       #endasm
       
return(1);       
}
/*** (c) 2002  ST Microelectronics ****************** END OF FILE ************/

⌨️ 快捷键说明

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