📄 readme
字号:
onhold- an ATA/ATAPI CDROM application using a 8051 based Micro controller Copyright (C) 2000 Jason Nunn Darwin NT, Australia jsno@downunder.net.au jsno@arafura.net.au http://jsno.downunder.net.au--------------------------------------------------------------------------Synopsis-on about 10:00pm on Saturday 15th April 2000, my Unreal Tournment game iwas playing got rudely interrupted by a friend who paid an unannouncedvisit. he told me about a friend of his who wanted me to design a cheap CDplayer for phone systems. his friend was a radio announcer, people paidfor his voice to be on their phone announcement systems. the idea was thathe would record his "voice" onto a CD, and then have a device that playedthat CD, feeding his audio recording into a telephone system. wheneversomebody would ring up the business and get "put on hold" (and behold !-the project name), they would hear him talking about the company etc..i did eventually go on to design the project for him, and i submitted iton the 25th of october 2000, but due to various complications (possibly alack of customer interest, possibly unfeasible to design), it never wentahead. so, i chose to turn this project into a GNU GPL project. this distribution contains two programs. the first one called"cdrom_controller" which is a prototype program- an aid i used to learnabout ATAPI. the second one is "onhold"- this is the actual finishedapplication.a few other programs you might want to grab are-la51-0.1.tgz- is an assembler i wrote a while go. you will need it if youdo any mods to my programs.burn-1.19.tar.gz is an eeprom/flash writer (co-developed by me and terryporter). if you don't want to fork out a few hundred on a burner, thenyou can design one using this dist.ihex2bin.tar.gz is an intel hex to binary converter. la51 produces a ihexfile. burn requires a bin file. this program will do the conversion.these programs are developed for linux. but, you should be able to portthem quite easierly. you can find these on my web site-http://jsno.downunder.net.aua word to those seeking help...-------------------------------if you are a hobbyist with non-profit intentions (ie you will be givingyour project away like me), i am happy to help you with any aspect of thisproject. please don't hesitate to email if you have any questions ;).however, if you are a commercial body seeking help, then you will get nohelp from me unless you PAAAAAYY. are you authorised to sign cheques ?,big cheques ??. if so, then my rates are $200 per hour under "written"contract. if not, then please don't waste my valuable time like myex-client did. i'm beginning to tire of companies and other assorted'suits' rooting me around. i am not a charity for profit organisations.you want something, you paaaayy... just like you expect to be paaaaid.cdrom_controller/cdrom_controller.a51-------------------------------------when i went about researching ATA/ATAPI. i didn't know anything about itat all. it was a bit of a grey area to me. i've always been hidden from itby drivers or an operating system. as i discovered, you don't need a flashprocessor to talk to an ATAPI device. a simple $4 8051 can do the job.for about 4 months, i researched the problem on and off. i discovered thatthe ATAPI SFF-8020i specification is a big mess. if you look at theliterature on the net, there is alot of noise on how shocking thisdocument is. "ATAPI references & Black magic in ATA/ATAPI by ConstantineSapuntzakis" is one such document that discusses flaws in the spec and howto get around certain problems.On Saturday the 26th of August, the real work on the project began. i hadjust acquired a development board (DARMICON development board SAB80C537)-a prize given to me by my local university for scoring 5 straight highdistinctions for a course i did the previous year. with this, i set aboutdesigning the project. after two weeks of work, cdrom_controller.a51 wasproduced.cdrom_controller.a51 is a simple prototype program. it was a graduallearning aid that helped me slowly learn to talk to an ATAPI device.... in operating systems theory, we call this boot strap development. the ATA(T13/1321D R3) and ATAPI (SFF-8020i) specs are f**** big. if you were toprint both these specs out, they would make a handy monitor raiser ;), orif you had a hostage, you could perhaps beat them with the T13/1321D specsto get them to talk ;). both specs are very confusing in places. writingthis prototype was needed to slowly work out how to talk to the device.grey areas in the spec was left to experimentation and learning from that.this was the purpose of cdrom_controller.a51.all cdrom_controller.a51 does is initialise a CDROM device, and send andreceive various command "ATAPI packets" to identify what it is (which itprints via the Darimon development board stdio facility), read the CD'stable of contents (TOC), play a CD (that's in the CDROM device) andfinally report play status of the device.now, this program itself is very adhoc... but in understanding the programand using other ATAPI packets, you will be able to make a whole range ofcontrollers that do different things with ATAPI devices. particularly thereally nifty stuff you can do with the newer ATA/ATAPI revisions.. or eventhe MM2 spec (a really cool application is password protection forharddisks etc).simple_cdrom_controller.a51 has been written to run on the DarimonDevelopment board. If you want to use it on any other development system,then the program will need modifying slightly.if you do get a Darimon board, then usage instructions go like this-print out cdrom_controller/simple_cdrom_controller.sch (or just print the*.ps file), and configure the board according to my diagram. using la51,assemble cdrom_controller.a51. this will produce an intel hex file. usingthe instructions that come with the darimon board, upload the hex file tothe Darimon. power on the attached CDROM drive and then run program. itshould now run. insert CD into drive, and the program will then startplaying the CD.onhold/onhold_dev.a51---------------------onhold was a refinement of cdrom_controller.a51. it's been cut down. allthe printing information has been removed, replaced with basic LED flags,and the program has been modified so that it can detect a CD disk in thedrive. if there is one there it will play it's contents. if there's no CDin the drive, then it just sits in a loop until one is inserted. if it hasfinished playing a CD, then it starts playing it again from thebeginning... in other words, it's stateful.onhold/final_target.a51-----------------------same as onhold_dev.a51, accept the line references and memory references have been changed for the Amtel at89c51 IC. this is the final target code that was burnt into the 5 or so prototypes i submitted to my customer.to build image, assemble using la51. if you are going to use the burnproject to flash your IC's, then use ihex2bin to convert the hex file(produced by la51) into a binary file.final_target.a51 is really made for the Amtel at89c51 IC. if you want to use a different flavour of 8051, then modification may be needed.Amtel at89c51 IC's, are readily available from atmel. o o o o oi have done the ground work here. finding examples of an implementedcontroller was.... very rare indeed. there was only one documented examplei could find (8052 Basic project page (IDE logger section) by Sergey Zorin<zorinsn@rs-pribor.ru>). .. and thank you very much for that to sergey. italked with sergey last year... a very friendly fellow. so, for you itwill just be a matter of understanding my work and recycling my code ;).the hard part for me was working out the semantics of the signalling. once i sussed that out, everything else was fairly smooth sailing.building--------the following is discussions of problems i counted.. and talk about myexperiences etc. it's been almost 9 months since of touched the code, andi have forgotten some of the things i wanted to talk about. but anyway,here goes-- one question i was confused about in the early stages of design, was canyou talk to an ATA device using 8 data lines ?. if so, this would makedesign very simple. as i discovered, very old specs of ATA (ie ATA-1), didhave provisions for 8 bit communication. however, in later iterations ofthe spec, this was phased out. so, in other words, NO, you can't talk tomodern ATA devices using 8 bit data bus.- ah... also, all timing is assumed to be 12 mhz. that is the clock speedof your micro you design must be 12 mhz. if this isn't the case, thenyou're going to have to modify the timing of my code... which shouldn't betoo hard. i've put comments in the code of how long certain timing shouldbe. it's a simple matter of recalculating the loop waits etc.- in the spec, it mentions that DD7 (of the data bus) should be pulleddown by a 10k resister. i discuss this in the source code, but basically ifound that certain devices, the resistor pulls down this line a bit toowell. this causes data loss. the idea behind the pull down is to determineif a device is attached. when the ATAPI device is first powered, DD7 ishigh. so, if the line is high, then you have a device attached. the codein simple_cdrom_controller.a51 is uncommented out. but you can commentthis back in if you like.- the documentation i found can be confusing in places. they talk aboutasserting and deasserting. you can have asserted signals (1's) that have aVss state, and assertions that have a Vdd state. the only thing thatindicates this in the spec is a '-' minus sign in the front of the linenames in the "interface signal names assignment" table (page 28 of theATA/ATAPI-5 spec). it took me a day to figure this out. it didn't clickuntil i looked at Sergey Zorin's project before i worked out where i wasgoing wrong.- looking at the init_ata_device: routine in thesimple_cdrom_controller.a51 file--hard reset i had a bit of a problem with. if i did it the way the specstold me to do it, then the busy flag would assert falsey, and my codewould go charging full steam ahead without the device initing... so to getaround this, i put in a 2 second delay. this hack seemed to fix theproblem... and the state of the busy flag is correct after 2 seconds.the device signature was a bit of a haha funny one too. device signaturesare the initial values held in the various register's of an ATA device. these values can tell you if the device is ATAPI packet command capable. ihad to comment out a part of the code due to suggestions by ConSapuntzakis (ATAPI references & Black magic in ATA/ATAPI). i didn'texperience any problems, but i did it just incase.- another little thing that had me stumped for a while was the ATAPIidentify packet device command. i discovered that this command ismandatory for CDROM (and like) devices, as it will enable the DRDY flag.without this command, you won't be able to issue any commands (ATA orpacket). for a while, i couldn't figure out why the device wouldn'trespond to any commands. i think i remember a small print in the spec(SFF-8020i) mentioning this.- also, another area i got into trouble was the byte count register. thisregister is used when the device sends variable or fitted length data toyour controller. it limits the amount it sends before asserting DRQ. ifthis wasn't set, then the ATAPI device wouldn't send any packet data. thiswasn't really emphasised in the spec. the funny thing is that the'identify packet device' command sets the byte count register (well, ifound this to be the case anyway), yet other packet commands don't.a strategy i used when i issuing commands that send me data was simply toset this register to ffffh before sending the command, and then detect endof packet data with the DRQ flag.- the SFF-8020i talks about ASC (Additional Sense Key) and ASCQ(Additional Sense Key Qualifier) error codes. this had me scratching myhead for a while because, if you look in the spec, it doesn't actuallymention what they are until you get to the REQUEST SENSE command which isnearly at the back of the manual ;). and i couldn't for the life of mework out what they were, becuase i was expecting a description about themat the start of the spec (one would expect).after i consulted the linux 2.2 source code, i discovered that these wereSCSI error codes. as ATAPI is based on SCSI, this seems to be a throw backthing from when the ATAPI protocol was adapted from SCSI.i don't use these codes in my implementations. all my simple applicationsneed to know is if the command failed or not (determined by ERR flag inthe status register), but for your information, if you issue a command,and you get an ERR flag, then you can issue the REQUEST SENSE command toget these codes. o o o o owell, that's about it really. i have exhausted all of the things iremembered to talk about ;) haha.design references----------------- - ATA/ATAPI-5 (T13/1321D R3) (www.t10.org) - ATA packet interface for CDROM's (SFF-8020i) (fission.dt.wdc.com)other references used: - linux 2.2.x source code (/usr/src/linux/drivers/ide*) (had to be referred to seens that the SFF-8020i spec is so shitty) - ATAPI references & Black magic in ATA/ATAPI by Constantine Sapuntzakis <csapuntz@stanford.edu> http://www.stanford.edu/~csapuntz/ide.html http://www.stanford.edu/~csapuntz/blackmagic.html - 8052 Basic project page (IDE logger section) by Sergey Zorin <zorinsn@rs-pribor.ru> http://www.nomad.ee/micros/8052bas.html (nb/ very very helpful) - General ATAPI info (including some source code) Hale Landis's ATAPI pages http://www.ata-atapi.com (a good introduction to it all, as i knew nothing when i first started this project) ooo0ooo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -