CHAPTER 5 APPLICATION EXAMPLES
Application Note U17121EJ1V1AN
92
// //
/////////////////////////////////////////////////////////////////////////
int ATA_PIO_dataout(ATA_COMMAND *atacom, UHWORD sector_count, void *buff)
{
UBYTE dev, idestat;
UWORD *buffp;
int i, j, status;
buffp = (UWORD*)buff;
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_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; // DRDY timeout
}
*IDEREG_COMMAND = atacom->command; // Command register
wait(TIMER400ns); // Wait 400 ns
status = Wait_IDE_BSY0_DRQ0(); // Wait until BSY=0, DRQ=0
if ( status != 0 ) {
return STATUS_TIMEOUT_BSY0_DRQ0; // BSY timeout error end
}
for ( i=0; i<sector_count; i++ ) {
for ( j=0; j<128; j++ ) { // Data write
*IDEREG_DATA
=
*buffp;
buffp++;
}
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)
}
if ( idestat & IDEREG_ERROR_ERR_BIT ) {