CHAPTER 5 APPLICATION EXAMPLES
Application Note U17121EJ1V1AN
91
*IDEREG_SECTOR_NUMBER = atacom->sector_number; // SectorNumber register
*IDEREG_CYLINDER_LOW = atacom->cylinder_low; // CylinderLow register
*IDEREG_CYLINDER_HIGH = atacom->cylinder_high; // CylinderHigh register
status = Wait_IDE_DRDY1(); // Loop until DRDY=1
if ( status != 0 ) {
return STATUS_TIMEOUT_DRDY1 // DRDY1 timeout
}
*IDEREG_COMMAND = atacom->command; // Command register
wait(TIMER400ns); // Wait 400 ns
for ( i=0; i<sector_count; i++ ) {
status = Wait_IDE_INTRQ(); // Wait for INTRQ assert
if ( status != 0 ) {
return STATUS_TIMEOUT_INTRQ; // INTRQ timeout error
}
idestat = *IDEREG_STATUS; // Status register read (INTRQ clear)
for ( j=0; j<128; j++ ) { // Data read
*buffp = *IDEREG_DATA;
buffp++;
}
}
idestat = *IDEREG_ALTERNATE_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_PIO_dataout //
// Function: Executes PIO data out command protocol. //
// Argument: atacom : ATA_COMMAND structure pointer //
// sector_count : Number of sectors //
// buff : Buffer 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_IDE_ERROR : Error end after command execution //