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

📄 zata.h

📁 &#8226 控制器(CPU): Atmel AT90S8515 AVR &#8226 MP3解码器: STA013 &#8226 音频 DAC: CS4334 &#8226 IDE 接口
💻 H
字号:
/*
    Copyright 2003 Nasif Akand (nasif@yifan.net)
    http://go.to/zipamp
    http://zipamp.virtualave.net

    This file is part of ZipAmp MP3 software.

    ZipAmp 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.

    ZipAmp 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 code; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/


//This module is the hardware interface to the ATA drives.



#ifndef __ZATA_H__
#define __ZATA_H__


#define TRUE     1 
#define FALSE    0 
#define CTRL     0
#define CMD      1
#define DRIVE0   0


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

//ATA Register address, this is : 		/CS1 	/CS0 	A2 	A1 	A0 (5 bits, treated as byte)

#define	IOReg		0x10		//	1	0	0	0	0  (used for 16 bit data transfer)
#define ErrorReg        0x11		//	1	0	0	0	1  (Has the error info)
#define SecCountReg	0x12		//	1	0	0	1	0  (# of sector to transfer, always 1 for our case)
#define	SecReg		0x13		//	1	0	0	1	1  (Sector that has to be read)
#define LoCylReg	0x14		//	1	0	1	0	0  (Holds the low byte of cylinder #)
#define HiCylReg	0x15		//	1	0	1	0	1  (Only bit 1 and 0 is significat. 
										  //Cylinder # is 10 bits long)
#define	DrvHeadReg	0x16		//	1	0	1	1	0  (Holds head and drive to be read from)										  
#define CmdStsReg	0x17		//	1	0	1	1	1  (Command and Status Register)
#define Interrupt	0x0E		//	0	1	1	1	0


// ATA status register bits

#define SR_BSY		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
#define Drive		0
#define LBAMaster	0xE0
#define LBASlave	0xF0
#define ClusterBufSize	0x08

typedef struct store { 
 unsigned char data[256]; 
} bufferType; //256 bytes, 128 words

typedef struct buf { 
 dword cluster [ClusterBufSize]; 
} clusterBufferType; //64bytes, 32words, can store 16 FAT16/FAT32 address


//Global variables

bufferType	sectorBuffer;    //This buffer will have sector data after hard drive read.
clusterBufferType clusterBuffer; //clusterBuffer is used to read ahead FAT table

//unsigned char 	error=0;        //Error variable, not used much. When not 0, there was error reading drive

unsigned int	readPos=0; 	//holds the value of read offset of one sector
 				//it is reset to 0 when reaches 512 (end of 1 sector)
 				//this is the byte # that will be read next.         
 				
unsigned char	sectorPos=0;	//# of sectors read for a file, reset to 0 when reaches max cluster size


//Function definition

unsigned char ReadUpper8(); 			 	//Reads ATA Upper byte (D8..D15) through 74244 buffer.
void WriteAddr(unsigned char address);			//write ATA register address through 74373 Latch
void RegWrite(unsigned char reg, unsigned char data); 	//Write data value to ATA register
unsigned char RegRead(unsigned char reg); 		//Read data from ATA register
                   
void WaitTillNotBusy(); 	//loops until drive is ready for command
void ATA_Init(); 		//Initialize IDE drive at startup.
void UnBusy(); 			//Clear the busy LED

//Read wordsToRead number of word from the LBA address  (max 32words can be read)
void ATA_Read_Sectors_LBA(unsigned long lba, unsigned int wordsToRead); 
				  
void ATA_Move_Head(unsigned long lba); 		//Move hard drive head to the give lba address sector
void ATA_Read(unsigned int wordsToRead); 	//Read from current sector
void ATA_WriteSector(dword lba); 		//Writes to Drive only 128 byte

				  	
#endif

⌨️ 快捷键说明

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