BF533对ATA-IDE硬盘操作的底层函数初始化
0赞
发表于 4/1/2012 10:29:40 AM
阅读(3056)
/**********************************************************************************
* 名称:IdeStandby
* 功能:使硬盘进入Standby状态
* 入口参数:无
* 出口参数:无
***********************************************************************************/
void IdeStandby(void)
{
*pCommand = 0xe0;
}
/**********************************************************************************
* 名称:IdeIdle
* 功能:使硬盘进入Idle状态
* 入口参数:无
* 出口参数:无
***********************************************************************************/
void IdeIdle(void)
{
*pCommand = 0x95;
}
/**********************************************************************************
* 名称:fnIDE_BufferSector
* 功能:读出指定逻辑扇区的全部数据
* 入口参数:uint16_t *buf 数据地址
* DWORD LBALocation 逻辑扇区地址
* uint8_t count 读扇区数最大255,如count=0,读入256个扇区
* 出口参数:操作正常返回0,错误返回1
***********************************************************************************/
int fnIDE_ReadBufferSector(uint16_t *buf,uint32_t LBALocation,uint8_t count)
{
uint16_t i,temp;
uint8_t j;
uint8_t errorcode;
uint16_t Head, Cyl_H,Cyl_L,SecNum;
Wait_ReadyBusy();
*pDriveHead=((LBALocation >> 24) & 0xFF) | 0xE0;
*pCylinderHigh=(LBALocation >> 16) & 0xFF;
*pCylinderLow=(LBALocation >> 8) & 0xFF;
*pSectorNumber=LBALocation & 0xFF;
*pSectorCount=count;
*pCommand=0x21;
j=count;
temp=0;
do
{
Wait_DRQ();
for(i=0; i < SECTORWORDSIZE; i++)
{
buf[temp+i] = *pDataPort;
}
j--;
temp += SECTORWORDSIZE ;
}while(j!=0);
errorcode = CheckforError();
if (errorcode!=0)
return 1;
return 0;
}
/**********************************************************************************
* 名称:fnIDE_WriteBufferSector
* 功能:向指定逻辑扇区写数据
* 入口参数:uint16_t *buf 数据地址
* DWORD LBALocation 逻辑扇区地址
* uint8_t count 读扇区数最大255,如count=0,读入256个扇区
* 出口:操作正常返回0,错误返回1
***********************************************************************************/
int fnIDE_WriteBufferSector(uint16_t *buf,uint32_t LBALocation,uint8_t count)
{
uint16_t i,temp;
uint8_t j;
uint8_t errorcode;
Wait_ReadyBusy();
*pDriveHead=((LBALocation >> 24) & 0xFF) | 0xE0;
*pCylinderHigh=(LBALocation >> 16) & 0xFF;
*pCylinderLow=(LBALocation >> 8) & 0xFF;
*pSectorNumber=LBALocation & 0xFF;
*pSectorCount=count;
*pCommand=0x31;
j=count;
temp=0;
do
{
Wait_DRQ();
for(i=0; i < SECTORWORDSIZE; i++)
{
*pDataPort=buf[temp+i];
}
j--;
temp += SECTORWORDSIZE ;
}while(j!=0);
errorcode = CheckforError();
if (errorcode!=0)
return 1;
return 0;
}
