📄 onhold- an ata-atapi cdrom application using a 8051 based micro controller.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0056)http://jsno.arafuraconnect.com.au/proj_micro/onhold.html -->
<HTML><HEAD><TITLE>onhold- an ATA/ATAPI CDROM application using a 8051 based Micro controller</TITLE>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2919.6307" name=GENERATOR></HEAD>
<BODY bgColor=#000000 link=#8888ff text=#f0f0f0 vLink=#ff0000>
<HR>
<CENTER><FONT color=#ffffd0>== <B>onhold- an ATA/ATAPI CDROM application using a
8051 based Micro controller</B> (Aug-Oct 2000) == </FONT></CENTER>
<P>This is a project I designed for a customer. It would have become a full
commercial venture, but the client never went ahead and so it become GPL.
<P>
<CENTER><IMG align=bottomleft
src="onhold- an ATA-ATAPI CDROM application using a 8051 based Micro controller_files/onhold.jpg">
</CENTER>
<P>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 <I>fed</I> into a telephone system. Whenever somebody would ring
up the business and get "put on hold" <I>(and behold !- the name !)</I>, they
would hear the CD.
<P>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
<I>(a fancy latin word meaning play the CD over and over again)</I>, and the
customer only wanted *his* CD's to be played <I>(the idea here was that the CD
would have a digital preamble.. and my device would only play CD's with this
preamble)</I>.
<P>
<CENTER><IMG align=bottomleft
src="onhold- an ATA-ATAPI CDROM application using a 8051 based Micro controller_files/onhold1.png">
</CENTER>
<P>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.
<P>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.
<P>On Saturday the 26th of August 2000, the real work on the project began. I
had just acquired a development board <I>(DARMICON development board
SAB80C537)</I>- 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.
<P>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 one is inserted, 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 ;).
<P>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
<I>(a really cool application is password protection for harddisks etc)</I>.
<P>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 <I>(8052 Basic project page (IDE logger section) by Sergey Zorin
(zorinsn@rs-pribor.ru))</I>. .. 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.
<P><B>Building</B>
<P>The following is discussions of problems i counted. Nine months passed before
I documented this page, and unfortunately forgot some of the things I wanted to
talk about... but anyway, here goes-
<P>- 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 <I>(ie ATA-1)</I>, 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.
<P>- 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.
<P>- In the spec, it mentions that DD7 <I>(of the data bus)</I> 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.
<P>- 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 <I>(page 28 of the ATA/ATAPI-5 spec)</I>. 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 ;).
<P>- Looking at the init_ata_device: routine in the simple_cdrom_controller.a51
file--
<P>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 BSY 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.
<P>The device signature was a bit of a funny one as well. 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 <I>(ATAPI references
& Black magic in ATA/ATAPI)</I>. I didn't experience any problems, but I did
it just incase.
<P>- 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 <I>(and like)</I> devices, as it will enable the DRDY flag. Without
this command, you won't be able to issue any commands <I>(ATA or packet)</I>.
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.
<P>- 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
emphasized in the spec. The funny thing is that the 'Identify Packet Device'
command sets the byte count register <I>(well, I found this to be the case
anyway)</I>, yet other packet commands don't.
<P>A strategy I used when 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.
<P>- The SFF-8020i talks about ASC <I>(Additional Sense Key)</I> and ASCQ
<I>(Additional Sense Key Qualifier)</I> 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, because I was expecting a description about them at the start of the spec
<I>(one would expect)</I>.
<P>After consulting 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.
<P>I don't use these codes in my implementations. All my simple applications
need to know is if the command failed or not <I>(determined by ERR flag in the
status register)</I>, 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.
<P><PRE><B>Design references:</B>
- ATA/ATAPI-5 (T13/1321D R3) (www.t10.org)
- ATA packet interface for CDROM's (SFF-8020i) (fission.dt.wdc.com)
<B>Other references used:</B>
- 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)
</PRE>
<HR>
Availability- <BR><A
href="http://jsno.arafuraconnect.com.au/rel/micros/onhold-atapi-0.tar.bz2">Locally
(onhold-atapi-0.tar.bz2)</A> <BR><A
href="http://jsno.arafuraconnect.com.au/rel/micros/onhold-atapi-0.zip">Locally
(onhold-atapi-0.zip)</A> for the windoze users... <I>*sigh* god help you..</I>
<BR><I>(Nb/ these dists. contain source code, schematics and instructions
etc)</I>
<P><A
href="http://jsno.arafuraconnect.com.au/rel/micros/onhold_errata.txt">Source
code errata</A> bugs spotted by users (and yet to be updated ;)
</P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -