?? ide.c
字號:
#include "../CPLD.h"
#include "ide.h"
#include "GeneralFunc.h"
#define IdeDalayValue 100000
extern void Delay(unsigned int Value);
extern void IdeStandby(void);
extern void IdeIdle(void);
extern unsigned char IdeReadSector(unsigned char SectorNum,
unsigned short CylinderNum);
extern unsigned char IdeWriteSector(unsigned char SectorNum,
unsigned short CylinderNum);
extern unsigned short buffers[256];
/************************************************************************/
/* */
/************************************************************************/
void IdeStandby(void)
{
*pCommand = 0xe0;
}
void IdeIdle(void)
{
*pCommand = 0x95;
}
unsigned char IdeReadSector(unsigned char SectorNum,
unsigned short CylinderNum)
{
unsigned int i=0;
unsigned int sum1=0,sum2=0;
unsigned char errorstatus=0;
unsigned short result=0;
unsigned char ERRbit=0;
unsigned char cylinderlow=0,cylinderhigh=0;
cylinderlow = (unsigned char)(CylinderNum & 0x00ff);
cylinderhigh = (unsigned char)((CylinderNum & 0xff00)<<8);
IDEREADLAB1:
result = *pStatus;
if(result == 0x50)
{
*pPreComp = 0x00;
*pSectorCount = 0x01;
*pSectorNumber = SectorNum;
*pCylinderLow = cylinderlow;
*pCylinderHigh = cylinderhigh;
*pDriveHead = 0xa0+1;
*pCommand = 0x21;//read
IDEREADLAB2:
result = *pStatus;
if(result == 0x58)
{
for(i=0;i<256;i++)
{
buffers[i] = *pDataPort;//read
}
result = *pStatus;
ERRbit = result & 0x01;
if(ERRbit == 0)//ok
{return(0);
}
else
{errorstatus = *pErrorReg;
return(errorstatus);
}
}
else//timeout process
{Delay(IdeDalayValue);
sum2++;
if(sum2<1000)
{goto IDEREADLAB2;
}
else
{errorstatus = *pErrorReg;
return(errorstatus);
}
}
}
else//timeout process
{Delay(IdeDalayValue);
sum1++;
if(sum1<10)
{goto IDEREADLAB1;
}
else
{errorstatus = *pErrorReg;
return(errorstatus);
}
}
}
unsigned char IdeWriteSector(unsigned char SectorNum,
unsigned short CylinderNum)
{
unsigned int i=0;
unsigned int sum1=0,sum2=0;
unsigned char errorstatus=0;
unsigned char result=0;
unsigned char ERRbit=0;
unsigned char cylinderlow=0,cylinderhigh=0;
cylinderlow = (unsigned char)(CylinderNum & 0x00ff);
cylinderhigh = (unsigned char)((CylinderNum & 0xff00)<<8);
IDEREADLAB1:
result = *pStatus;
if(result == 0x50)
{
*pPreComp = 0x00;
*pSectorCount = 0x01;
*pSectorNumber = SectorNum;
*pCylinderLow = cylinderlow;
*pCylinderHigh = cylinderhigh;
*pDriveHead = 0xa0+1;
*pCommand = 0x31;//write
IDEREADLAB2:
result = *pStatus;
if(result == 0x58)
{
for(i=0;i<256;i++)
{
*pDataPort = buffers[i];//write
}
result = *pStatus;
ERRbit = result & 0x01;
if(ERRbit == 0)//ok
{return(0);
}
else
{errorstatus = *pErrorReg;
return(errorstatus);
}
}
else//timeout process
{Delay(IdeDalayValue);
sum2++;
if(sum2<1000)
{goto IDEREADLAB2;
}
else
{errorstatus = *pErrorReg;
return(errorstatus);
}
}
}
else//timeout process
{Delay(IdeDalayValue);
sum1++;
if(sum1<10)
{goto IDEREADLAB1;
}
else
{errorstatus = *pErrorReg;
return(errorstatus);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -