FS#6289 - groundwork to get the ata driver to call calllbacks before shutting down the hard disk

Attached to Project: Rockbox
Opened by Jonathan Gordon (jdgordon) - Saturday, 04 November 2006, 13:59 GMT
Task Type Patches
Category Operating System/Drivers
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


following on from Midkays suggestion in irc on friday morning.
this patch adds groundwork so functions in apps/ can register a callback with the ata driver to be called before the disk is spun down.
I belive this compiles for all targets, and just going by the logf output (remomved from the patch) it looks like it works.

There is 1 minor problem with this. I'm not sure what to do for targets which donot use a hard disk (or more specifically, ata.c), e.g the sims and the ondio.
at the moment registering a callback will just call that function immediatly, however im not sure if this is the best thing todo, because it may be that the calling function wants to set some variable if it registered successfully (so it doesnt re-register for example), and it expects the callback to unset the variable. if the callback is called immediatly the variable would be set and never unset!

So, im open to ideas about that part.. the rest just needs some functions to test this.
This task depends upon

Closed by  Jonathan Gordon (jdgordon)
Monday, 06 November 2006, 14:24 GMT
Reason for closing:  Accepted
Comment by Jonathan Gordon (jdgordon) - Sunday, 05 November 2006, 04:54 GMT
and this is the exact same patch, except it makes the audio thread queue up a buffer refill for the next time the callbacks are run.

there is a slight problem i think. I assume it would be pretty bad to call the buffer fill function from the ata thread which is why I have put the message on the audio thread event queue. the problem is, if the disk gets shutdown before the audio thread gets swicthed to this whole thing is pointless...
there is a HZ/4 sleep at the end of the loop in the ata thread, but is that enough? should I add a function to fake a user access so the disk stays spinning anoher X seconds to give the audio thread plenty of time to get the refill message?
Comment by Jonathan Gordon (jdgordon) - Monday, 06 November 2006, 05:24 GMT
and again, this time, the register_ata_accesslater_func checks if the function being registered is already there.
it also calls the callbacks more often (every 5s while the disk is idle but spinning, instead of just when it is about to shutdown).

also, i found the ata_spin() function which fakes a disk access, so thats added to the rebuffer callback also.

I've been running rb with this patch now for a while, and unless there is semi-constant disk access then this doesnt really affect anything. I guess it will work well for people who dont use dircache and browse a bit during playback.
Comment by Jonathan Gordon (jdgordon) - Monday, 06 November 2006, 13:37 GMT
new version
functions renamed to ata_idle_notify...
audio rebuffering makes sure the disk is still spinning before rebuffering (if the ata_idle_notify called the rebuffer)
audio rebuffering only on targets with > 8mb RAM
Comment by Jonathan Gordon (jdgordon) - Monday, 06 November 2006, 14:00 GMT
tiny fix.. remove the ata_sleep() call at the end of audio_fill_file_buffer() which would make this whole thing useless