Hi,
I want to connect a 3.5" disk drive to a 8051 (or faster compatible) controller. Has anyone done this before? Is any free or commercial source code available? I need only functions for reading, writing and deleting files in DOS format.
Michael
Hi,
I want to connect a 3.5" disk drive to a 8051 (or faster compatible) controller. Has anyone done this before? Is any free or commercial source code available? I need only functions for reading, writing and deleting files in DOS format.
Michael
Simple and easy way is to use a 'Super I/O' card ( maybe $5 these days..) and cut some code. I've done this for both 8052-BASIC and PIC16F877 chips. Easy way to add IDE/Floppy/SIO/PTR,etc. to micros hth jay
This is all the Bios functions.
This will help you get started.
You have a lot more homework to do.
A floppy disk is only FAT12. This will also give some good information.
As to the source, not a big deal, been doin' asm for years. Lots of info, esp. on the web, about.Once you get the memory map pegged down,get ahold of a good reference book( I used the IBM one,if i recall correctly, it has been about 10 years since I did this stuff)) and work out the printer port. Then then serial, then the floppy, then the hard drive. It's really not that tough to do. I did it as a 'mind challenge', something to keep the grey cells functioning.
As to the hardware, any 16 bit ISA Super I/o Card will work. I wirewrapped two edgeconnectors together to ease the wiring, then I found a 'daughterboard' extender for a desktop( old Tandy 1000 series, I think) which made life simpler. jay
_____________________________________ Murray R.Van Luyn Revolutionary Urban Guerilla. Ph: +618 9354 1375 E-mail: snipped-for-privacy@ses.curtin.edu.au snipped-for-privacy@cs.curtin.edu.au
Thanks for all answers!!!
Michael
Regarding reading/writing DOS format disks:
- If your requirements are simple, then you may be able to get by with my MDCFS (Minimal Dos Compatible File System). It is very small, consisting of a single .C source file. Here is the output of my CSTATS program when run against that file:
Characters: in file(s) : 18607 in comments : 10834 whitespace : 3280 significant : 4493 Lines: in file(s) : 680 blank/comment: 342 significant : 338 Cism's: '{'s : 38 '}'s : 38 ';'s : 212 comments : 111
Here is the main comment which describes it:
/* * MDCFS: Minimal Dos Compatible File System * * These routines provide the bare minimum needed to read and write * files on an MS-DOS format floppy disk. You could use them with a hard * disk as well, however since only 12 bit FAT's are supported, you are * limited to a total of 4096 clusters, and total drive space is limited * to 32MB due to 16 bit sector numbers (assuming 512 byte sectors). * * The functions were written for use in embedded systems (where memory * is often limited), and therefore provide only the basic open, read/write, * close and delete operations. I have documented the functions which * manipulate the directory and FAT, and it should be fairly easy to add * other features if you need them (directory display etc.). Only access to * files in the ROOT directory is provided, subdirectories are NOT supported. * * For simplicity and memory conservation, these functions buffer only 1 * sector (512 bytes) in memory. This makes them run quite slowly, but is * adaquate for reading/writing setup information and occational data logging. * If you have lots of memory and need extra speed, you could modify the * functions to read/write multiple sectors (a cluster would be easy). * You can also experiment with different interleave factors, to obtain * optimim performance with the existing I/O functions. * * As they stand, the functions really support access to only one drive * at a time. You can use multiple drives if you call "open_drive()" between * disk operations to the separate drives. This "switches" the active drive * to the specified one. Note however, that the selected drive will seek to * track zero each time this function is called, so performing many small * operations on more than one drive gets VERY inefficent. DO NOT read or * write to an open file located on any drive other than the currently * selected one! Call "open_drive()" first! * * Concurrent access to multiple files (on the same drive) is supported, * however since only one "work" buffer is used for directory/FAT access, * the drive may have to perform extra read/write operation when switching * from one file to the other. For this reason, it is best to try and do * as many reads or writes as possible on one file before accessing others. * Avoid many small operations to multiple files. * * At present, only the first copy of the disk File Allocation Table * (FAT) is used by these functions. * * Functions read/write data in RAW (binary) form, without regard for * NEWLINE characters etc. If you want to read/write ASCII text, you will * have to write "wrapper" functions to drop RETURN (0x0D) characters on * reading, and to add them before NEWLINE (0x0A) when writing. * * Due to the use of 'C' structures, Version 3.0 (or later) of MICRO-C * is REQUIRED! It should not be difficult to compile with a different * compiler, but I have not attempted to do so. * * You can compile this DEMO program to run under DOS with the MICRO-C * DOS compiler (available from our web page:
These are the main functions provided in the module:
/* * File accessing functions: * * open_drive(drive) - Initialize a drive for file access * drive - Drive id (0=A, 1=B ...) * * open_file(name, attrs) - Open file for read or write * name - Name of file to open * attrs - Open attributes: READ or WRITE * returns : Pointer to file structure, or 0 if failure * * close_file(fp) - Close an open file * fp - Pointer to open file structure * * read_byte(fp) - Read a byte from an open file * fp - Pointer to open file structure * returns : Value read (0-255), -1 if EOF, -2 if not open for read * * write_byte(byte, fp) - Write a byte to a file * byte - Value to write to file (0-255) * returns : Value written (0-255) or -2 if error * * delete_file(name) - Erases the named file * name - Name of file to erase * returns : 0 if Success, -1 if failure (file not found) * * * FAT manipulation functions: * * allocate(cluster) - Allocate a free cluster * cluster - Cluster to link this one to (0 if none). * returns : Cluster number allocated, 0 if failure * * release(cluster) - Release a cluster chain (if allocated) * cluster - Begining cluster to release * * get_fat(cluster) - Get FAT entry for cluster * cluster - Cluster number to obtain entry for * returns : Cluster number linked (0 if free, 0xFF8+ for EOF) * * set_fat(cluster, link) - Set the FAT entry for a cluster * cluster - Cluster number to set link for * link - Cluster number to link to (0=free, 0xFFF = EOF) * * * Directory manipulation functions: * * lookup(file) - Locate a files directory entry * file - Name of file to locate * returns : Pointer to directory entry, 0 if failure. * * create_file(file,attrs) - Create a mew file * file - Name of file to create * attrs - Attributes for file (0 = normal) * returns : Pointer to directory entry, 0 if failure. * * parse_filename(buffer,name) - Get filename in directory format * buffer - Buffer for directory format filename (13 bytes) * name - ASCII filename to convert * * memcmp(ptr1, ptr2, size) - Block memory compare * ptr1 - Pointer to first block * ptr2 - Pointer to second block * size - Number of bytes to compare * returns : -1 if match, 0 if different. */
These are the low-level disk I/O function which you will have to provide:
/* * Low level disk I/O functions: * * * read_sector(d, s, b) - Read a sector from the disk * d - Drive to read (0=A, 1=B ...) * s - Sector number to read (1-n) * b - Pointer to buffer to receive data * * write_sector(d, s, b) - Write a sector to the disk * d - Drive to write (0=A, 1=B ...) * s - Sector number to write (1-n) * b - Pointer to buffer containing the data * */
NOTE that MDCFS views the drive as a single array of sectors - you will have to provide the translation to your actual drive geometry (Cylinder, Head & Sector) within your drivers.
You can obtain MDCFS.C from EMBEDPC.ZIP avaialble on my web page.
Regards,
Have something to add? Share your thoughts — no account required.
Ask the community — no account required