Page 1 of 1

[SOLVED] What causes endless lag of BUSY bit of ATA device?

Posted: Sat May 04, 2013 8:21 am
by HugeCode
Does anybody have any idea what can cause endless lag of BUSY bit of ATA device?
This is how it looks like:
Image
(Values are signed char, so real value of status register is 0x86)
This is my code:

Code: Select all

while((ata_readstatus(dev) & ATA_STATUS_BUSY) == ATA_STATUS_BUSY)
		;

	if((ata_readstatus(dev) & ATA_STATUS_BUSY) == ATA_STATUS_BUSY) {
		ata_srst(dev);
	}
	if((ata_readstatus(dev) & ATA_STATUS_BUSY) == ATA_STATUS_BUSY) {
		dbg_print("ATA device is busy");
		dbg_descrval("STATUS: ", ata_readstatus(dev));
		return 0;
	}
The first version was without while loop. It simple checks if busy bit is set. If it is, it does the software reset. If BUSY bit doesn't clear, it is error. After occurence of this error I tried to put loop to wait until busy bit clears. Nothing changed, so it looks like busy bit is set for some time, then it's cleared and set again.

Does anybody know what can cause such problem?

Re: What can cause endless lag of BUSY bit of ATA device?

Posted: Wed May 08, 2013 10:08 am
by HugeCode
I finally solved it by little trick...
Where there were more whiles which were trying to solve the problem, I put this code:

Code: Select all

while((ata_readstatus(dev) & ATA_STATUS_BUSY) == ATA_STATUS_BUSY)
      while((ata_readstatus(dev) & ATA_STATUS_BUSY) == ATA_STATUS_BUSY)
              ;
So whenever was the BUSY bit cleared for some time, it jumped to test of higher while loop and there it was set again. Now it works, but I must say that there is noticeable slowdown.

Re: What can cause endless lag of BUSY bit of ATA device?

Posted: Thu May 09, 2013 3:01 am
by Combuster
Sounds like you forgot the delay needed for selecting a device.

Re: What can cause endless lag of BUSY bit of ATA device?

Posted: Thu May 09, 2013 7:26 am
by HugeCode
I don't know. I placed this code on the absolute top of reading function, before any commanding code.