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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

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

Post 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?
Last edited by HugeCode on Sun May 12, 2013 6:03 am, edited 1 time in total.
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

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

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

Sounds like you forgot the delay needed for selecting a device.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

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

Post by HugeCode »

I don't know. I placed this code on the absolute top of reading function, before any commanding code.
Post Reply