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

📄 ata_if.h

📁 Yet Another MP3 Player source code. It can be usefull as reference source for any project.
💻 H
字号:
/*
  Copyright (C) 2001 Jesper Hansen <jesperh@telia.com>.

  Rewritten by:	Nikolai Vorontsov <nickviz@mail.be>

  This file is part of the yampp system.

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation, 
  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef __ATA_IF_H__
#define __ATA_IF_H__

#include "types.h"
#include "Constants.h"


//----------------------------------------------------------------------------
// Constants...
//----------------------------------------------------------------------------

#define TRUE     1 
#define FALSE    0 
#define CTRL     0
#define CMD      1
#define CTRL_A	 0x08
#define CMD_A	 0x10
#define DRIVE0   0


#define STANDBY	0
#define SLEEP	1
#define IDLE	2


// ATA status register bits
#define SR_BUSY		0x80
#define SR_DRDY		0x40
#define SR_DF		0x20
#define SR_DSC		0x10
#define SR_DRQ		0x08
#define SR_CORR		0x04
#define SR_IDX		0x02
#define SR_ERR		0x01

// ATA error register bits
#define ER_UNC		0x40
#define ER_MC		0x20
#define ER_IDNF		0x10
#define ER_MCR		0x08
#define ER_ABRT		0x04
#define ER_TK0NF	0x02
#define ER_AMNF		0x01

// ATA control register bits
#define CT_SRST			0x04
#define CT_nIEN			0x02

// ATA dev/head register bits
#define DH_CHS0			0xA0
#define DH_CHS1			0xB0
#define DH_LBA0			0xE0
#define DH_LBA1			0xF0

// ATA registers

// Command registers
#define CMD_DATA		0x00
#define CMD_ERROR		0x01
#define CMD_FEATURES	0x01
#define CMD_SECT_CNT	0x02
#define CMD_SECT_NUM	0x03
#define CMD_CYL_LOW		0x04
#define CMD_CYL_HIGH	0x05
#define CMD_DEV_HEAD	0x06
#define CMD_STATUS		0x07
#define CMD_COMMAND		0x07

// Control registers
#define CTRL_ALT_STAT	0x06
#define CTRL_DEV_CTRL	0x06


// ATA commands
#define ATA_READ_SECTS	0x20
#define ATA_IDENTIFY	0xEC

//----------------------------------------------------------------------------
// Prototypes
//----------------------------------------------------------------------------
void ATA_Init(void);
void ATA_SW_Reset(void);
u08  ATA_ReadCHS0(u08 Head, u16 Track, u08 Sector, u08 NumSectors, u08 *Buffer);
u08  ATA_ReadLBA0(u32 LBA, u08 NumSectors, u08 *Buffer);

#ifdef DEBUG_ATA
void DiskStat(void);
u08 IdentifyDrive0(u08 *Buffer);
#else
#define DiskStat()
#define IdentifyDrive0(Buffer) 1
#endif

// Bytes per sector
#define BPS 512

#ifdef ENABLE_CRC
extern u16 crcs[];
u16 CalculateCRC(u08* buf, u16 size);
#endif // ENABLE_CRC

#endif // __ATA_IF_H__

⌨️ 快捷键说明

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