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

📄 te28f256.c

📁 vxWorks V5.5下Flash驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************   
Flash Disk  Driver for Intel e28f256(P30)
this flash is BP,so we know the param block at front.ya!
driver code must be use ansi c write
Manufacture Code 00000 (00) 89
Device Code 256-Mbit      00001 (00) 1c

shenming  write  2006-08 
*************************************************************************/

#define  DEBUG_TFFS28F256
#undef   DEBUG_TFFS28F256

#include "tffs/flflash.h"
#include "tffs/backgrnd.h"
#include "ppc405EP.h"


#include "stdio.h"
#include "stdlib.h"
#include "string.h"



/* JEDEC ids for this MTD */
#define E28F256_MANU_ID                    0x0089  
#define E28F256_DEVICE_ID                  0x891c  
#define E28F256_FLASH                      0x891c 

#define CLEAR_LOCK_BIT                     0x6060
#define CONFIRM_CLEAR_LOCK_BIT             0xd0d0
#define SETUP_ERASE	                       0x2020
#define SETUP_WRITE	                       0x1010
#define WRITE_TO_BUFFER                    0xe8e8
#define CLEAR_STATUS                       0x5050
#define READ_STATUS                        0x7070
#define READ_ID                            0x9090
#define SUSPEND_WRITE                      0xb0b0
#define SUSPEND_ERASE                      0xb0b0
#define CONFIRM_ERASE                      0xd0d0
#define CONFIRM_WRITE                      0xd0d0
#define RESUME_ERASE                       0xd0d0
#define READ_ARRAY	                       0xffff


#define	WSM_VPP_ERROR                      0x08
#define   WSM_ERROR	                       0x38
#define   WSM_SUSPENDED	                   0x40
#define   WSM_READY                        0x80
#define   GSR_ERROR                        0x20

/********************************************************************
                       e28f256MTDMap	
map the offset address to flash  mmc address
DEBUG:ok 
2006-8-29
*********************************************************************/

static void FAR0 * e28f256MTDMap(FLFlash vol, CardAddress addr, int inter)
{
    /*FLASH1_START  is the flash address begin 0xf0000000*/
    /*the param block ox20000 must stride*/

    UINT32 ret;
    ret = FLASH1_START + 0x20000+addr;
    vol.socket->remapped = TRUE;
    return (void FAR0 *)ret;

}

/********************************************************************
                      e28f256Write			
									
 Write a block of bytes to Flash					
									
 This routine will be registered as the MTD flash.write routine	
									
 Parameters:                                                          
	vol		       : Pointer identifying drive			
    address		: Card address to write to			
    buffer		: Address of data to write			
	length		: Number of bytes to write			
	overwrite	: TRUE if overwriting old Flash contents	
			  FALSE if old contents are known to be erased	
                                                                      
 Returns:                                                             
	FLStatus	: 0 on success, failed otherwise
	
	
DEBUG: ok		
*********************************************************************/

static FLStatus e28f256Write(FLFlash vol,
                            CardAddress address,/*the block offser address*/
                            const void FAR1 *buffer,/*the byte buffer*/
                            int length,
                            FLBoolean overwrite)
{
    int i,cLength;
    FLStatus status = flOK;
    FlashWPTR flashPtr,flashTmp;
    volatile UINT16 *gBuffer;

#ifdef DEBUG_TFFS28F256
    printf("into e28f256Write function\n");
#endif

    if (flWriteProtected(vol.socket))
        return flWriteProtect;
 
    if ((length & 1) || (address & 1)) /* Only write words on word-boundary */
        return flBadParameter;
        
#ifdef SOCKET_12_VOLTS
    checkStatus(flNeedVpp(vol.socket));
#endif

    flashTmp = flashPtr = (FlashWPTR) vol.map(&vol, address, vol.interleaving); 

#ifdef DEBUG_TFFS28F256
    printf("e28f256Write will write  (flashTmp,flashPtr)= 0x%x address=0x%x length=0x%x \n",flashPtr,address,length);
#endif

/*must unlock the block*/

    flashPtr[0] = CLEAR_LOCK_BIT; 
            
    do{}while(!(flashPtr[0] & WSM_READY ));

    flashPtr[0] = CONFIRM_CLEAR_LOCK_BIT;
    
    do{}while(!(flashPtr[0] & WSM_READY ));


/*buffer unsigned char type buffer to  unsigned short buffer and write the data*/
    cLength = length/2;
    gBuffer = (UINT16 *)buffer;  

    for(i = 0; i < cLength; i++)
    {
        *flashPtr = SETUP_WRITE;
        do{}while(!(flashPtr[0] & WSM_READY ));
        *flashPtr = *gBuffer;
        do{}while(!(flashPtr[0] & WSM_READY ));
        flashPtr++;
        gBuffer++;
        *flashPtr = READ_ARRAY;
    }
  
#ifdef DEBUG_TFFS28F256
    printf("e28f256Write successed wirte to flashPtr= 0x%x address=0x%x length=0x%x\n",flashPtr,address,length);
#endif

#ifdef SOCKET_12_VOLTS
    flDontNeedVpp(vol.socket);
#endif

    /* verify the data */

    if (status == flOK && tffscmpWords((void FAR0 *) flashTmp, (void FAR1 *) buffer,length)) 
    {
#ifdef DEBUG_TFFS28F256
    printf("verify data error!.\n");
    printf("ya! error exit e28f256Write function\n");
#endif
        status = flWriteFault;
        return status;
    }
#ifdef DEBUG_TFFS28F256
    printf("successed exit e28f256Write function\n\n");
#endif  
   
    return status;
}


/********************************************************************
                      te28f256Erase			
									
 Erase one or more contiguous Flash erasable blocks			
									
 This routine will be registered as the MTD vol.erase routine	
									
 Parameters:                                                          
	vol		: Pointer identifying drive			
    firstErasableBlock : Number of first block to erase		
	numOfErasableBlocks: Number of blocks to erase			
                                                                      
 Returns:                                                             
	FLStatus	: 0 on success, failed otherwise
	
DEBUG: ok			
********************************************************************/

FLStatus e28f256Erase(FLFlash vol,
			   int firstErasableBlock,
			   int numOfErasableBlocks)
{
    FLStatus status = flOK; /* unless proven otherwise */
    FlashWPTR flashPtr;
    FlashWPTR addr;
    int i=0;
    FLBoolean finished;
 

    if (flWriteProtected(vol.socket))
        return flWriteProtect;
  
#ifdef DEBUG_TFFS28F256
    printf("into e28f256Erase function  firstErasableBlock=0x%x,numOfErasableBlocks=0x%x.\n",firstErasableBlock,numOfErasableBlocks);
#endif  
 
#ifdef SOCKET_12_VOLTS
    checkStatus(flNeedVpp(vol.socket));
#endif

    flashPtr = (FlashWPTR) vol.map (&vol,(firstErasableBlock) * vol.erasableBlockSize,vol.interleaving);

#ifdef DEBUG_TFFS28F256
    printf("the flash addr  flashPtr=0x%x.\n",flashPtr);
#endif

   
    for(;i<numOfErasableBlocks;++i)
    {
        addr = flashPtr + i * vol.erasableBlockSize;

/*unlock*/
        addr[0] = CLEAR_LOCK_BIT;         
        do{}while(!(addr[0] & WSM_READY ));
        addr[0] = CONFIRM_CLEAR_LOCK_BIT ;
        do{}while(!(addr[0] & WSM_READY ));

/*start erase*/
        addr[0] = SETUP_ERASE;
        do{}while(!(addr[0] &WSM_READY ));
        
 /*confirm erase*/
        addr[0] = CONFIRM_ERASE; 
 	
        do{}while(!(addr[0] &WSM_READY ));
        
        do{
            finished = TRUE;
            if (!(addr[0] & WSM_READY ))
                finished = FALSE;
            else{
                if ( addr[0] & WSM_ERROR ) 
                {
#ifdef DEBUG_PRINT
    DEBUG_PRINT("erase error.\n");
#endif
                    status = (addr[0] & WSM_VPP_ERROR ) ?  flVppFailure : flWriteFault;
                    addr[0] = CLEAR_STATUS;
                }
/*set device read mode*/
                addr[0] = READ_ARRAY;
            }
        } while (!finished);
   }

#ifdef SOCKET_12_VOLTS
    flDontNeedVpp(vol.socket);
#endif

#ifdef DEBUG_TFFS28F256
    printf("exit e28f256Erase function\n\n");
#endif
    return status;

}


/********************************************************************
                     te28f256Identify                             	
									                                    
 Identifies media based on Intel e28f256 and registers as an MTD for	
 such.                                                                
									
 This routine will be placed on the MTD list in custom.h. It must be	

⌨️ 快捷键说明

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