Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

floppy.c File Reference

Floppy disk driver. More...

#include <const.h>
#include <arch/i386.h>
#include <arch/interrupt.h>
#include <arch/mem.h>
#include <arch/paging.h>
#include <kernel/clock.h>
#include <kernel/console.h>
#include <kernel/dma.h>
#include <kernel/task.h>
#include <kernel/floppy.h>

Go to the source code of this file.

Functions

void fdc_sendbyte (byte b)
 Send a byte to the FDC controller.
Parameters:
b  The byte to send.


int fdc_getbyte ()
 Get a byte from the FDC controller.
Returns:
The byte read from the controller.
Exceptions:
NULL  If timeout is elapsed.


void fdc_motor_on ()
 Turn the floppy motor on.

void fdc_motor_off ()
 Starts the FDC motor kill countdown.

bool fdc_wait (bool sensei)
 Wait for a FDC operation.
Parameters:
sensei 
  • TRUE if a "sense interrupt status" command is required;
  • FALSE for a simple timeout wait.
Returns:
  • TRUE if the operation has successfully done;
  • FALSE if the timeout has been elapsed.


void fdc_recalibrate ()
 Recalibrate the floppy drive.

bool fdc_seek (int track)
 Seek a track.
Parameters:
track  The track to seek.
Returns:


void fdc_reset ()
 Reset the floppy disk controller.

void lba2chs (int lba, int *track, int *head, int *sector)
 Convert from a LBA (Linear Block Address) address to a CHS (Cylinder, Head, Sector) coordinates.
Parameters:
lba  The LBA address.
track  A pointer to the track coordinate.
head  A pointer to the head coordinate.
sector  A pointer to the sector coordinate.


bool fdc_rw (int block, byte *buffer, bool do_read)
 Perform a read/write operation with the floppy drive using the DMA (Direct Memory Access).
Parameters:
block  The LBA address of the block on the floppy.
buffer  The address of the buffer in memory for the transfer operation. It must have a size of at least FDC_SECTOR_SIZE bytes.
do_read 
  • TRUE to perform a read operation (from disk to memory);
  • FALSE to perform a write operation (from memory to disk).
Returns:


bool fdc_read (int block, byte *buffer, uint32_t count)
 Read some contiguous blocks from the floppy disk.
Parameters:
block  The starting block to read.
buffer  The destination buffer in memory where the blocks will be copied.
count  How many blocks to read.
Returns:


bool fdc_write (int block, byte *buffer, uint32_t count)
 Write some contiguous blocks to the floppy disk.
Parameters:
block  The starting block to write.
buffer  The address in memory from which the data will be copied.
count  How many blocks to write.
Returns:


bool fdc_is_changed ()
 Check if the floppy disk was changed.
Returns:
  • TRUE if the disk was changed;
  • FALSE otherwise.


void floppy_thread ()
 This is a routine called from clock_thread() at every clock tick to perform the floppy motor kill countdown and to control the floppy timeouts.

void floppy_handler ()
 This is the floppy interrupt handler routine. It is invoked every time that a floppy operation successfully completes.

bool init_floppy ()
 Initialize the floppy driver.
Returns:



Variables

volatile bool fdc_motor = FALSE
 Motor on flag.

volatile int fdc_timeout = 0
 FDC timeout.

volatile int fdc_motor_countdown = 0
 Floppy motor kill countdown.

volatile bool fdc_done = FALSE
 FDC operation finish.

volatile bool fdc_change = FALSE
 Disk change flag.

volatile byte fdc_status [7] = { 0 }
 FDC status (result output).

volatile byte fdc_track = 0xFF
 Current head position.

volatile byte ST0 = 0
 Status register 0.

floppy_struct floppy_type []
 Floppy types known from the system.

byte fdc_geometry = 0
 Current floppy geometry.

bytefdc_buffer
 Floppy r/w buffer.


Detailed Description

Floppy disk driver.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update: 2003-11-08
Note:
Copyright (©) 2003 Andrea Righi

Definition in file floppy.c.


Function Documentation

bool fdc_is_changed  
 

Check if the floppy disk was changed.

Returns:
  • TRUE if the disk was changed;
  • FALSE otherwise.

Definition at line 411 of file floppy.c.

00412 {
00413         return(fdc_change);
00414 }

void fdc_motor_off  
 

Starts the FDC motor kill countdown.

Definition at line 116 of file floppy.c.

00117 {
00118         if (fdc_motor && (fdc_motor_countdown==-1))
00119                 fdc_motor_countdown = FDC_TIME_MOTOR_OFF/1000*HZ;
00120 }

void fdc_motor_on  
 

Turn the floppy motor on.

Definition at line 104 of file floppy.c.

00105 {
00106         if (!fdc_motor)
00107         {
00108                 outportb(FDC_DOR, 0x1C);
00109                 delay(FDC_TIME_MOTOR_SPINUP);
00110                 fdc_motor = TRUE;
00111         }
00112         fdc_motor_countdown = -1;
00113 }

bool fdc_read int    block,
byte   buffer,
uint32_t    count
 

Read some contiguous blocks from the floppy disk.

Parameters:
block  The starting block to read.
buffer  The destination buffer in memory where the blocks will be copied.
count  How many blocks to read.
Returns:

Definition at line 376 of file floppy.c.

00377 {
00378         register int i;
00379 
00380         for(i=0; i<count; i++)
00381                 if (!(fdc_rw(block+i, buffer+(FDC_SECTOR_SIZE*i), TRUE)))
00382                         return(FALSE);
00383         // Read operation OK! //
00384         return(TRUE);
00385 }

void fdc_recalibrate  
 

Recalibrate the floppy drive.

Definition at line 178 of file floppy.c.

00179 {
00180         // Turn the motor on //
00181         fdc_motor_on();
00182 
00183         // Send recalibrate command //
00184         fdc_sendbyte(CMD_RECAL);
00185         fdc_sendbyte(0);
00186 
00187         // Wait until recalibrate command is finished //
00188         fdc_wait(TRUE);
00189 
00190         // Turn the motor off //
00191         fdc_motor_off();
00192 }

bool fdc_seek int    track
 

Seek a track.

Parameters:
track  The track to seek.
Returns:

Definition at line 199 of file floppy.c.

00200 {
00201         // If already threre return //
00202         if (fdc_track == track)
00203                 return(TRUE);
00204 
00205         // Turn the motor on //
00206         fdc_motor_on();
00207 
00208         // Send seek command //
00209         fdc_sendbyte(CMD_SEEK);
00210         fdc_sendbyte(0);
00211         fdc_sendbyte(track);
00212 
00213         // Wait until seek is finished //
00214         if (!fdc_wait(TRUE))
00215         {
00216                 // Timeout! //
00217                 fdc_motor_off();
00218                 return(FALSE);
00219         }
00220 
00221         // Let the head settle for 15msec //
00222         delay(15);
00223 
00224         // Turn off the motor //
00225         fdc_motor_off();
00226 
00227         // Check if seek worked //
00228         if ((ST0 != 0x20) || (fdc_track != track))
00229                 return(FALSE);
00230         else
00231                 return(TRUE);
00232 }

bool fdc_write int    block,
byte   buffer,
uint32_t    count
 

Write some contiguous blocks to the floppy disk.

Parameters:
block  The starting block to write.
buffer  The address in memory from which the data will be copied.
count  How many blocks to write.
Returns:

Definition at line 396 of file floppy.c.

00397 {
00398         register int i;
00399 
00400         for(i=0; i<count; i++)
00401                 if (!(fdc_rw(block+i, buffer+(FDC_SECTOR_SIZE*i), FALSE)))
00402                         return(FALSE);
00403         // Write operation OK! //
00404         return(TRUE);
00405 }

void floppy_handler  
 

This is the floppy interrupt handler routine. It is invoked every time that a floppy operation successfully completes.

Definition at line 440 of file floppy.c.

00441 {
00442         fdc_done = TRUE;
00443 }

void floppy_thread  
 

This is a routine called from clock_thread() at every clock tick to perform the floppy motor kill countdown and to control the floppy timeouts.

Definition at line 422 of file floppy.c.

00423 {
00424         if (fdc_timeout > 0)
00425                 fdc_timeout--;
00426 
00427         if (fdc_motor_countdown > 0)
00428                 fdc_motor_countdown--;
00429         else if (fdc_motor && !fdc_motor_countdown)
00430         {
00431                 outportb(FDC_DOR, 0x0C);
00432                 fdc_motor = FALSE;
00433         }
00434 }

bool init_floppy  
 

Initialize the floppy driver.

Returns:

Definition at line 451 of file floppy.c.

00452 {
00453         int v;
00454 
00455         // Install the interrupt handler routine                        //
00456         install_irq_handler( FLOPPY_IRQ, (void *)floppy_handler );
00457 
00458         // Create the FDC buffer //
00459         fdc_buffer = PHYSICAL( dma_phys_alloc(PAGE_SIZE) );
00460 
00461         // Reset the controller //
00462         fdc_reset();
00463 
00464         // Get floppy controller version //
00465         fdc_sendbyte(CMD_VERSION);
00466         v = fdc_getbyte();
00467 
00468         switch ( v )
00469         {
00470                 case 0xFF:
00471                         return( FALSE );
00472                 break;
00473 
00474                 case 0x90:
00475                         kprintf("\n\rEnhanced controller found!");
00476                         return( TRUE );
00477                 break;
00478 
00479                 default:
00480                         kprintf("\n\r8272A/765A controller found! (cmd_version=%02X)", v);
00481                         return( TRUE );
00482                 break;
00483         }
00484 }


Generated on Fri Feb 20 15:32:18 2004 for Minirighi by doxygen1.2.18