本人是初学者,买了个开发板,有关于ATA访问的函数,以下是头文件,向高手请教基本读写IDE硬盘方法。
/*ATA register*/
#define DM642_ATA_AS (DM642_ATACS1 + 0x18) //read only
#define DM642_ATA_DEVCON (DM642_ATACS1 + 0x18) //write only
#define DM642_ATA_DATA (DM642_ATACS0 + 0x0) //write and read
#define DM642_ATA_ERROR (DM642_ATACS0 + 0x4) //read only
#define DM642_ATA_FEATURES (DM642_ATACS0 + 0x4) //write only
#define DM642_ATA_SECTOR (DM642_ATACS0 + 0x8) //write and read
#define DM642_ATA_LBAL (DM642_ATACS0 + 0xc)//write and read
#define DM642_ATA_LBAM (DM642_ATACS0 + 0x10) //write and read
#define DM642_ATA_LBAH (DM642_ATACS0 + 0x14)//write and read
#define DM642_ATA_DEVICE (DM642_ATACS0 + 0x18) //write and read
#define DM642_ATA_COM (DM642_ATACS0 + 0x1c) //write only
#define DM642_ATA_STATUS (DM642_ATACS0 + 0x1c) //read only
/*the bus status*/
#define ATA_BUS_BSY 0x80
#define ATA_BUS_DRDY 0x40
#define ATA_BUS_DF 0x20
#define ATA_BUS_DRQ 0x08
#define ATA_BUS_ERR 0x01
/*ata command*/
#define IDENTIFY_DEVICE 0xEC
#define READ_SECTOR(S) 0x20
#define WRITE_SECTOR(S) 0x30
/*ATA command,if a regiset is not used during command ,set the rigiter
value :0x100*/
typedef struct {
Uint32 features;
Uint32 sector_count;
Uint32 LBA_l;
Uint32 LBA_M;
Uint32 LBA_H;
Uint32 device;
Uint32 com_code;
int prereq;
int complete_flag;
} ATA_command;
/* ATA Handle */
typedef int DM642_ATAHandle;
/*******************************************************************/
/* */
/* int ata_status() */
/* 描述:读回当前硬盘的状态 */
/* 参数:无 */
/* 返值:当前状态寄存器的值 */
/* */
/*******************************************************************/
int ata_status();
/*******************************************************************/
/* */
/* DM642_ATAHandle ata_open() */
/* 描述:打开有效的硬盘设备 */
/* 参数:无 */
/* 返值:有效设备的句柄 */
/* */
/*******************************************************************/
DM642_ATAHandle ata_open();
/*******************************************************************/
/* */
/* int ata_command() */
/* 描述:设置当前寄存器 */
/* 参数:regaddr:寄存器地址 */
/* regdata:寄存器的值 */
/* 返值:无 */
/* */
/*******************************************************************/
Bool ata_command(ATA_command *command,Uint32 buffer,Uint32 longth);
/*******************************************************************/
/* */
/* int ata_reg_write() */
/* 描述:设置当前寄存器 */
/* 参数:regaddr:寄存器地址 */
/* regdata:寄存器的值 */
/* 返值:无 */
/* */
/*******************************************************************/
void ata_reg_write(Uint32 regaddr,Uint32 regdata);
/*******************************************************************/
/* */
/* int ata_reg_read() */
/* 描述:读回当前寄存器的状态 */
/* 参数:寄存器指示 */
/* 返值:当前状态寄存器的值 */
/* */
/*******************************************************************/
int ata_reg_read(Uint32 regaddr);