An ATA/ATAPI CDROM application using a 8051 based Micro controller

this is a project i designed for a customer. it would have become a full on commercial project, but the client never went ahead and so it become GPL.




the objective was to design a cheap CD player for phone systems- a device that plays CD's with recordings of music and people. the signals from this device would be fed into a telephone system. whenever somebody would ring up the business and get "put on hold" (and behold !- the name !), they would hear the CD.
yes, i know this sounds like a common old CD sound system, but my client wanted something very cheap, something that used a simple ATAPI CDROM that could be acquired very cheapy. also, the client wanted some custom features you couldn't get with an off-the-shelf product- he wanted the device to be mobius (a fancy latin word meaning play the CD over and over again), and the customer only wanted *his* CD's to be played (the idea here was that the CD would have a digital preamble.. and my device would only play CD's with this preamble).







when i went about researching ATA/ATAPI. i didn't know anything about it at all. it was a bit of a grey area to me. i've always been hidden from it by drivers or an operating system. as i discovered, you don't need a flash processor 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 that the ATAPI SFF-8020i specification is a big mess. if you look at the literature on the net, there is alot of noise on how shocking this document is. "ATAPI references & Black magic in ATA/ATAPI by Constantine Sapuntzakis" is one such document that discusses flaws in the spec and how to get around certain problems.
On Saturday the 26th of August 2000, the real work on the project began. i had just acquired a development board (DARMICON development board SAB80C537)- a prize given to me by my local university for scoring 5 straight high distinctions for a course i did the previous year. with this, i set about designing the project.
the finished program itself is very simple in operation. it has 3 LED flags that tell you status of the device. the program will detect a CD disk in the drive. if there is one there it will play it's contents. if there's no CD in the drive, then it just sits in a loop until one is inserted. if it has finished playing a CD, then it starts playing it again from the beginning... in other words, it's stateful.
now, this program itself is very adhoc... but in understanding the program and using other ATAPI packets, you will be able to make a whole range of controllers that do different things with ATAPI devices. particularly the really nifty stuff you can do with the newer ATA/ATAPI revisions.. or even the MM2 spec (a really cool application is password protection for harddisks etc).
i have done the ground work here. finding examples of an implemented controller was.... very rare indeed. there was only one documented example i 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. i talked with sergey last year... a very friendly fellow. so, for you it will 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 my experiences etc. it's been almost 9 months since of touched the code, and i 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 can you talk to an ATA device using 8 data lines ?. if so, this would make design very simple. as i discovered, very old specs of ATA (ie ATA-1), did have provisions for 8 bit communication. however, in later iterations of the spec, this was phased out. so, in other words, NO, you can't talk to modern ATA devices using 8 bit data bus.
- ah... also, all timing is assumed to be 12 mhz. that is the clock speed of your micro you design must be 12 mhz. if this isn't the case, then you're going to have to modify the timing of my code... which shouldn't be too hard. i've put comments in the code of how long certain timing should be. it's a simple matter of recalculating the loop waits etc.
- in the spec, it mentions that DD7 (of the data bus) should be pulled down by a 10k resister. i discuss this in the source code, but basically i found that certain devices, the resistor pulls down this line a bit too well. this causes data loss. the idea behind the pull down is to determine if a device is attached. when the ATAPI device is first powered, DD7 is high. so, if the line is high, then you have a device attached. the code in simple_cdrom_controller.a51 is uncommented out. but you can comment this back in if you like.


- the documentation i found can be confusing in places. they talk about asserting and deasserting. you can have asserted signals (1's) that have a Vss state, and assertions that have a Vdd state. the only thing that indicates this in the spec is a '-' minus sign in the front of the line names in the "interface signal names assignment" table (page 28 of the ATA/ATAPI-5 spec). it took me a day to figure this out. it didn't click until i looked at Sergey Zorin's project before i worked out where i was going wrong.
- looking at the init_ata_device: routine in the simple_cdrom_controller.a51 file--
hard reset i had a bit of a problem with. if i did it the way the specs told me to do it, then the busy flag would assert falsey, and my code would go charging full steam ahead without the device initing... so to get around this, i put in a 2 second delay. this hack seemed to fix the problem... 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 signatures are 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. i had to comment out a part of the code due to suggestions by Con Sapuntzakis (ATAPI references & Black magic in ATA/ATAPI). i didn't experience any problems, but i did it just incase.


- another little thing that had me stumped for a while was the ATAPI identify packet device command. i discovered that this command is mandatory 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 or packet). for a while, i couldn't figure out why the device wouldn't respond 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. this register is used when the device sends variable or fitted length data to your controller. it limits the amount it sends before asserting DRQ. if this wasn't set, then the ATAPI device wouldn't send any packet data. this wasn't really emphasised in the spec. the funny thing is that the 'identify packet device' command sets the byte count register (well, i found 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 to set this register to ffffh before sending the command, and then detect end of 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 my head for a while because, if you look in the spec, it doesn't actually mention what they are until you get to the REQUEST SENSE command which is nearly at the back of the manual ;). and i couldn't for the life of me work out what they were, becuase i was expecting a description about them at the start of the spec (one would expect).
after i consulted the linux 2.2 source code, i discovered that these were SCSI error codes. as ATAPI is based on SCSI, this seems to be a throw back thing from when the ATAPI protocol was adapted from SCSI.
i don't use these codes in my implementations. all my simple applications need to know is if the command failed or not (determined by ERR flag in the 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 to get these codes.

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)

Availability-

Locally (onhold-atapi-0.zip) main web site- jsno.arafuraconnect.com.au
email: jsno@arafura.net.au

1 comment:

Labels

PROJECTS 8086 PIN CONFIGURATION 80X86 PROCESSORS TRANSDUCERS 8086 – ARCHITECTURE Hall-Effect Transducers INTEL 8085 OPTICAL MATERIALS BIPOLAR TRANSISTORS INTEL 8255 Optoelectronic Devices Thermistors thevenin's theorem MAXIMUM MODE CONFIGURATION OF 8086 SYSTEM ASSEMBLY LANGUAGE PROGRAMME OF 80X86 PROCESSORS POWER PLANT ENGINEERING PRIME MOVERS 8279 with 8085 MINIMUM MODE CONFIGURATION OF 8086 SYSTEM MISCELLANEOUS DEVICES MODERN ENGINEERING MATERIALS 8085 Processor- Q and A-1 BASIC CONCEPTS OF FLUID MECHANICS OSCILLATORS 8085 Processor- Q and A-2 Features of 8086 PUMPS AND TURBINES 8031/8051 MICROCONTROLLER Chemfet Transducers DIODES FIRST LAW OF THERMODYNAMICS METHOD OF STATEMENTS 8279 with 8086 HIGH VOLTAGE ENGINEERING OVERVOLATGES AND INSULATION COORDINATION Thermocouples 8251A to 8086 ARCHITECTURE OF 8031/8051 Angle-Beam Transducers DATA TRANSFER INSTRUCTIONS IN 8051/8031 INSTRUCTION SET FOR 8051/8031 INTEL 8279 KEYBOARD AND DISPLAY INTERFACES USING 8279 LOGICAL INSTRUCTIONS FOR 8051/8031 Photonic Transducers TECHNOLOGICAL TIPS THREE POINT STARTER 8257 with 8085 ARITHMETIC INSTRUCTIONS IN 8051/8031 LIGHTNING PHENOMENA Photoelectric Detectors Physical Strain Gage Transducers 8259 PROCESSOR APPLICATIONS OF HALL EFFECT BRANCHING INSTRUCTIONS FOR 8051/8031 CPU OF 8031/8051 Capacitive Transducers DECODER Electromagnetic Transducer Hall voltage INTEL 8051 MICROCONTROLLER INTEL 8251A Insulation Resistance Test PINS AND SIGNALS OF 8031/8051 Physical Transducers Resistive Transducer STARTERS Thermocouple Vacuum Gages USART-INTEL 8251A APPLICATIONs OF 8085 MICROPROCESSOR CAPACITANCE Data Transfer Instructions In 8086 Processors EARTH FAULT RELAY ELECTRIC MOTORS ELECTRICAL AND ELECTRONIC INSTRUMENTS ELECTRICAL BREAKDOWN IN GASES FIELD EFFECT TRANSISTOR (FET) INTEL 8257 IONIZATION AND DECAY PROCESSES Inductive Transducers Microprocessor and Microcontroller OVER CURRENT RELAY OVER CURRENT RELAY TESTING METHODS PhotoConductive Detectors PhotoVoltaic Detectors Registers Of 8051/8031 Microcontroller Testing Methods ADC INTERFACE AMPLIFIERS APPLICATIONS OF 8259 EARTH ELECTRODE RESISTANCE MEASUREMENT TESTING METHODS EARTH FAULT RELAY TESTING METHODS Electricity Ferrodynamic Wattmeter Fiber-Optic Transducers IC TESTER IC TESTER part-2 INTERRUPTS Intravascular imaging transducer LIGHTNING ARRESTERS MEASUREMENT SYSTEM Mechanical imaging transducers Mesh Current-2 Millman's Theorem NEGATIVE FEEDBACK Norton's Polarity Test Potentiometric transducers Ratio Test SERIAL DATA COMMUNICATION SFR OF 8051/8031 SOLIDS AND LIQUIDS Speed Control System 8085 Stepper Motor Control System Winding Resistance Test 20 MVA 6-digits 6-digits 7-segment LEDs 7-segment A-to-D A/D ADC ADVANTAGES OF CORONA ALTERNATOR BY POTIER & ASA METHOD ANALOG TO DIGITAL CONVERTER AUXILIARY TRANSFORMER AUXILIARY TRANSFORMER TESTING AUXILIARY TRANSFORMER TESTING METHODS Analog Devices A–D BERNOULLI’S PRINCIPLE BUS BAR BUS BAR TESTING Basic measuring circuits Bernoulli's Equation Bit Manipulation Instruction Buchholz relay test CORONA POWER LOSS CURRENT TRANSFORMER CURRENT TRANSFORMER TESTING Contact resistance test Current to voltage converter DAC INTERFACE DESCRIBE MULTIPLY-EXCITED Digital Storage Oscilloscope Display Driver Circuit E PROMER ELPLUS NT-111 EPROM AND STATIC RAM EXCITED MAGNETIC FIELD Electrical Machines II- Exp NO.1 Energy Meters FACTORS AFFECTING CORONA FLIP FLOPS Fluid Dynamics and Bernoulli's Equation Fluorescence Chemical Transducers Foil Strain Gages HALL EFFECT HIGH VOLTAGE ENGG HV test HYSTERESIS MOTOR Hall co-efficient Hall voltage and Hall Co-efficient High Voltage Insulator Coating Hot-wire anemometer How to Read a Capacitor? IC TESTER part-1 INSTRUMENT TRANSFORMERS Importance of Hall Effect Insulation resistance check Insulator Coating Knee point Test LEDs LEDs Display Driver LEDs Display Driver Circuit LM35 LOGIC CONTROLLER LPT LPT PORT LPT PORT EXPANDER LPT PORT LPT PORT EXTENDER Life Gone? MAGNETIC FIELD MAGNETIC FIELD SYSTEMS METHOD OF STATEMENT FOR TRANSFORMER STABILITY TEST METHODS OF REDUCING CORONA EFFECT MULTIPLY-EXCITED MULTIPLY-EXCITED MAGNETIC FIELD SYSTEMS Mesh Current Mesh Current-1 Moving Iron Instruments Multiplexing Network Theorems Node Voltage Method On-No Load And On Load Condition PLC PORT EXTENDER POTIER & ASA METHOD POWER TRANSFORMER POWER TRANSFORMER TESTING POWER TRANSFORMER TESTING METHODS PROGRAMMABLE LOGIC PROGRAMMABLE LOGIC CONTROLLER Parallel Port EXPANDER Paschen's law Piezoelectric Wave-Propagation Transducers Potential Transformer RADIO INTERFERENCE RECTIFIERS REGULATION OF ALTERNATOR REGULATION OF THREE PHASE ALTERNATOR Read a Capacitor SINGLY-EXCITED SOLIDS AND LIQUIDS Classical gas laws Secondary effects Semiconductor strain gages Speaker Driver Strain Gages Streamer theory Superposition Superposition theorem Swinburne’s Test TMOD TRANSFORMER TESTING METHODS Tape Recorder Three-Phase Wattmeter Transformer Tap Changer Transformer Testing Vector group test Virus Activity Voltage Insulator Coating Voltage To Frequency Converter Voltage to current converter What is analog-to-digital conversion Windows work for Nokia capacitor labels excitation current test magnetic balance voltage to frequency converter wiki electronic frequency converter testing voltage with a multimeter 50 hz voltages voltmeter

Search More Posts

Followers