|
楼主 |
发表于 2007-12-20 17:43:53
|
显示全部楼层
这是发送packet(0xa0)命令的函数,请各位大虾帮忙,偶得qq是285611790,可加我,多谢了
/******************************************************
* SendPacketCommand()
* Output: 0 -> success
* other -> fail,redo
******************************************************/
unsigned char SendPacketCommand(unsigned char dmamode)
{
unsigned i;
unsigned char status,bug,err_status;
BYTE4 timeout;
timeout = ATAPI_TIME_OUT_VALUE;
/**************************************************
* wait for device free *
**************************************************/
while(1)
{
status = _ATA_ReadRegister(ATAPI_REG_STATUS);
if(!(status & ATAPI_BSY_BIT_MASK)&& !(status & ATAPI_DRQ_BIT_MASK))
break;
if( --timeout == 0)
{
return(1);
}
}
/**************************************************
* initial Atapi task file here *
**************************************************/
_ATA_WriteRegister( ATAPI_REG_FEATURE, dmamode &0xff);
_ATA_WriteRegister(ATAPI_REG_BCOUNTL,0x00);
_ATA_WriteRegister(ATAPI_REG_BCOUNTH,0x08);
_ATA_WriteRegister( ATAPI_REG_DRVSEL, 0xa0);
_ATA_WriteRegister( ATAPI_REG_CONTROL, 0x08);
/**************************************************
* Send packet command opcode 0xa0 *
**************************************************/
RESEND_A0:
_ATA_WriteRegister( ATAPI_REG_COMMAND, ATA_POCKETE_COMMAND);
Wait_nBusy();
/**************************************************
* Wait for DRQ flag , max 3ms from 0xa0 sent *
**************************************************/
timeout = ATAPI_TIME_OUT_VALUE;
while(1)
{
status = _ATA_ReadRegister(ATAPI_REG_STATUS);
if((status & (ATAPI_BSY_BIT_MASK|ATAPI_DRQ_BIT_MASK)) == ATAPI_DRQ_BIT_MASK) //bsy = 0,drq = 1
break;
/* if DRQ does not assert 3ms after 0xA0 sent, resend 0xA0 */
if(--timeout == 0){
goto RESEND_A0;
}
}
/**************************************************
* Send 12 bytes command data *
**************************************************/
for (i = 0; i < 12; i += 2)
{
_ATA_WriteRegister(ATAPI_REG_DATA, (gAtapi.command[i+1] << 8) | gAtapi.command );
}
//此处响应中断,检测到错误
Wait_us(200);
return 0;
} |
|