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

📄 ide_base.h

📁 在Bf533上实现FAT32文件系统
💻 H
字号:
#include "type.h"
#ifndef IDE
#define IDE

//IDE Register Address
#define IDECS0BASEADDR		0x20340000

#define pDataPort 		(volatile unsigned short *)(IDECS0BASEADDR +(0x00<<1))
#define pPreComp 		(volatile unsigned char *)(IDECS0BASEADDR + (0x01<<1))
#define pSectorCount		(volatile unsigned char *)(IDECS0BASEADDR + (0x02<<1))
#define pSectorNumber	(volatile unsigned char *)(IDECS0BASEADDR + (0x03<<1))
#define pCylinderLow		(volatile unsigned char *)(IDECS0BASEADDR + (0x04<<1))
#define pCylinderHigh		(volatile unsigned char *)(IDECS0BASEADDR + (0x05<<1))
#define pDriveHead		(volatile unsigned char *)(IDECS0BASEADDR + (0x06<<1))
#define pCommand 		(volatile unsigned char *)(IDECS0BASEADDR + (0x07<<1))

#define pStatus			(volatile unsigned char *)(IDECS0BASEADDR + (0x07<<1))
#define pErrorReg 		(volatile unsigned char *)(IDECS0BASEADDR + (0x01<<1))

//IDE Status Register Bit
#define IDE_BUSY 	0x80		//HD busy flag
#define IDE_DRDY 	0x40		//HD ready flag
#define IDE_DWF  	0x20		//Write error
#define IDE_DSC		0x10		//search done flag
#define IDE_DRQ		0x08		//data request query
#define IDE_CORR	0x04		//data correct
#define IDE_INDEX	0x02		
#define IDE_ERROR	0x01

//IDE Command 
#define IDE_CMD_CHECKPOWERMODE 	0x98 	// Check Power Mode      
#define IDE_CMD_CHECKPOWERMODE2 0xE5 	//Check Power Mode (same as 98h) 
#define IDE_CMD_DRIVEDIAG 	0x90     // Execute Drive Diagnostic        |             D+  |
#define IDE_CMD_FORMAT		0x50   	// Format Track                    |          V  V   |
#define	IDE_CMD_IDENTIFY	0xEC	// Identify Drive                  |             D   |
#define IDE_CMD_IDLE		0x97	//Idle                            |    V        D   |
#define IDE_CMD_IDLE2		0xE3	//Idle (same as 97h)              |    V        D   |
#define IDE_CMD_IDLEIMMEDIATE	0x95	//Idle Immediate                  |             D   |
#define IDE_CMD_IDLEIMMEDIATE2	0xE1	//Idle Immadiate (same as 95h)    |             D   |
#define IDE_CMD_INITDRIVERPARAM	0x91	//Initialize Drive Parameters     |    V        V   |
#define IDE_CMD_READBUFFER	0xE4	//Read Buffer                     |             D   |
#define IDE_CMD_READDMARETRY	0xC8	//Read DMA With Retry             |  >> Unknown <<  |
#define IDE_CMD_READDMA		0xC9	//Read DMA                        |  >> Unknown <<  |
#define IDE_CMD_READMILTI	0xC4	//Read Multiple                   |    V  V  V  V   |
#define IDE_CMD_READSECTORRETRY	0x20	//Read Sectors With Retry         |    V  V  V  V   |
#define IDE_CMD_READSECTOR	0x21	//Read Sectors                    |    V  V  V  V   |
#define IDE_CMD_READLONGRETRY	0x22	//Read Long With Retry            |    V  V  V  V   |
#define IDE_CMD_READLONG	0x23	//Read Long                       |    V  V  V  V   |
#define IDE_CMD_READVERSECRETRY	0x40	//Read Verify Sectors With Retry  |    V  V  V  V   |
#define IDE_CMD_READVERSEC	0x41	//Read Verify Sectors             |    V  V  V  V   |
//#define IDE_CMD_RECALIBRATE	0x1X	//Recalibrate                     |             D   |
//#define IDE_CMD_SEEK		0x7X	//Seek                            |          V  V   |
#define IDE_CMD_SETFEATURES	0xEF	//Set Features                    |  V          D   |
#define IDE_CMD_SETMULTIMODE	0xC6	//Set Multiple Mode               |    V        D   |
#define IDE_CMD_SETSLEEPMODE	0x99	//Set Sleep Mode                  |             D   |
#define IDE_CMD_SETSLEEPMODE2	0xE6	//Set Sleep Mode (same as 99h)    |             D   |
#define IDE_CMD_STANDY		0x96	//Standby                         |    V        D   |
#define IDE_CMD_STANDY2		0xE2	//Standby (same as 96h)           |    V        D   |
#define IDE_CMD_STANDYIMMEDIATE	0x94	//Standby Immediate               |             D   |
#define IDE_CMD_STANDYIMMEDIATE2 0xE0	//Standby Immediate (same as 94h) |             D  

//IDE Driver Function
extern void IdeStandby(void);
extern void IdeIdle(void);
extern unsigned char IdeReadSector(unsigned char SectorNum,unsigned short CylinderNum,unsigned char DriverHead);
extern unsigned char IdeWriteSector(unsigned char SectorNum,unsigned short CylinderNum,unsigned char DriverHead);
extern BYTE	Wait_Ready(void);
extern BYTE	Wait_ReadyBusy(void);
extern BYTE	Wait_DRQ(void);
extern BYTE	CheckforError(void);

//IDE Statics
#define SECTORBYTESIZE 512
#define SECTORWORDSIZE 256

//IDE Variable
typedef union {
	unsigned char u8data[512];
	unsigned short u16data[256];
	unsigned long u32data[128];
}BUFFER;

typedef struct
{
 	BUFFER currentsector;
	DWORD SectorCurrentlyLoaded; 
} IDE_BUFFER;
extern IDE_BUFFER buffers;

typedef struct
{
	WORD	cylinder_num;
	WORD 	head_num;
	WORD	one_cylinder_byte;
	WORD	one_sector_byte;
	WORD	one_cylinder_sector;
	char	serialnum[21];
	char 	modelnum[41];
	DWORD	maxLBA;	   
} IDE_DRIVER;
extern IDE_DRIVER IDE_current;

#else
#endif




⌨️ 快捷键说明

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