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

📄 smt_tmp.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************************/
/*																						*/
/*	Copyright (C) SEIKO EPSON CORP. 2000												*/
/*																						*/
/*	File name : smt_tmp.c																*/
/*		This is smart media control library header file.								*/
/*																						*/
/*	Revision history																	*/
/*		2000.11.17	H.Ogura		start													*/
/*		2000.12.08	H.Ogura		Data are erased when it is release.						*/
/*		2003.03.29	A.Saito		Modify smtTmpWriteData()								*/
/*		2003.06.05	A.Saito		Modify Comment											*/
/*								Remove prototype declaration of functions				*/
/*																						*/
/****************************************************************************************/
/****************************************************************************************/
/*			The tab size of this file is 4.								 				*/
/****************************************************************************************/

#include	"smt.h"
#include	"smt_ctl.h"
#include	"smt_tmp.h"

/********************************************************/
/*	GLOBAL												*/
/********************************************************/
unsigned int		smt_TmpDevIdx;						// Device information structure index.
unsigned char		smt_TmpBuff[512+16];				// Temporary read / write buffer.
struct	SMT_TMPACC	smt_TmpMemTbl[SMT_C_TMPNUM];		// Temporary memory table.

const struct SMT_DEVINF	smt_stDevInf[SMT_C_MODEL] = {
	{ 0xE3,  512, 512, 16,  48 },				//   4MB
	{ 0xE5,  512, 512, 16,  48 },				//   4MB
	{ 0xE6, 1024, 512, 16,  48 },				//   8MB
	{ 0x73, 1024, 512, 32,  64 },				//  16MB
	{ 0x75, 2048, 512, 32,  64 },				//  32MB
	{ 0x76, 4096, 512, 32,  96 },				//  64MB
	{ 0x79, 8192, 512, 32, 128 }				// 128MB
};

extern	union SMT_PROLIX_BUFF	smtProlBuff;
/************************************************************************
 *  smtTmpInitial
 *      Type     : int
 *      Ret val  : Error code.
 *                 =  0 ... Normality completion.
 *                 = -1 ... Device un-support.
 *      Argument : None
 *      Function : This function initializes a free territory table.
 ************************************************************************/
int	smtTmpInitial(void)
{
	unsigned long	ulTblIdx;				// Table index.
	unsigned int	uiModel;				// Device model index.
	unsigned char	bMaker;					// Maker code.
	unsigned char	bDevice;				// Device code.

	//-------------------------------------------------------//
	// The initialization of the free territory information. //
	//-------------------------------------------------------//
	for(ulTblIdx = 0; ulTblIdx < SMT_C_TMPNUM; ulTblIdx++){
		smt_TmpMemTbl[ulTblIdx].bUseFlag = 0;		// Resetting of temporary information table.
		smt_TmpMemTbl[ulTblIdx].bWrtFlag = 0;
		smt_TmpMemTbl[ulTblIdx].ulZone   = 0;
		smt_TmpMemTbl[ulTblIdx].ulPhyBlk = 0;
		smt_TmpMemTbl[ulTblIdx].ulPhySct = 0;
		smt_TmpMemTbl[ulTblIdx].ulSctNum = 0;
		smt_TmpMemTbl[ulTblIdx].ulWrtSize = 0;
	}

	//--------------------//
	// Device ID is read. //
	//--------------------//
	bMaker = bDevice = 0x00;
	smtIdRead(&bMaker, &bDevice);
	if((bMaker == 0x00)||(bDevice == 0x00)){
		return(-1);					// Device ID reading error.
	}

	//-------------------------------//
	// The device model is searched. //
	//-------------------------------//
	for(uiModel = 0; uiModel < SMT_C_MODEL; uiModel++){
		if(smt_stDevInf[uiModel].bDevice == bDevice){
			break;
		}
	}
	if(uiModel < SMT_C_MODEL){
		smt_TmpDevIdx = uiModel;
	}
	else{
		return(-1);					// Device which isn't being supported.
	}

	return(0);
}


/************************************************************************
 *  smtTmpGetMaxSize
 *      Type     : unsigned long
 *      Ret val  : Number of free sector
 *      Argument : None
 *      Function : This function acquires the maximum capacity of free
 *                 sector which can be used.
 ************************************************************************/
unsigned long	smtTmpGetMaxSize(void)
{
	unsigned int	uiLoop;					// Loop counter.
	unsigned long	ulResult;				// Result.
	unsigned long	ulZone;					// Zone address.
	unsigned long	ulPhyBlk;				// Physics block address.
	unsigned long	ulPhySct;				// Physics sector address.
	unsigned long	ulLogBlk;				// Logic block address.
	unsigned long	ulPage;					// Page address.
	unsigned long	ulStartSct;				// Start sector address.
	unsigned long	ulSctCnt;				// Sector counter.

	//-------------------------------------------------------//
	// The initialization of the free territory information. //
	//-------------------------------------------------------//
	smt_TmpMemTbl[0].bUseFlag = 0;				// Resetting of temporary information table.
	smt_TmpMemTbl[0].bWrtFlag = 0;
	smt_TmpMemTbl[0].ulZone   = 0;
	smt_TmpMemTbl[0].ulPhyBlk = 0;
	smt_TmpMemTbl[0].ulPhySct = 0;
	smt_TmpMemTbl[0].ulSctNum = 0;
	smt_TmpMemTbl[0].ulWrtSize = 0;

	//-------------------------------------------------------------//
	// The whole territory is checked, and the size of the maximum //
	// free territory is acquired.                                 //
	//-------------------------------------------------------------//
	for(ulLogBlk = smt_stDevInf[smt_TmpDevIdx].ulStartSct / smt_stDevInf[smt_TmpDevIdx].ulBlkSize;
	ulLogBlk < smt_stDevInf[smt_TmpDevIdx].ulNumBlk; ulLogBlk++){
		ulZone   = ulLogBlk / SMT_C_ZONE;
		ulPhyBlk = ulLogBlk % SMT_C_ZONE;
		ulStartSct = 0;
		ulSctCnt = 0;
		for(ulPhySct = 0; ulPhySct < smt_stDevInf[smt_TmpDevIdx].ulBlkSize; ulPhySct++){
			ulPage = smtChgPgNum(ulZone, ulPhyBlk, ulPhySct);
			if(smtPageRead(SMT_C_DREAD_1, 0x00, ulPage, smt_TmpBuff) == SMT_E_FAILURE){
				return(0);		// Sector reading error.
			}

			// The condition of the block is checked.
			if(smtChkBadBlk(smtProlBuff.stDatBuff.bBlkSts) == SMT_E_FAILURE){
				break;			// Bad block.
			}

			// The contents of the data are checked.
			for(uiLoop = 0; uiLoop < smt_stDevInf[smt_TmpDevIdx].ulSctSize; uiLoop++){
				if(smt_TmpBuff[uiLoop] != 0xFF){
					break;		// Secotr use.
				}
			}
			if(uiLoop >= smt_stDevInf[smt_TmpDevIdx].ulSctSize){
				if(!ulPhySct){
					break;		// Block un-use.
				}
				if(!ulStartSct){
					ulStartSct = ulPhySct;
				}
				ulSctCnt++;		// Free sector is counted
			}
		}
		// The renewal of the maximum free territory.
		if(smt_TmpMemTbl[0].ulSctNum < ulSctCnt){
			smt_TmpMemTbl[0].bUseFlag = 1;
			smt_TmpMemTbl[0].bWrtFlag = 0;
			smt_TmpMemTbl[0].ulZone   = ulZone;
			smt_TmpMemTbl[0].ulPhyBlk = ulPhyBlk;
			smt_TmpMemTbl[0].ulPhySct = ulStartSct;
			smt_TmpMemTbl[0].ulSctNum = ulSctCnt;
			smt_TmpMemTbl[0].ulWrtSize = 0;
		}
	}
	if(smt_TmpMemTbl[0].bUseFlag){
		ulResult = smt_TmpMemTbl[0].ulSctNum
			 * smt_stDevInf[smt_TmpDevIdx].ulSctSize
			 - (sizeof(SMT_C_DISCOD) - 1);
	}
	else{
		ulResult = 0;
	}

	return(ulResult);
}


/************************************************************************
 *  smtTmpGetSector
 *      Type     : unsigned long
 *      Ret val  : Sector ID
 *      Argument : unsigned long ulSize ... The size of a free territory
 *                                          to acquire.
 *      Function : This function acquires the free territory of the
 *                 specified size.
 ************************************************************************/
unsigned long	smtTmpGetSector(unsigned long ulSize)
{
	unsigned long	ulTblIdx;				// Table index.
	unsigned int	uiLoop;					// Loop counter.
	unsigned long	ulZone;					// Zone address.
	unsigned long	ulPhyBlk;				// Physics block address.
	unsigned long	ulPhySct;				// Physics sector address.
	unsigned long	ulLogBlk;				// Logic block address.
	unsigned long	ulPage;					// Page address.
	unsigned long	ulStartSct;				// Start sector address.
	unsigned long	ulSctCnt;				// Sector counter.

	//-------------------------------------------------------------//
	// The search of the territory where a table hasn't been used. //
	//-------------------------------------------------------------//
	for(ulTblIdx = 1; ulTblIdx < SMT_C_TMPNUM; ulTblIdx++){
		if(!smt_TmpMemTbl[ulTblIdx].bUseFlag){
			break;
		}
	}
	if(ulTblIdx >= SMT_C_TMPNUM){
		return(0);					// There is no table which hasn't been used.
	}
	if(ulSize < (sizeof(SMT_C_DISCOD) + 1)){
		return(0);
	}

	//-----------------------------------------------------------//
	// The bigger territory than the specified size is acquired. //
	//-----------------------------------------------------------//
	for(ulLogBlk = smt_stDevInf[smt_TmpDevIdx].ulStartSct / smt_stDevInf[smt_TmpDevIdx].ulBlkSize;
	ulLogBlk < smt_stDevInf[smt_TmpDevIdx].ulNumBlk; ulLogBlk++){
		ulZone   = ulLogBlk / SMT_C_ZONE;
		ulPhyBlk = ulLogBlk % SMT_C_ZONE;
		ulStartSct = 0;
		ulSctCnt = 0;
		for(ulPhySct = 0; ulPhySct < smt_stDevInf[smt_TmpDevIdx].ulBlkSize; ulPhySct++){
			ulPage = smtChgPgNum(ulZone, ulPhyBlk, ulPhySct);
			if(smtPageRead(SMT_C_DREAD_1, 0x00, ulPage, smt_TmpBuff) == SMT_E_FAILURE){
				return(0);			// Sector reading error.
			}

			// The condition of the block is checked.
			if(smtChkBadBlk(smtProlBuff.stDatBuff.bBlkSts) == SMT_E_FAILURE){
				break;				// Bad block.
			}

			// The contents of the data are checked.
			for(uiLoop = 0; uiLoop < smt_stDevInf[smt_TmpDevIdx].ulSctSize; uiLoop++){
				if(smt_TmpBuff[uiLoop] != 0xFF){
					break;			// Secotr use.
				}
			}
			if(uiLoop >= smt_stDevInf[smt_TmpDevIdx].ulSctSize){
				if(!ulPhySct){
					break;			// Block un-use.
				}
				if(!ulStartSct){
					ulStartSct = ulPhySct;
				}
				ulSctCnt++;			// Free sector is counted
			}
		}
		// The renewal of the maximum free territory.

⌨️ 快捷键说明

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