CHAPTER 5 APPLICATION EXAMPLES
Application Note U17121EJ1V1AN
94
idestat = *IDEREG_ALT_STATUS; // Alt Status register empty read
idestat = *IDEREG_STATUS; // Status register read
if ( idestat & IDEREG_ERROR_ERR_BIT ) {
return STATUS_IDE_ERROR(*IDEREG_ERROR); // Error end (after command execution)
}
return STATUS_SUCCESS; // Normal end
}
/////////////////////////////////////////////////////////////////////////
// Function name: ATA_DMA //
// Function: Executes DMA command protocol. //
// Argument: atacom : ATA_COMMAND structure pointer //
// Return value: //
// STATUS_SUCCESS : Normal end //
// STATUS_TIMEOUT_DEVICE_SELECTION : DEVICE SELECTION error end //
// STATUS_TIMEOUT_BSY0_DRQ0 : BSY=0,DRQ=0 timeout error end //
// STATUS_TIMEOUT_DRDY1 : DRDY=1 timeout error end //
// STATUS_TIMEOUT_INTRQ : INTRQ timeout error end //
// STATUS_TIMEOUT_BMEND : BM timeout error end //
// STATUS_IDE_ERROR : Error end after command execution //
// //
/////////////////////////////////////////////////////////////////////////
int ATA_DMA(ATA_COMMAND *atacom)
{
int status;
UBYTE dev, idestat;
dev = ( atacom->device_head >> 4 ) & 1;
status = ATA_Device_Selection(dev); // DEVICE SELECTION
if ( status != 0 ) {
return STATUS_TIMEOUT_DEVICE_SELECTION; // DEVICE SELECTION timeout
}
*IDEREG_FEATURES = atacom->features; // Features register
*IDEREG_SECTOR_COUNT = atacom->sector_count; // SectorCount register
*IDEREG_SECTOR_NUMBER = atacom->sector_number; // SectorNumber register
*IDEREG_CYL_LOW = atacom->cylinder_low; // CylinderLow register
*IDEREG_CYL_HIGH = atacom->cylinder_high; // CylinderHigh register
status = Wait_IDE_DRDY1(); // Loop until DRDY=1
if ( status != 0 ) {
return STATUS_TIMEOUT_DRDY1; // DRDY timeout
}
*IDEREG_COMMAND = atacom->command; // Command register