nanddisk.c
来自「ertfs文件系统里面既有完整ucos程序」· C语言 代码 · 共 209 行
C
209 行
/***********************************************************************
* $Workfile: nanddisk.c $
* $Revision: 1.1.1.1 $
* $Author: meterchen $
* $Date: 2003/11/10 17:00:55 $
*
* Project: NAND FLASH MANAGEMENT
*
* Description:
*
*
* Revision History:
*
***********************************************************************
*
* Copyright (c) 2003 CHENMENG
*
* All rights reserved
*
**********************************************************************/
#include "pcdisk.h"
static unsigned short HostCylinders;
static unsigned char HostHeads;
static unsigned char HostSectors;
static unsigned long HostAllSectors;
/************************************************************************
* FUNCTION
*
* pc_rd_ioctl
*
* DESCRIPTION
*
* This function doesn't do anything for the . It is
* included for devtable consistency.
*
* AUTHOR
*
* Meterchen
*
* INPUTS
*
* None.
*
* OUTPUTS
*
* None.
*
*************************************************************************/
int nand_perform_device_ioctl(int driveno, int opcode, PFVOID pargs)
{
DDRIVE *pdr;
DEV_GEOMETRY gc; // used by DEVCTL_GET_GEOMETRY
pdr = pc_drno_to_drive_struct(driveno);
if (!pdr)
return (-1);
switch (opcode)
{
/* Get geometry and format share common code */
case DEVCTL_GET_GEOMETRY:
pc_memfill(&gc, sizeof(gc), '\0');
/* Now set the geometry section */
gc.dev_geometry_heads = HostHeads;
gc.dev_geometry_cylinders = HostCylinders;
gc.dev_geometry_secptrack = HostSectors;
gc.dev_geometry_lbas = gc.dev_geometry_heads*gc.dev_geometry_cylinders*gc.dev_geometry_secptrack;
copybuff(pargs, &gc, sizeof(gc));
return (0);
case DEVCTL_FORMAT:
/* low level format */
Physical$Format();
return(0);
case DEVCTL_CHECKSTATUS:
// Check device status and return
// DEVTEST_NOCHANGE
// DEVTEST_NOMEDIA, DEVTEST_UNKMEDIA or DEVTEST_CHANGED
return(DEVTEST_NOCHANGE);
case DEVCTL_WARMSTART:
pdr->drive_flags |= DRIVE_FLAGS_VALID;
nand_open(0);
return(0);
case DEVCTL_POWER_RESTORE:
/* Fall through */
case DEVCTL_POWER_LOSS:
/* Fall through */
default:
break;
}
return(0);
}
/************************************************************************
* FUNCTION
*
* pc_rd_open
*
* DESCRIPTION
*
* This function prepares the RAM Disk for usage by allocating the
* pages necesary for usage.
*
* AUTHOR
*
* Meterchen
*
* INPUTS
*
* driveno The number assigned to the
* RAM Disk (not used)
*
* OUTPUTS
*
* YES Successful Completion.
* NO Couldn't allocate all of the
* pages.
*
*************************************************************************/
int nand_open(word driveno)
{
word i;
word j;
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
/* configure 4510's io port */
Init$SmartMedia();
/* use only once in factory */
if(Check$Parameter(&HostCylinders,&HostHeads,&HostSectors))
{
//if(ErrCode == ERR_IllegalFmt)
Physical$Format();
//return(ErrCode);
}
return(1);
}
/************************************************************************
* FUNCTION
*
* pc_rd_io
*
* DESCRIPTION
*
* This function reads or writes data from and to the RAM Disk
* based on the 'reading' parameter.
*
* AUTHOR
*
* Takahiro Takahashi
*
* INPUTS
*
* driveno The number assigned to the
* RAM Disk (not used)
* block The block number to read or
* write
* buffer Pointer to the data to be
* placed from a read or
* stored on a write
* count Number of bytes to be read
* or written
* reading Indicates whether or not we
* are reading or writing
*
* OUTPUTS
*
* YES Successful Completion.
* NO Block number is out of range.
*
*************************************************************************/
BOOLEAN nand_io(int driveno, dword block, void KS_FAR *buffer, word count, BOOLEAN reading)
{
byte *p;
dword ltemp;
word page_number;
word byte_number;
word i;
byte *pbuffer;
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
pbuffer = (byte *)buffer;
if(reading)
Media$ReadSector(block, count, pbuffer);
else
Media$WriteSector(block, count, pbuffer);
return(1);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?