⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fl_drver.h

📁 ertfs文件系统里面既有完整ucos程序
💻 H
字号:
/*
* EBS - RTFS (Real Time File Manager)
*
* Copyright EBS inc., 1996
* All rights reserved.
* This code may not be redistributed in source or linkable object form
* without the consent of its author.
  Portable Floppy Disk Device driver.
*
*
*/


#if (USE_FLOPPY)

#define USE_DMA 1

/* Handy bit definitions */
#define BIT7 (byte) 0x80
#define BIT6 (byte) 0x40
#define BIT5 (byte) 0x20
#define BIT4 (byte) 0x10
#define BIT3 (byte) 0x08
#define BIT2 (byte) 0x04
#define BIT1 (byte) 0x02
#define BIT0 (byte) 0x01

/* Timing parameters */
#define FL_SPINUP       (ks_ticks_p_sec()*1) /* Milliseconds to delay on spin up */
#define MOTOR_TIMEOUT   4                    /* Seconds until we shut the motor off */
                                             /* Note: The units (4) are correct
                                                for MOTOR_TIMEOUT since the 
                                                floppy timer callback is called 
                                                once per second */
                                                

/* Timeout values in sys tick for various operations */
/* These are in ticks under smx */
#define FLTMO_IO        (6*ks_ticks_p_sec())        /* 6 sec Read or write */
#define FLTMO_FMTTRACK  (6*ks_ticks_p_sec())        /* 6 sec Format a track */
#define FLTMO_READID    (3*ks_ticks_p_sec())       /* 3 sec Read ID during establish media */
#define FLTMO_SEEK      (1*ks_ticks_p_sec())        /* 1 sek Seek to a track */
#define FLTMO_RECAL     (3*ks_ticks_p_sec())        /* 3 sec Recalibrate (seek to 0) */
#define FLTMO_RESET     (6*ks_ticks_p_sec())        /* 6 sec Wait for interrupt after reset */

/* Digital output register bits */
#define DORB_DSEL       BIT0
#define DORB_SRSTBAR    BIT2
#define DORB_DMAEN      BIT3
#define DORB_MOEN1      BIT4
#define DORB_MOEN2      BIT5
#define DORB_MODESEL    BIT7

/* Commands to the controller */
#define FL_SPECIFY           0x3    /* Specify drive timing */
#define FL_SENSE_STATUS      0x4    /* Read status register 3 */
#define FL_WRITE             0x5    /* Write block(s)  */
#define FL_READ              0x6    /* Read block(s)  */
#define FL_RECALIBRATE       0x7    /* Recalibrate */
#define FL_SENSE_INTERRUPT   0x8    /* Sense interrupt status */
#define FL_READID            0xa    /* Read sector id under head */
#define FL_FORMAT            0xd    /* Format track */
#define FL_SEEK              0xf    /* Seek to a cylinder */

/* Qualifier bits to read/write commands */
#define MFMBIT BIT6
#define MTBIT  BIT7

/* Arguments to specify command */
#define SP_1    (byte) 0xdf    /* step rate 3 milsec, head uload 240 */
#if (USE_DMA)
#define SP_2    (byte) 0x2     /* head load = 2ms, dma enabled */
#else
#define SP_2    (byte) 0x1     /* head load = 2ms, dma disabled */
#endif

/* Filler byte for use during format */
#define FORMAT_FILLER   0xf6

/* Error values */
#define FLERR_ABN_TERM                  1
#define FLERR_CHIP_HUNG                 2
#define FLERR_DMA                       3
#define FLERR_FORMAT                    4
#define FLERR_INVALID_INTERLEAVE        5
#define FLERR_IO_SECTOR                 6
#define FLERR_IO_TMO                    7
#define FLERR_MEDIA                     8
#define FLERR_RECAL                     9
#define FLERR_RESET                    10
#define FLERR_SEEK                     11
#define FLERR_SPECIFY                  12
#define FLERR_UNK_DRIVE                13 
#define FLERR_EXEC_EST                 14


/* Drive types as stored in the AT cmos eeprom. We use the same constants for
   established media type in the drive. */
#define DT_NONE 0
#define DT_360  1
#define DT_12   2
#define DT_720  3
#define DT_144  4
#define DT_288  5

/* Data rate register values */
#define DR_250  0x02
#define DR_300  0x01
#define DR_500  0x00
#define DR_1000 0x03

/* Values returned from fl_ready. - If it returns 0 the controller is not
   ready to accept or send data */
#define FL_FRHOST   1           /* Controller expecting data from host */
#define FL_TOHOST   2           /* Controller has data for host */

/* Gap values. nemonics make the drive description table easier to read */
/* GPF is gpl_format */
#define GPF_50 0x50
#define GPF_54 0x54
#define GPF_6C 0x6C
/* GPL is gpl_read */
#define GPL_2A 0x2A
#define GPL_1B 0x1B

typedef struct _fl_devparms {
    int drive_size;           /* 360,720,1200,1440,2880 */
    byte drive_type;           /* DT_360 et al. Drive type from AT cmos */
    byte media_type;           /* DT_360 et al. Media installed in drive */
    byte specify_1;            /* StepRate:Head Unload */
    byte specify_2;            /* HeadLoad:NonDma      */
    byte data_rate;            /* DR_250 et al */
    byte sectors_per_track;    
    byte cylinders_per_disk;
    byte gpl_read;             /* Gap durong read write */
    byte gpl_format;           /* Gap during format     */
} _FL_DEVPARMS;

typedef struct command_block
{
    byte data_rate_reg; /* Written to data rate register each time */
    int n_to_send;     /* Number of bytes to send in the command phase */
    int n_to_get;      /* Number of bytes expected in the results phase */
    int n_gotten;      /* Number gotten in the results phase */
    byte commands[10];  /* Sent during command phase */
    byte results[10];   /* Returned during results phase */
} COMMAND_BLOCK;



/* Each drive has one of these structures that we update one we know what the media type is */
typedef struct _floppy
{
    byte drive_type;           /* DT_360 et al. Drive type from AT cmos */
    byte media_type;           /* DT_NONE if not established */
    byte specify_1;            /* StepRate:Head Unload */
    byte specify_2;            /* HeadLoad:NonDma      */
    byte data_rate;            /* DR_250 et al */
    byte sectors_per_track;    
    byte sectors_per_cyl;    
    byte cylinders_per_disk;
    byte gpl_read;             /* Gap durong read write */
    BOOLEAN  double_step;
    word    last_cyl;
    word    last_head;
} _FLOPPY;


#if (USE_DMA)

#ifdef PROTECTED_MODE

#undef POINTER_SEGMENT
#undef POINTER_OFFSET
/* These macros are used only in pointer_to_linear().
   take a low memory bufer and return realmode style segment and offset */
#define POINTER_SEGMENT(X) RP_SEG(X)
#define POINTER_OFFSET(X)  RP_OFF(X)

typedef REALPTR DMAPTYPE
extern DMAPTYPE alloc_dma_buffer(void);
extern DMAPTYPE dma_buffer;
extern void WriteRealMem(DMAPTYPE real_to, byte *pm_from, int n);
extern void ReadRealMem(byte *pm_to, DMAPTYPE real_from , int n);
#else
typedef unsigned char KS_FAR * DMAPTYPE;
#define WriteRealMem(TO, FROM, N) far_copybuf((TO), (FROM), (N))
#define ReadRealMem(TO, FROM, N) far_copybuf((TO), (FROM), (N))

#if (defined(__BORLANDC__))
#define POINTER_SEGMENT(X) FP_SEG(X)
#define POINTER_OFFSET(X)  FP_OFF(X)
#else
#define POINTER_SEGMENT(X) _FP_SEG(X)
#define POINTER_OFFSET(X)  _FP_OFF(X)
#endif

#endif
#endif /* USE_DMA */

int floppy_perform_device_ioctl(int driveno, int opcode, PFVOID pargs);
BOOLEAN floppy_io(int driveno, dword l_sector, void KS_FAR *in_buffer, word count, BOOLEAN reading);

#endif


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -