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

📄 def_ide.h

📁 小型操作系统,以VC为开发环境,需要boachs调试
💻 H
字号:
/***************************************************************************
**     File name   : def_ide.h
**     Author      : x.cheng
**     Create date :
**
**	   Comment:
**        ide驱动头文件 - local...
**
**     Revisions:
**     $Log: def_ide.h,v $
**     Revision 1.3  2005/08/09 16:13:38  x.cheng
**     new function prototype
**
**     Revision 1.2  2005/07/27 15:58:49  x.cheng
**     ide device system bufferblock structure
**     ide request structure
**     ide device structure
**     function prototype....
**
**     Revision 1.1.1.1  2005/07/27 06:53:15  x.cheng
**     add into repositories
**
**
***************************************************************************/
#ifndef __DEF_IDE_H__
#define __DEF_IDE_H__

#include "..\..\inc\task.h"
#include "..\..\inc\i386\interrupt.h"

#include ".\def_ata.h"
#include ".\def_hd.h"

/*****************IDE设备的系统读写缓冲结构**************/
#define BUFFER_BLOCK_SIZE		2048
#define BUFFER_BLOCK_SIZE_BITS  11
#define NR_HASH			307

typedef struct BufferBlock_Struct {
	unsigned char *pucBlock;        /* pointer to data block (1024 bytes) */
	unsigned long ulBlockNr;		// block number
	unsigned short uiDevice;		// device (0 = free)
	unsigned char ucUpToDate;		// it it 最新的?
	unsigned char ucDirty;			// 0-clean, 1-dirty
	unsigned char ucRefers;			// reference to this block
	unsigned char ucLocked;			// 0 - ok, 1 - locked 
	ts_Task *pstWaitTask;			//指向等待缓冲区解锁的任务
	struct BufferBlock_Struct *pstPrev;
	struct BufferBlock_Struct *pstNext;
	struct BufferBlock_Struct *pstPrevFree;
	struct BufferBlock_Struct *pstNextFree;
}ts_BufferBlock;

/****************读写IDE设备请求的结构********************/
#define MAX_REQUEST_NR	32
	//---------------ide command--------------
#define IDE_READ_BLK	0
#define IDE_WRITE_BLK	1
	// Max read/write errors/sector
#define MAX_ERRORS	7

typedef struct Ide_Request_Struct{
	int iDevice;						/* -1 if no request */
//	unsigned char ucRtc;				/* 0 wait sucess, 1 request ok */
	unsigned char ucCmd;				/*一次请求的命令类型*/
	unsigned char ucError;				/*返回的错误*/
	unsigned long ulNumOfSectors;		/*读写的总扇区数*/
	unsigned long ulStartOfSector;		/*起始扇区*/
//	unsigned char ucHead;
//	unsigned short uiCylinder;
	ts_Task* pstWaitTask;
	unsigned char* pucBuffer;			/*数据地址 */
	ts_BufferBlock* pstBlock;
	struct Ide_Request_Struct *pstNext;	/*下一个读写请求, 目前最多32个*/
}ts_IdeRequest;

//----------------------------------------------------------------
// This is used in the elevator algorithm: Note that
// reads always go before writes. This is natural: reads
// are much more time-critical than writes.
#define ELEVATOR_IN_ORDER(pstReq1,pstReq2) \
		((pstReq1)->ucCmd<(pstReq2)->ucCmd || (pstReq1)->ucCmd==(pstReq2)->ucCmd && \
		((pstReq1)->iDevice < (pstReq2)->iDevice || ((pstReq1)->iDevice == (pstReq2)->iDevice && \
		(pstReq1)->ulStartOfSector < (pstReq2)->ulStartOfSector)))

/**************IDE设备的请求管理结构*******************/
#define IDE_DEVICE_NR	5
#define IDE_DEVICE_FD	1
#define IDE_DEVICE_HD	2
#define IDE_DEVICE_CD	3
#define IDE_DEVICE_PR	4
typedef struct Ide_Device_Struct{
	void (*fpRequestFct) (void);
	ts_IdeRequest* pstCurrentRequest;
}ts_IdeDevice;

/******************************************************
 * function prototype...
 ******************************************************/
#define DELAY400NS()	\
	do {	\
		ucInPortDelay( ATA_PRIMARY_ALTERNATE_STATUS );	\
		ucInPortDelay( ATA_PRIMARY_ALTERNATE_STATUS );	\
		ucInPortDelay( ATA_PRIMARY_ALTERNATE_STATUS );	\
		ucInPortDelay( ATA_PRIMARY_ALTERNATE_STATUS );	\
	} while(0)

	//-------------in file id1_buffer.c-------------------

void Id1BufferInitialize(void);

ts_BufferBlock* pstId1BufferRead(int iDevice, int iBlock);

void Id1BufferRelease( ts_BufferBlock* pstBlock);

ts_BufferBlock* pstId1GetBlock(int iDevice, int iBlock);

ts_BufferBlock* pstId1GetHashTable(int iDevice, int iBlock);

int iId1SyncDeviceBuffer(int iDevice);

	//-------------in file id2_hd.c--------------------
void vDoHdRequest(void);
int iId2ReadHdData(ts_IdeRequest* pstRequest);
void Id2HardDiskSetup(void);

#define CURRENT_PARTITION	0
#define DEFAULT_PARTITION	0
ts_PartitionInfo* pstId2GetPartitonInfo( unsigned char ucPartition);
unsigned long ulId2GetPartitonStartSector(unsigned char ucPartition);
void Id2SetCurrentPartiton(unsigned char ucPartiton);

	//-------------in file id3_cd.c--------------------
void DoCdRequest(void);
int iId3ReadCdData(ts_IdeRequest* pstRequest);

void Id3CdromSetup(void);


	//-------------in fil id5_util.c-------------------
#define TIMEOUT		50
int iId5WaitIdeStatus( int iChannel, int iMask, int iVal);
int iId5ControllerReady(int iChannel );
#define DEVICE_1	0x10	//00010000
#define DEVICE_0	0x00	//00000000
unsigned char ucId5InterruptDevice(int iChannel );
unsigned char ucId5CmdResult(int iChannel);
unsigned char ucId5DeviceStatus(int iChannel);
unsigned char ucId5SendCommand(unsigned char ucCmd, unsigned char* pucBuffer);

	//-------------in file ide.c-----------------------
void IdeInitialize(void);

//void vDoIdePriIRQ(void);
void vDoIdePriIRQ(ts_IrqContext *pstContext);
void DoIdeSecIRQ(ts_IrqContext *pstContext);

void IdeReadWriteBlock( int iCmd, ts_BufferBlock* pstBlock);

inline void IdeEndRequest(int iDevice, unsigned char ucUpToDate);

#endif /* end of  __DEF_IDE_H__ */

⌨️ 快捷键说明

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