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

📄 amdmtd_cwc.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
字号:
/* amdmtd_cwc.c - CWV-183 board series CWC system-dependent TrueFFS library *//********************************************************************** * *   Copyright (c) 2005, Dy 4 Systems All rights reserved. *   This Source Code is the Property of Dy 4 Systems Inc. and can *   only be used in accordance with Source Code License *   Agreement of Dy 4 Systems Inc. dba (doing business as)  *   CURTISS-WRIGHT CONTROLS EMBEDDED COMPUTING, "CWCEC".  * **********************************************************************//* Copyright 1984-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/* FAT-FTL Lite Software Development Kit * Copyright (C) M-Systems Ltd. 1995-1997	*//*modification history--------------------01b,04Aug05,rcd Change to ensure min write is Bankwidth.01a,27jul05,tis Created from amdmtd_dy4.c v1f.*//************************************************************************//*                                                                      *//*		FAT-FTL Lite Software Development Kit			*//*		Copyright (C) M-Systems Ltd. 1995-1996			*//*									*//************************************************************************//*----------------------------------------------------------------------*//*                                                                      *//* This MTD supports the following Flash technologies:                  *//*                                                                      *//* - AMD Am29F080 8-mbit devices					*//* - AMD Am29LV080 8-mbit devices			       		*//* - AMD Am29F016 16-mbit devices					*//* - Fujitsu MBM29F080 8-mbit devices					*//*									*//* And (among others) the following Flash media and cards:		*//*                                                                      *//* - AMD Series-D PCMCIA cards                                        	*//* - AMD AmMC0XXA Miniature cards					*//* - AMD AmMCL0XXA Miniature cards					*//*									*//*----------------------------------------------------------------------*/#include "stdio.h"#include "config.h"#include "tffs/flflash.h"#include "tffs/backgrnd.h"/* To remove when call implemented in CSS LIB */#include "h/drv/dy4/vxCss_dy4.h"#ifdef __cplusplusextern "C" {#endif#undef TFFS_DEBUG#define BANKWIDTH           4#define ERASE_SEGMENT_SIZE  0x00040000L#define PSUEDO_CHIP_SIZE    0x00800000L /* Set to 8M to be able to reserved space at end of flash */#define REAL_CHIP_SIZE      0x01000000L#define CHIP_INTERLEAVE     2#define  FLASH_ADDR         0xe0000000#define	TFFS_FFW_RES_SPACE  0x01000000  /* The upper 16MEG of flash reserved for FFW *//* Virtual flash size */#define VIRTUAL_FLASH_SIZE  (FLASH_SIZE - TFFS_FFW_RES_SPACE)int usableFlashSize = VIRTUAL_FLASH_SIZE;/*----------------------------------------------------------------------*//*----------------------------------------------------------------------*//*                      a m d M T D W r i t e                           *//*                                                                      *//* Write a block of bytes to Flash                                      *//*                                                                      *//* This routine will be registered as the MTD vol.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                *//*----------------------------------------------------------------------*/static FLStatus amdMTDWrite(FLFlash vol,	            CardAddress address,	            const void FAR1 *buffer,	            int length,	            FLBoolean overwrite){    FLStatus 		status;    FlashWPTR 		flashPtr;    char            buff[BANKWIDTH];    int             i=0;    char           *pbuf = (char *) buffer;	if (flWriteProtected(vol.socket))		return flWriteProtect;			flashPtr = (FlashWPTR) flMap(vol.socket,address);    #ifdef TFFS_DEBUG      printf("Flash Write Function: %x,  %d\n", (UINT)flashPtr, length);    #endif    /* Protect the FFW reserved space of flash bank */    if ( (UINT)flashPtr >= FLASH_ADDR + VIRTUAL_FLASH_SIZE) /* Last reserved space */    {        printf("ERROR Writing in restricted area\n");        return flWriteFault;    }    #ifdef FLASH_ALWAYS_LOCK      cssNVM_lock(FLASH_UNLOCK); /* Unlock all bank of flash */    #endif /* FLASH_ALWAYS_LOCK */    if(length < BANKWIDTH)    {        bcopy((char *) flashPtr, (char *) buff, BANKWIDTH);        for (i=0;i<length;i++)        {            buff[i] = pbuf[i];        }#ifdef TFFS_DEBUGprintf("amdMTDWrite: doing a 4 byte program\n");#endif        status = cssNVM_program((void *)buff,(void *)flashPtr, BANKWIDTH, NULL, NULL, 0, 0, NULL);    }    else    {        status = cssNVM_program((void *)buffer,(void *)flashPtr, length, NULL, NULL, 0, 0, NULL);    }    #ifdef FLASH_ALWAYS_LOCK      cssNVM_lock(FLASH_LOCK); /* Lock all bank of flash */    #endif /* FLASH_ALWAYS_LOCK */    return status;}/*----------------------------------------------------------------------*//*                     a m d M T D E r a s e                            *//*                                                                      *//* 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                        *//*----------------------------------------------------------------------*/static FLStatus amdMTDErase(FLFlash vol,			  int firstErasableBlock,			  int numOfErasableBlocks){    int        iBlock;    FLStatus   status = flOK;    FlashPTR   flashPtr;    if (flWriteProtected(vol.socket))        return flWriteProtect;    for (iBlock = 0; iBlock < numOfErasableBlocks; iBlock++)        {        flashPtr = (FlashPTR) flMap(vol.socket,(firstErasableBlock + iBlock) * vol.erasableBlockSize);        #ifdef TFFS_DEBUG               printf("Flash Erase Function: 0x%x, %d\n", (UINT)flashPtr,                    numOfErasableBlocks * (UINT)vol.erasableBlockSize);        #endif /* TFFS_DEBUG */         /* Protect the last 1meg of flash bank */        if ((UINT)flashPtr >= FLASH_ADDR + VIRTUAL_FLASH_SIZE) /* Last reserved space */           {           printf("ERROR Erasing in restricted area\n");           return flWriteFault;           }        #ifdef FLASH_ALWAYS_LOCK            cssNVM_lock(CSS_UNLOCK); /* Unlock all bank of flash */        #endif /* FLASH_ALWAYS_LOCK */        /* Call to DY4 FFW function */        status = cssNVM_erase((void   *)flashPtr, numOfErasableBlocks * (UINT)vol.erasableBlockSize, NULL, NULL);        #ifdef FLASH_ALWAYS_LOCK            cssNVM_lock(CSS_LOCK); /* Lock all bank of flash */        #endif /* FLASH_ALWAYS_LOCK */        }      return status;}/*----------------------------------------------------------------------*//*                    a m d M T D I d e n t i f y                       *//*                                                                      *//* Identifies AMD and Fujitsu flash media and registers as an MTD for   *//* such.                                                                *//*                                                                      *//* On successful identification, the Flash structure is filled out and  *//* the write and erase routines registered.                             *//*                                                                      *//* Parameters:                                                          *//*	vol		: Pointer identifying drive	                *//*                                                                      *//* Returns:                                                             *//*	FLStatus	: 0 on positive identificaion, failed otherwise *//*----------------------------------------------------------------------*/FLStatus amdMTDIdentify(FLFlash vol){    FlashPTR  FlashPtr;    #ifdef DEBUG_PRINT      DEBUG_PRINT("Debug: entering AMD MTD identification routine.\n");    #endif /* DEBUG_PRINT */    cssNVM_lock((void *)FLASH_ADDR, 0, CSS_UNLOCK,NULL);    flSetWindowBusWidth(vol.socket, 32);/* use 32 or 64-bits */    flSetWindowSpeed(vol.socket,120);  /* 120 nsec. */    flSetWindowSize(vol.socket,8);	/* 8 KBytes */    FlashPtr = (FlashPTR) flMap(vol.socket,0);    vol.chipSize = PSUEDO_CHIP_SIZE; /* Set to 8M to be able to reserved space at end of flash */    vol.interleaving = CHIP_INTERLEAVE;    vol.noOfChips = (UINT32) ( usableFlashSize / vol.chipSize);      vol.erasableBlockSize = ERASE_SEGMENT_SIZE * CHIP_INTERLEAVE; /* 64KB * x chips wide */    vol.flags |= SUSPEND_FOR_WRITE;    /* Register our flash handlers */    vol.write = amdMTDWrite;    vol.erase = amdMTDErase;    #ifdef FLASH_ALWAYS_LOCK        cssNVM_lock(CSS_UNLOCK); /* Unlock all bank of flash */    #endif /* FLASH_ALWAYS_LOCK */    #ifdef DEBUG_PRINT      DEBUG_PRINT("Debug: Identified AMD or Fujitsu flash media.\n");    #endif /* DEBUG_PRINT */    return flOK;}#ifdef __cplusplus}#endif

⌨️ 快捷键说明

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