#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.
| |||||||||
| int | fdc_getbyte () | ||||||||
Get a byte from the FDC controller.
| |||||||||
| 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.
| |||||||||
| void | fdc_recalibrate () | ||||||||
| Recalibrate the floppy drive. | |||||||||
| bool | fdc_seek (int track) | ||||||||
Seek a track.
| |||||||||
| 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.
| |||||||||
| 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).
| |||||||||
| bool | fdc_read (int block, byte *buffer, uint32_t count) | ||||||||
Read some contiguous blocks from the floppy disk.
| |||||||||
| bool | fdc_write (int block, byte *buffer, uint32_t count) | ||||||||
Write some contiguous blocks to the floppy disk.
| |||||||||
| bool | fdc_is_changed () | ||||||||
| Check if the floppy disk was changed. | |||||||||
| 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. | |||||||||
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. | |||||||||
| byte * | fdc_buffer | ||||||||
| Floppy r/w buffer. | |||||||||
Definition in file floppy.c.
|
|
Check if the floppy disk was changed.
Definition at line 411 of file floppy.c.
00412 {
00413 return(fdc_change);
00414 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||||||
|
Read some contiguous blocks from the floppy disk.
Definition at line 376 of file floppy.c.
|
|
|
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 }
|
|
|
Seek a track.
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 }
|
|
||||||||||||||||
|
Write some contiguous blocks to the floppy disk.
Definition at line 396 of file floppy.c.
|
|
|
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.
|
|
|
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 }
|
|
|
Initialize the floppy driver.
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 }
|
1.2.18