⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atapi.txt

📁 A MP3 Player Source Code, Enjoy it!
💻 TXT
字号:
UPDATE: the work these guys did is at this page:http://www.pjrc.com/tech/mp3/gallery/cs580/>I am currently looking through your code and>finding that there is a significant ramp-up time involved in understanding>it.  I am writing you to ask if I could use you as a resource to address>some of the questions I have?Sure, ask away.  I'll write a bit of explaination about how the idedriver stuff works.There is a section that begins with these lines:    ;*************************************************************    ;**                                                         **    ;**              IDE Disk Drive Driver Code                 **    ;**                                                         **    ;*************************************************************That is where you'll need to do most of the work to add ATAPI support.It is currently arranged as a state machine, where several states areused to complete an operation to the disk drive.The basic idea is that the FAT32 code generates requests for 4k blocksof data to be read.  It always makes a request for 4k, even if it needsless, and if it needs more than 4k, it will create multiple requests for4k sections.  This makes the IDE code simpler, since all transfers are4k.  If you look at the file "structs.txt", you'll see some C-sytnaxdescriptions of the structures of data that are used.  The only oneyou really need to worry about is:    struct read_request {            uint32  lba_to_read;            int16   block_to_read_into;            int16   unused;    };A read request will always be 8 bytes.  There are two arrays of theserequests, a high priority queue and a low priority queue.  The 32 bit"lba_to_read" gives the LBA sector number to start reading (a 4k chunkis always eight 512 byte sectors).  The 16 bit "block_to_read_into" isthe block number of a 4k block of memory that has already been allocatedby the FAT32 code.  It's the IDE code's job to check for any requestsin either of these queues, and actually perform the read operation ofthe data into that block of memory that was allocated by the FAT32 code.I said that the "read_request" struct was the only one you needed toworry about, but that's actually a bit of a lie.  After the 4k of datais transfered, you need to find the "block_info" struct thatcorresponds to the 4k block you just filled, and clear the bit thatindicates that a read is pending.  This is what tells the FAT32 codethat you've finished transfering the data.  It won't allow that blockto be used until you clear that read_pending bit.  Fortunately, thisdoesn't require getting into all the complexities of the "block_info"structs, as there is already a chunk of code in the IDE driver thatdoes this.  You should just copy that existing code and not worry toomuch about the many complex details of the block_info struct.So, for ATAPI from a cdrom... from what little I know about it... myunderstanding is that cdrom drives always use 2k sectors (extents)instead of 512 byte sectors like hard drives.  That means you'll needto read two 2k sectors to complete the 4k request issued from theFAT32 driver.  Perhaps the cdrom command set has a way to read multipleconsecuitive sectors in one command?  If not, you'll need to issue andprocess two commands, which would mean adding several states to thestate machine.Of course, this is all assuming you manage to make some non-standardcdroms with a FAT32 filesystem burned onto them instead of ISO9660.This ought to be fairly easy with a program like "cdrecord", thatI believe has a command line option to set the image length, insteadof parsing it from a field in the iso9660 headers.  It ought to bepossible to mount such a non-standard cdrom in linux with a commandline option to the mount command.One other minor detail about the "read_request" struct is that the"unused" part isn't actually unused anymore (I should update the file).The first byte is now used to indicate the nature of the request.  Azero is a normal 4k block read request.  I believe I defined 1 tomean putting the hard drive in full sleep mode.  If it becomes necessaryto define other commands besides reading a 4k block and shutdown,that's the place to do it.Now, about those read request queues... there are two, a high priorityand a low priority.  The code beginning at "ide_next_cmd" examinesboth queues and removes the next pending requests and ultimatelyjumps to "ide_next_cmd2" with DPTR pointing to the 8-byte read_requeststruct (or it just returns if no requests are pending).  You'll seethe first things ide_next_cmd2 does it grab the requests and shove itinto the registers.  The non-sleep requests just to "ide_next_norm".After printing a debug message, it starts doing the dirty work ofactually writing the request to the IDE drive.  I would imagine thatyou'll define a global variable to know if the device is a hard driveor cdrom (or for now just hard code a jump to always use cdrom commands),right at the spot where the comment ";now we actually get to work onexecuting this command" appears.  After the existing code finishescommanding the drive to fetch the data, it changes the state variableto cause the IDE code to wait for the read to complete.  It also mapsthe 4k block from the read_request into the 0xA000 page.  Even thoughit's not absolutely necessary to map the block until the drive has thedata ready to xfer, it's done here for a couple good reasons.. themain one being that there's no variable allocated to remember thatblock number for a later ide state (remember, the read_request wasremoved from the queue and the FAT32 code may overwrite it before weget to run in the next state).  This is also a time when the drive isbusy, so it makes sense to do work here instead of when the drive isnot doing useful work.  There's a lengthy comment about a futureoptimization... don't try that yet, as I want to convert to usinginterrupts before doing that sort of heavy optimization work.The last point, which hopefully is pretty obvious by now, it thatyou must not wait within the ide driver code.  While the drive isbusy executing your command, you must set the state variable torun another state later on, which will check if the xfer is doneand do the next action.  In the case of a hard drive, that is startingthe dma transfer of the data, which again sets to another state thatwaits for the dma to be complete, and so on until the state isfinally set back to the idle state.I hope this doesn't seem like massive information overload... thereare quite a number of details, but keep in mind that all of thehigher level work, like deciding what blocks to read and allocatingand managing the memory is all handled by the FAT32 and the mainprogram.  All you have to do is build code, as a sequeuce of statemachine steps, that responds to those requests from the FAT32 codeand stuffs the data into the 4k blocks it allocates for you.  Thereis the issue of detecting the partition and fat32 volume id... whenyou get farther into this, I can help you hard-code some values intothe necessary variables for your particular cdrom image.  I thinkthat for the scope of a student project (where you'll want to showsome success before the end of the academic year), it's best tojust plan on a dirty hack of hard coding the fat32 initializationvalues for your particular cdrom image, and if there is time at theend you could try to auto-detect those settings.  The main thing isto get the low-level device driver code working to get playback froma cdrom.  Even if it's a non-standard cdrom (FAT32 instead of ISO9660)and the initialization is hard-coded for your particular cdrom image,you'll have definately have a successful project and you'll be ableto give a cool demonstration.Well, I hope this clears things up a bit for you.  Please forward itto your other team members.  The project itself is GPL'd (with a clauseto handle inclusion of the hardware initialization data).  I hope you'llshare your success with others, in the spirit of the GPL.  If you onlymanage to get the driver code going, I'll add the autodetect codeand ISO9660 filesystem support later on.Paul

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -