home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / diskutil / dma / dma.txt
Encoding:
Text File  |  1988-12-21  |  13.9 KB  |  300 lines

  1. <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  2.  
  3. HOW TO USE THE ATARI ST HARD DISK PORT
  4.  
  5.     When I set about to interface to the Hard Disk Port on my Atari
  6. 1040ST I assembled all the documentation I could find and discovered that,
  7. though I found plenty, I still ended up without quite enough to design
  8. the interface.  I attacked the problem with the Scientific Method and
  9. now have a working one-megabyte-per-second interface.  This article was
  10. written to give others the information that I needed in hopes that they
  11. will not be frightened of using what has turned out to be a very simple
  12. and easy-to-use port.
  13.  
  14.     Since much of the information in this article is based on 
  15. experiment with only one DMA chip it is possible that some of it will
  16. not apply to other revisions of the chip.  Perhaps someone at Atari will
  17. correct any misconceptions or outright errors.  Also, the interface I
  18. built only does DMA transfers into the ST (read operations); therefore,
  19. while it is easy to infer the appropriate protocol, I haven't tested
  20. DMA transfers in the opposite direction.
  21.  
  22. DMA IN THE ST
  23.  
  24.     The same DMA channel is used for both the floppy disks and the
  25. Hard Disk Port.  The floppies are controlled by a floppy disk controller
  26. chip which is connected to the DMA chip.  The DMA chip is capable of
  27. servicing data requests at about 1.25 MHz.  If you attempt to transfer
  28. data at a rate greater than that data will be lost.  I have been able
  29. to transfer data at very close to this rate without any problems.  The
  30. DMA chips buffers 16 bytes of data before requesting the memory buss
  31. then holds the buss until all buffered data has been transfered.  Memory
  32. cycles used for DMA are taken from the processor;  since the memory buss
  33. makes 4 MByte/s available, 1 MByte/s of DMA should take 25% of the cycles
  34. normally available to the processor, plus a fudge factor to account for
  35. the time spent in arbitration.
  36.  
  37. THE HARD DISK PORT
  38.  
  39.     The Hard Disk Port is a 19-pin D connector - apparently completely
  40. unavailable through normal commercial channels.  I made my own from a 
  41. metal-shelled male DB25 connector as follows:
  42.  
  43.     - remove and discard the metal shell revealing that the pins are
  44.       held in place and insulated with two loose plastic retainers;
  45.     - remove the pins from the retainers (for once you can lose a couple
  46.       since you will end up with six spares);
  47.     - using a fretsaw or a fine hacksaw remove one end of both retainers
  48.       leaving 19 holes;
  49.     - replace the pins and glue the retainers together.
  50.  
  51. You now have the connector you need.  It has no mounting ears but the
  52. retaining force of 19 pins is quite substantial.  If this is not adequate
  53. you could perhaps ingeniously salvage the metal shell somehow.
  54.  
  55.     The pins on the Hard Disk Port are connected as follows (pin one
  56. is at the upper right of the connector facing the rear of the computer):
  57.  
  58.     1-8    DMA data buss bits 0-7 (bidirectional)
  59.     9    Hard Disk Controller Chip Select (_HDCS) (output)
  60.     10    Interrupt Request (_IRQ) (input, internal 1k pull-up)
  61.     11    Ground
  62.     12    Reset (bidirectional)
  63.     13    Ground
  64.     14    Acknowledge (_ACK) (output)
  65.     15    Ground
  66.     16    A1 (output)
  67.     17    Ground
  68.     18    Read/_Write (R/_W) (output)
  69.     19    Data Request (_DRQ) (input, internal 1k pull-up)
  70.  
  71.     The Hard Disk Port is connected directly to the DMA chip WITHOUT
  72. ANY BUFFERING on most pins - be careful,
  73. a small mistake (e.g., static) could blow your DMA chip.  The system reset
  74. line is also directly connected to the port meaning that accidental shorts
  75. reset your computer - very irritating.
  76.  
  77. INSIDE THE DMA CHIP
  78.  
  79.     The DMA chip is accessed through memory-mapped registers:
  80.  
  81. ff8604    R/W  16 bits    When bit 4 of the Mode register is zero a read or
  82.             write access to this word causes a read or write
  83.             cycle on the DMA buss.  If bit 3 is set the Hard
  84.             Disk Chip Select controls the cycle; otherwise,
  85.             the Floppy Disk Controller is selected.  R/_W is
  86.             set according to the type of the CPU access and
  87.             A1 is set according to bit 1 of the Mode register.
  88.             NOTA BENE: what is called A0 in the DMA chip is
  89.             called A1 on the Hard Disk Port.  For some reason, 
  90.             if bit 7 is not set no DMA buss    cycle will take
  91.             place.
  92.  
  93.             When bit 4 of the Mode register is one the internal
  94.             sector count register is selected.  This register
  95.             counts down the number of 512-byte blocks that have
  96.             been transferred.  When the sector count register
  97.             reaches zero the chip will cease to transfer data.
  98.  
  99. ff8606    R    16 bits    Status word:
  100.             bit 0: 1 if error.
  101.             bit 1: 1 if sector count is zero.
  102.             bit 2: 1 if _DRQ is active.
  103.             If this word is polled during a DMA operation the
  104.             transfer will be disrupted.  End of transfer must
  105.             be signalled with the _IRQ signal.  The status is
  106.             cleared by toggling bit 8 in the Mode register.
  107.  
  108. ff8606    W    16 bits    Mode register:
  109.             bit 0:    not used.
  110.             bit 1:    A0; state of Hard Disk Port line A1 (sic)
  111.                 during a DMA buss cycle.
  112.             bit 2:    A1; used for Floppy Controller only.
  113.             bit 3:    HDC/_FDC chip select; if this bit is 1
  114.                 the _HDCS chip select will be generated;
  115.                 otherwise the Floppy Controller select.
  116.             bit 4:    If one, select the the internal sector
  117.                 count register for access at ff8604.
  118.             bit 5:    Reserved; set to zero.
  119.             bit 6:    Disable DMA when set; this is not used by
  120.                 Atari.
  121.             bit 7:    FDC/_HDC transfer select; if set DRQ from
  122.                 the Floppy Controller is acknowledged;
  123.                 otherwise, DRQ from the Hard Disk Port.
  124.                 This bit must also be set to get a DMA buss
  125.                 cycle for some reason.
  126.             bit 8:    Write/_Read; if set, data will be transferred
  127.                 out of memory; otherwise, into.  Toggling
  128.                 this bit also clears the DMA chip status.
  129.  
  130. ff8609    R/W  8 bits    DMA Address Counter High byte.
  131. ff860b    R/W  8 bits    DMA Address Counter Mid byte.
  132. ff860d    R/W  8 bits    DMA Address Counter Low byte.
  133.             The DMA Address Counter must be loaded in Low, Mid,
  134.             High order.
  135.  
  136.     There are two eight-word FIFOs in the chip; one for buffering
  137. read operations and one for writes.  The FIFOs are not flushed automatically
  138. so you can only transfer data in multiples of 16 bytes.  Actually, use
  139. 512-byte units like the sector count register does.
  140.  
  141.     The DMA chip has no interrupt capability; This is ickky, but
  142.     cheap.  End-of-transfer  interrupts must  be  generated  by
  143. the  external controller and are  masked and vectored by the 68901  MFP
  144. chip on the General Purpose  I/O Port, bit 5, interrupt level  7. The
  145. MFP chip interrupts  are controlled  with the XBIOS  calls 'mfpinit',
  146. 'jdisint',  and 'jenabint'.  'jenabint(7)' and  'jdisint(7)' will
  147. enable and disable the DMA interrupt. 'mfpint(7,dmahandler)' will
  148. initialize  the vector  to 'dmahandler',  wiping out  any earlier one.
  149. If  you want  instead  to  simply  test  the state  of  the interrupt
  150. request line,  without taking  any interrupts  you can test the MFP
  151. GPIP data register. Read a byte from fffa01 and mask with $20; if the
  152. result is zero there is no interrupt.
  153.  
  154.     Because the floppy controller shares the DMA chip you have to
  155. be very careful about two things: 1) do not leave DMA interrupts enabled
  156. accidentally or floppy operations will call your DMA interrupt handler;
  157. 2) turn off the floppy check routine while using DMA by jamming a 1 into
  158. FLOCK=$43e to prevent this periodic operation from screwing up your
  159. transfers by altering the DMA chip registers.
  160.  
  161. TIMING
  162.  
  163.     These timing contraints are my interpretation of sketchy,
  164. preliminary-looking Atari documents dated "27 September 1985".  If
  165. someone at Atari can give better figures, please inform me.
  166.  
  167.     There are two separate types of transfer on the DMA buss: 
  168. processor cycles, which are initiated by the processor, and DMA cycles,
  169. which are initiated by the external controller.  The processor 
  170. initiates a DMA transfer by waking up the controller with a few command
  171. bytes then gives it control of the DMA buss.  The controller then uses
  172. the DMA buss as long as it needs it and returns control by interrupting
  173. the processor. 
  174.  
  175.     Processor cycles are controlled by the _HDCS, R/_W, and A1
  176. lines in the usual fashion.  On a write cycle, the DMA chip gives you
  177. 60 ns of setup on A1, data, and R/_W before asserting _HDCS for about
  178. 250 ns, then holds for no more than 20 ns.  On a read cycle, you get
  179. the same setup for A1 and R/_W, and you must give the DMA chip 100 ns
  180. setup oe data before _HDCS is retracted.  Hold time should be less than
  181. 80 ns.
  182.  
  183.     Data cycles are initiated by the external controller by asserting
  184. _DRQ.  _ACK will be asserted by the DMA chip no more than 240 ns later.
  185. _DRQ may then be retracted.  _ACK is asserted for about 250 ns.  In a
  186. read operation (data from controller to memory) data should be setup
  187. 60(?) ns before _ACK is retracted and held for 50(?) ns.  In a write
  188. operation (data from memory to controller) data is valid 60 ns before
  189. _ACK is asserted until 60 ns after _ACK is retracted. _DRQ for the next
  190. cycle may not be asserted earlier than 240 ns after _ACK has been
  191. retracted.
  192.  
  193. INTERFACING IT
  194.  
  195.     This interface transfers a byte into the the DMA chip whenever
  196. a rising edge is seen on the data strobe input.  This interface cannot
  197. coexist with a hard disk because it will respond to commands intended
  198. for the hard disk.  Bear with me, we'll tackle that later.
  199.  
  200.     Rather than attempt to render several schematics in ASCII I will
  201. describe the circuits and let you draw the schematics.  If the 
  202. instructions don't make any sense you probably should not attempt to
  203. make the interface.  It's all very simple if you know exactly what
  204. you are doing; if you don't - you're dead.
  205.  
  206. A SIMPLE, READ/WRITE INTERFACE
  207.  
  208.     If all you want to do is read and write bytes it is very simple:
  209. You simply use the Chip Select, R/_W, and A1 lines to select two write
  210. registers and two read registers.  If you need more than that all you
  211. have to do is use A1=0 to select an address register which selects the
  212. register you get on a cycle with A1=1.  One thing that you have to
  213. consider is that the ST writes to the Hard Disk Port several times
  214. during its booting procedure, presumably to determine if there are any
  215. hard disks connected.  Apparently, if no interrupt is received in response
  216. to these writes the ROM assumes that no controller is connected.  
  217.  
  218.     In my interface there is a mode register which is accessed when
  219. A1=0.  It has two control bits and two bits connected to a decoder which
  220. determines which of three other registers are selected when A1=1.
  221.  
  222. ADDING AN INTERRUPT
  223.  
  224.     If an interrupt is needed (probably why you want to use this
  225. port) you need a flipflop to store the interrupt state and some way
  226. to reset it.  I used a 74LS74 for the flipflop with a diode on the output
  227. to get the open-collector action.  This diode is not needed if there is
  228. no other device on the Hard Disk Port. (But don't scrimp on a diode...)
  229. I reset the interrupt with any access to the mode register but other
  230. methods would work as well.  Make sure that the circuit will always
  231. leave reset with the interrupt cleared.  I arranged this by having a
  232. circuit enable bit in the Mode register, which is cleared by system
  233. reset.  If you screw up on this your floppy will not work because the
  234. same interrupt is used for both floppy and hard disk controllers.  I
  235. learned a little about the file system the hard way while debugging
  236. this interface - I recommend getting the interrupt reset system right
  237. the first time.
  238.  
  239. ADDING DMA
  240.  
  241.     Once you can write to your mode register adding DMA transfers
  242. (at least for read operations) is very simple.  All you need is 
  243. another flipflop to do the Data Request synchronization and a 3-state
  244. octal latch (74LS374) to hold the data.  Connect
  245. the output to the DRQ line with a diode as with the interrupt flipflop.
  246. When data is available clock it into the data register and clock a zero
  247. into the flipflop.  This generates a data request for the DMA chip.
  248. When it gets around to it the DMA chip will assert _ACK, which means it
  249. is ready to accept the data.  Since you have the _ACK signal connected
  250. to the three-state enable pin on the data register the data is driven
  251. onto the buss.  You also use the _ACK signal to set the flipflop.
  252. When the DMA chip no longer needs the data it will retract _ACK and
  253. you can begin another transfer.  Spurious data requests are not as
  254. nasty as spurious interrupts because the DMA chip does not listen to
  255. hard disk data requests if it is listening to the floppy disk controller.
  256. Naturally, if there is a real hard disk out there, there had better not
  257. be any spurious data requests.
  258.  
  259. CO-EXISTING WITH A HARD DISK
  260.  
  261.     I do not own a hard disk; therefore, the suggestions in this
  262. section are totally untested.
  263.  
  264.                                           eight
  265.     The Atari-defined protocol allows seven different controllers on
  266. the DMA buss.  In order to make an interface which will not interfere with
  267. other controllers you must understand the protocol.  Each command is
  268. initiated with a processor write cycle which sends out a Command Byte (A1=0)
  269. on the DMA buss.  The most-significant three bits contain the controller
  270. number and the remaining bits contain an operation code.  The controller
  271. whose number matches the controller number in the Command Byte responds
  272. to the operation code.  Some operations require parameters, which are 
  273. sent as Data Bytes (A1=1) following the Command Byte.  The controller
  274. generates an interrupt after coping with each byte.  After the last Data
  275. Byte is sent the controller takes over the buss for the DMA transfer.
  276. When the transfer is finished the controller generates an interrupt.
  277.  
  278.     In order to keep out of the way of other controllers on the buss it
  279. should only be necessary to select your interface with a Command Byte with
  280. the proper format.  After that use data bytes as you wish, since all other
  281. controllers will not be selected.
  282.  
  283. GOOD LUCK!
  284.  
  285.     Using this information anyone with any experience in interfacing
  286. can produce a working DMA interface.  Best of luck and drop me a line if
  287. you find this useful.
  288.  
  289. <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  290. -- 
  291.         Doug Collinge
  292.         School of Music, University of Victoria,
  293.         PO Box 1700, Victoria, B.C., Canada,  V8W 2Y2  
  294.         collinge@uvunix.BITNET
  295.         decvax!uw-beaver!uvicctr!collinge
  296.         ubc-vision!uvicctr!collinge
  297.         __... ...__  _.. .  ..._ . __... __. _. .._  ..._._
  298.  
  299.  
  300.