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

📄 drvfs.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
字号:
//--------------------------------------------------------------------------------- 
//
//      Copyright (C) SEIKO EPSON CORP. 2004 
//
//      GROUP					: SEE LSI
//      FILE                    : drvFS.c
//      MODULE                  : storage module
//      Function description    : Driver 
//      Revision history        :                                                                                               
//                                Date            userName        	Description
//                                2004/04/15      David		      	start
//
//      Notes                   : 
//
//---------------------------------------------------------------------------------

#include "drvFS_IO.h"
#include "drvFS.h"
#include "mcp_ctl.h"
#include "adv_ctl.h"
#include "smt_fat.h"
#include "ramdsk.h"

/****************************************************************************
 *	Internal function prototype												*
 ****************************************************************************/

//---------------------------------------------------------------------------------
// external variables
//---------------------------------------------------------------------------------
extern	const struct SMT_DEV_INFO	*smt_pDevInf;	// Device Information Structure

/****************************************************************************
	DrvFS_Init()
 ----------------------------------------------------------------------------
	description:

	argument:	(none)
	return:		(none)
	input:		(none)
	output:		(none)
	flag:		(none)
	global:		(none)
	comment:	(none)
 ****************************************************************************/
void DrvFS_Init()
{
	/* Default inital device mcp */
	DrvFS_IO_InitSmt(DRV_MCP);
	DrvFS_IO_SelSmt(DRV_MCP);
	ramdskMakeDriveImage();

}
/**** End of function *******************************************************/


/****************************************************************************
	DrvFS_GetMediaInfo
 ----------------------------------------------------------------------------
	description:

	argument:
		long				DrvNum	<in>
												DRV_SM:		SmartMedia
												DRV_RAM:	RAM disk
		STG_MEDIA_INFO		*Info	<out>

	return:
		int					ret		<out>	 0:
											-1:
											-2:
	flag:		(none)
	global:		(none)
	comment:	(none)
 ****************************************************************************/
const char *g_Serial = "(not impliment)";

int DrvFS_GetMediaInfo(enDrvNum DrvNum, STG_MEDIA_INFO *Info)
{
	/* get media infomation */
	switch (DrvNum)
	{
	case DRV_RAM:
		Info->bytePerSec = 512;
		Info->secPerDrv = ramdskTotalSec();
		break;
	  
	case DRV_SMT:
	case DRV_MCP:
	case DRV_ADV:
		Info->bytePerSec = smt_pDevInf->pSizeInf->uwDatSize;
		Info->secPerDrv = smt_pDevInf->pSizeInf->ulNumPage;
		break;
		
	default:
		return -1;
	}
	
	Info->type = DrvNum;
	Info->serial = g_Serial;
	return 0;
}
/**** End of function *******************************************************/


/****************************************************************************
	DrvFS_ReadSec()
 ----------------------------------------------------------------------------
	description:

	argument:
		long			DrvNum		<in>
		unsigned long	StrSec		<in>
		unsigned long	SecNum		<in>
		unsigned char*	Buf			<in*>

	return:
		int				Ret			<out>	 0:
											-1:
											-2:
	input:		(none)
	output:		(none)
	flag:		(none)
	global:		(none)
	comment:	(none)
 ****************************************************************************/
int DrvFS_ReadSec(	enDrvNum DrvNum, unsigned long StrSec, 
					unsigned long SecNum, unsigned char *Buf)
{
	int	ret;
	unsigned short	uwDataPerSct;	
	
	if(DrvNum == DRV_RAM){
		ret = ramdskRdSect(0, StrSec, SecNum * 512, Buf);
		if (ret != RAMDSK_E_SUCCESS) return -2;
		return 0;
	}
	
	uwDataPerSct = smt_pDevInf->pSizeInf->uwDatSize;	
	// sector read
	ret = smtRdSect(0, StrSec, SecNum * uwDataPerSct, Buf);
	if (ret != SMT_E_SUCCESS) return -2;
	return 0;
}
/**** End of function *******************************************************/


/****************************************************************************
	DrvFS_WriteSec()
 ----------------------------------------------------------------------------
	description:

	argument:
		long			DrvNum		<in>
		unsigned long	StrSec		<in>
		unsigned long	SecNum		<in>
		unsigned char*	Buf			<in>

	return:
		int				Ret			<out>	 0:
											-1:
											-2:

	input:		(none)
	output:		(none)
	flag:		(none)
	global:		(none)
	comment:	(none)
 ****************************************************************************/
int DrvFS_WriteSec(	enDrvNum DrvNum, unsigned long StrSec,
					unsigned long SecNum, const unsigned char *Buf)
{
	int		ret;
	unsigned short	uwDataPerSct, uwSctPerBlk;
	
	if(DrvNum == DRV_RAM){
		ret = ramdskWtSect(0, StrSec, SecNum * 512, (unsigned char*)Buf, 0);
		if (ret != SMT_E_SUCCESS) return -2;
		return 0;
	}	
	
	uwDataPerSct = smt_pDevInf->pSizeInf->uwDatSize;
	uwSctPerBlk	= smt_pDevInf->pSizeInf->uwBlkSize;
		
	if (SecNum > (uwSctPerBlk-(StrSec % uwSctPerBlk)))
	{
			if (StrSec % uwSctPerBlk)
	  		{ 
		  		ret = smtWtSect(0, StrSec, (uwSctPerBlk-(StrSec % uwSctPerBlk)) * uwDataPerSct, (unsigned char*)Buf, 0);
				if (ret != SMT_E_SUCCESS) return -2;
				(unsigned long)Buf += ((uwSctPerBlk-(StrSec % uwSctPerBlk)) * uwDataPerSct);
				SecNum -= (uwSctPerBlk-(StrSec % uwSctPerBlk));
				StrSec += (uwSctPerBlk-(StrSec % uwSctPerBlk));
	  		}
	}	
	while (SecNum > uwSctPerBlk){
		ret = smtWtSect(0, StrSec, uwSctPerBlk * uwDataPerSct, (unsigned char*)Buf, 0);
		if (ret != SMT_E_SUCCESS) return -2;
		StrSec += uwSctPerBlk;
		SecNum -= uwSctPerBlk;
		(unsigned long)Buf += uwSctPerBlk * uwDataPerSct;
	}
	
	ret = smtWtSect(0, StrSec, SecNum * uwDataPerSct, (unsigned char*)Buf, 0);
	if (ret != SMT_E_SUCCESS) return -2;
	return 0;
}
/**** End of function *******************************************************/

/**** End of file ***********************************************************/

⌨️ 快捷键说明

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