?? harddisc.h
字號:
/*H**************************************************************************
* NAME: harddisk.h
*----------------------------------------------------------------------------
* Copyright (c) 2004 Toplow.
*----------------------------------------------------------------------------
* RELEASE:
* REVISION:
*----------------------------------------------------------------------------
* PURPOSE:
*
*
* NOTES:
* Global Variables:
* - gl_sbc_wr_protect: write protect flag for SCSI disk
*****************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h" /* system configuration */
#include <absacc.h>
#define FILE0 XBYTE[0x0880] //硬盤數據寄存器
#define FILE1 XBYTE[0x0881] //錯誤/特征寄存器
#define FILE2 XBYTE[0x0882] //扇區數寄存器
#define FILE3 XBYTE[0x0883] //扇區號寄存器
#define FILE4 XBYTE[0x0884] //柱面號寄存器L
#define FILE5 XBYTE[0x0885] //柱面號寄存器H
#define FILE6 XBYTE[0x0886] //驅動器/磁頭寄存器
#define FILE7 XBYTE[0x0887] //狀態/命令寄存器
///////////////////位設置///////////////////////////
sbit BSY=ACC^7;
sbit DRDY=ACC^6;
sbit DRQ=ACC^3;
sbit ERR=ACC^0;
/************************************************************
* D7 D6 D5 D4 D3 D2 D1 D0 *
BSY DRDY DWF DSC DRQ CORR IDX ERR *
BSY:驅動器忙; *
DRDY:驅動器準備好; *
DWF:驅動器寫失敗; *
DSC:尋道結束; *
DRQ:請求服務,驅動器希望通過數據寄存器與CPU交換一字節數據;*
CORR:當可以糾正的讀錯誤發生時,該位置1,數據傳輸將繼續進行 *
IDX:收到綜引信號; *
ERR:命令執行出錯。 *
*************************************************************/
sbit ARST=P5^3;
sbit INTQ=P5^1;
//uchar status; //從硬盤寄存器返回的狀態數據寄存器
uchar buffer0,buffer1; //硬盤16位數據
/*******************************************************
*函數名稱:void ReadReg(uchar address) *
*函數用途:讀硬盤非數據寄存器內容,并將結果返回 *
********************************************************/
/*void ReadReg(uchar address)
{
status=address;
ACC=status;
}
/*******************************************************
*函數名稱:void WriteReg(uchar address,uchar sdata) *
*函數用途:寫硬盤非數據寄存器內容 *
********************************************************/
/*void WriteReg(uchar address,uchar sdata)
{XBYTE[0x0881]=address;
}
/*******************************************************
*函數名稱:void ReadData() *
*函數用途:讀硬盤數據寄存器內容 *
********************************************************/
void ReadData()
{
buffer0=FILE0;
buffer1=DAT16H;
}
/*******************************************************
*函數名稱:void WriteData(uchar Data0,uchar Data1) *
*函數用途:寫硬盤數據寄存器內容 *
********************************************************/
/*void WriteData(uchar address,uchar data0,uchar data1)
{
DAT16H=data1;
address=data0;
}*/
/*********************************************************
*函數名稱:WriteLBA(Uint32 LBA) *
*函數用途:寫LBA信息(地址信息) *
**********************************************************/
WriteLBA(Uint32 LBA)
{uchar head,cylinderh,cylinderl,sector;
head=(uchar)(LBA>>24);
cylinderh=(uchar)((LBA&0x00ff0000)>>16);
cylinderl=(uchar)((LBA&0x0000ff00)>>8);
sector=(uchar)(LBA&0x000000ff);
do{ACC=FILE7;}while(BSY);
FILE6=(0xe0|(head&0x0f));
FILE5=cylinderh; //high 2-bit cylinder
FILE4=cylinderl;//low 8-bit cylinder
FILE3=sector; //start sector
FILE2=0x01; //sector counter
}
/*********************************************************
*函數名稱:WriteCHS(uint cylinder,uchar head,uchar sector)*
*函數用途:寫CHS信息(地址信息) *
**********************************************************/
WriteCHS(uchar head,uchar cylinderh,uchar cylinderl,uchar sector)
{do{ACC=FILE7;}while(BSY);
FILE6=(0xe0|(head&0x0f));
FILE5=cylinderh; //high 2-bit cylinder
FILE4=cylinderl;//low 8-bit cylinder
FILE3=sector; //start sector
FILE2=0x01; //sector counter
}
/*********************************************************
*函數名稱:WriteCommand(command) *
*函數用途:寫命令 *
**********************************************************/
WriteCommand(command)
{do{ACC=FILE7;}while(BSY);
FILE7=command;
}
/**********************************************************
*函數名稱:void DriveID(void) *
*用途:讀硬盤ID *
***********************************************************/
void DriveID(void)
{uint i=512;
do{ACC=FILE7;}while(BSY);
FILE7=0xec;
do{ACC=FILE7;}while(BSY|!DRQ);
while(i){ReadData();putch(buffer0);putch(buffer1);i-=2;}
}
/**********************************************************
*函數名稱:GetData() *
*用途:將硬盤的返回數據讀入BUFFER數組 *
***********************************************************/
void GetData()
{uint i=0;
do{ACC=FILE7;}while(BSY|!DRQ);
if(ERR){LcdWriteCH(0x90,MEG[0],MEG[1]);
LcdWriteCH(0x91,MEG[2],MEG[3]);
}
/* else {LcdWriteCH(0x90,MEG[4],MEG[5]);
LcdWriteCH(0x91,MEG[4],MEG[5]);
LcdWriteCH(0x94,INF[0],INF[1]);
LcdWriteCH(0x95,INF[2],INF[3]);
LcdWriteCH(0x96,INF[4],INF[5]);
}*/
while(i!=512){ReadData();
BUFFER[i++]=buffer0;
BUFFER[i++]=buffer1;
}
}
////////////////////////////////////////////////////////////
void GetTowSector(void)
{uint i=0;
do{ACC=FILE7;}while(BSY|!DRQ);
if(ERR){LcdWriteCH(0x90,MEG[0],MEG[1]);
LcdWriteCH(0x91,MEG[2],MEG[3]);
}
/* else {LcdWriteCH(0x90,MEG[4],MEG[5]);
LcdWriteCH(0x91,MEG[4],MEG[5]);
LcdWriteCH(0x94,INF[0],INF[1]);
LcdWriteCH(0x95,INF[2],INF[3]);
LcdWriteCH(0x96,INF[4],INF[5]);
}*/
while(i!=1024){ReadData();
BUFFER[i++]=buffer0;
BUFFER[i++]=buffer1;
}
}
/**********************************************************
*函數名稱:GetLBAData() *
*用途:將硬盤的返回數據讀入BUFFER數組 *
***********************************************************/
void GetLBAData(Uint32 LBA)
{uchar head,cylinderh,cylinderl,sector;
head=(uchar)(LBA>>24);
cylinderh=(uchar)((LBA&0x00ff0000)>>16);
cylinderl=(uchar)((LBA&0x0000ff00)>>8);
sector=(uchar)(LBA&0x000000ff);
do{ACC=FILE7;}while(BSY);
FILE6=(0xe0|(head&0x0f));
FILE5=cylinderh; //high 2-bit cylinder
FILE4=cylinderl;//low 8-bit cylinder
FILE3=sector; //start sector
FILE2=0x02; //sector counter
WriteCommand(0x20);
GetTowSector();
BufferFlag=1;
}
/**********************************************************
*函數名稱:void IniHard(void) *
*用途:初始化硬盤 *
***********************************************************/
void IniHard(void)
{ARST=0;
delay(0xffff);
ARST=1;
delay(0xffff);
AUXR=0x5c; //設置EXT16=1,使能16-BIT傳送模式
do{FILE6=0xa0; ACC=FILE7;}while(!DRDY|BSY);
FILE6=0x20;
FILE2=64;
FILE7=0x91;
do{ACC=FILE7;}while(BSY);
FILE7=0x10;
do{ACC=FILE7;}while(BSY);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -