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

📄 dochtl.c

📁 电子盘DEMO板程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************/
/*                                                                            */
/*  Copyright (C), 1995-2006, msystems Ltd. All rights reserved.              */
/*                                                                            */
/*  Redistribution and use in source and binary forms, with or without        */
/*  modification, are permitted provided that the following conditions are    */
/*  met:                                                                      */
/*  1. Redistributions of source code must retain the above copyright notice, */
/*     this list of conditions and the following disclaimer.                  */
/*  2. Redistributions in binary form must reproduce the above copyright      */
/*     notice, this list of conditions and the following disclaimer in the    */
/*     documentation and/or other materials provided with the distribution.   */
/*  3. Neither the name of msystems nor the names of its contributors may be  */
/*     used to endorse or promote products derived from this software without */
/*     specific prior written permission.                                     */
/*                                                                            */
/*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/*  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR             */
/*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      */
/*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     */
/*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED  */
/*  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR    */
/*  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    */
/*  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      */
/*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        */
/*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
/*                                                                            */
/******************************************************************************/
/*
 * $Log:   V:/PVCSDB/DiskOnChip/archives/Test for 7.x/src/H3/dochtl.c-arc  $
 * 
 *    Rev 1.23   Sep 11 2006 13:45:16   yaniv.iarovici
 * Legal header added
 * 
 *    Rev 1.22   Sep 10 2006 10:03:42   Yaniv.Iarovici
 * Fix compilation warning: Initialize tlRecTable[] and tlTable[] upon first entry to dochMountTL().
 * 
 *    Rev 1.21   Aug 24 2006 11:39:46   Yaniv.Iarovici
 * Change error returned by dochMountTL() in case DOCHPartitionInfo() failed to:
 * 	- flHWProtection if the operation failed due to protection error
 * 	- flGeneralFailure otherwise
 * 
 *    Rev 1.20   Aug 17 2006 15:20:36   Yaniv.Iarovici
 * Zerioze partition info structure.
 * 
 *    Rev 1.18   Aug 09 2006 17:26:56   Polina.Marimont
 * initial for DOC Driver 1.0
 * 
 */

#include "dochtl.h"
#include "doch_ata.h"
#include "doch_func.h"

#ifdef FL_MIGRATION_VERSION
#include "tffs_api.h"
#endif /*FL_MIGRATION_VERSION*/

static DocTLRec		tlRecTable[DOCH_MAX_PARTITIONS];
static TL			tlTable[DOCH_MAX_PARTITIONS];


extern FLDword gIsDMAEnabled;				/*DMA is Enabled/Disabled*/

#ifdef CHECK_POWER_ON_EVERY_COMMAND
extern FLBoolean gDeviceTurnedOff;
#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#ifndef FL_MIGRATION_VERSION
bdCallType bdCall = bdCallSureFS;
#endif /*FL_MIGRATION_VERSION*/

static FLStatus dochMapSector(TLrec * tlRec, SectorNo sectorNo, void * *retBuffer)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = 1;
	ioreq.irData = tlRec->mappedSector;

	rc = flDOCHReadPartitionSectors(&ioreq);

	*retBuffer = tlRec->mappedSector;

	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochWriteSector(TLrec *tlRec, SectorNo sectorNo, void FAR1 *fromAddress)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = 1;
	ioreq.irData = fromAddress;

	rc = flDOCHWritePartitionSectors(&ioreq);

	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		if( (rc == DOCH_ATA_ERROR_TRACK_0_NOT_FOUND) || (rc == DOCH_ProtectionFault))
			return flHWProtection;

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochWriteMultiSector(TLrec *tlRec, SectorNo sectorNo, void FAR1 *fromAddress,SectorNo sectorCount)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = sectorCount;
	ioreq.irData = fromAddress;

#ifdef FL_MIGRATION_VERSION
	#ifdef FL_USE_DMA_ON_WRITE
#endif /*FL_MIGRATION_VERSION*/

#ifdef DOCH_DMA_CONFIG
	/*Check if to enable DMA*/
	if((((FLDword)fromAddress & 0x3) == 0) && (gIsDMAEnabled == DOCH_GLOBAL_BOOL_PATTERN))
		ioreq.irFlags |= DOCH_USE_DMA;
#endif /*DOCH_DMA_CONFIG*/

#ifdef FL_MIGRATION_VERSION
	#endif /*FL_USE_DMA_ON_WRITE*/
#endif /*FL_MIGRATION_VERSION*/

#ifdef DOCH_USE_BURST_MODE_WRITE
    ioreq.irFlags |= DOCH_USE_BURST;
#endif /*DOCH_USE_BURST_MODE_WRITE*/

	rc = flDOCHWritePartitionSectors(&ioreq);

	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochReadSectors(TLrec *tlRec, SectorNo sectorNo, void FAR1 *dest,SectorNo sectorCount)
{
	DOCH_Error rc;
	IOreq ioreq;
	DOCH_Socket* pdev;
	DOCH_get_socket(pdev, tlRec->socketNo);

	/*If socket is not registered, return error*/
	if(pdev == NULL)
		return flAdapterNotFound;

	tffsset(&ioreq, 0, sizeof(ioreq));

	pdev->bAtaDevNum = 0;
	DOCH_SET_SOCKET_TO_IOREQ_HANDLE(&ioreq, tlRec->socketNo);
	DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&ioreq, tlRec->partitionNo);
	ioreq.irSectorNo = sectorNo;
	ioreq.irSectorCount = sectorCount;
	ioreq.irData = dest;

#ifdef DOCH_DMA_CONFIG
	/*Check if to enable DMA*/
	if((((FLDword)dest & 0x3) == 0) && (gIsDMAEnabled == DOCH_GLOBAL_BOOL_PATTERN))
	{
		ioreq.irFlags |= DOCH_USE_DMA;
#ifdef DOCH_USE_BURST_MODE_READ
		ioreq.irFlags |= DOCH_USE_BURST;
#endif /*DOCH_USE_BURST_MODE_READ*/
	}
#endif /*DOCH_DMA_CONFIG*/

	rc = flDOCHReadPartitionSectors(&ioreq);
	if(rc != DOCH_OK)
	{
		#ifdef CHECK_POWER_ON_EVERY_COMMAND
		/*In case Power Fail was detected, return DOCH_DeviceTurnedOff*/
		if(gDeviceTurnedOff)
		{
			gDeviceTurnedOff = FALSE;

#ifdef FL_MIGRATION_VERSION
			return flSuspendModeDetected;    
#else /*FL_MIGRATION_VERSION*/
			return DOCH_DeviceTurnedOff;    
#endif /*FL_MIGRATION_VERSION*/
		}
		#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

		return flBadFunction;
	}
	else
		return flOK;
}

static FLStatus dochDeleteSector(TLrec *tlRec, SectorNo sectorNo, SectorNo noOfSectors)
{
	DOCH_Error rc;
	IOreq ioreq;

⌨️ 快捷键说明

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