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

📄 ide_drv.h

📁 ertfs文件系统里面既有完整ucos程序
💻 H
📖 第 1 页 / 共 2 页
字号:
/*
* 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 IDE Device driver.
*
*
*/

#if (USE_ATA)

    /* Don't allow more then 128 blocks (64K) for fear of a segment wrap. */
#define MAX_BLOCKS  128


/* Function prototypes */
 /* Timeout values - These indicate how long we will wait until deciding
    that an operation has failed. Set these high if you are not worried about
    bus latches. Values are in ticks */
#define TIMEOUT_RDWR  (4*ks_ticks_p_sec())      /*  4 second for a multiblock read or write
                                                    transfer to take. This is from start to finish.
                                                    We can't diddle the timer on each interrupt of
                                                    a multiblock transfer */
#define TIMEOUT_DIAG    (12*ks_ticks_p_sec())   /* 12 seconds maximum to complete diagnostics */
#define TIMEOUT_RESET   (12*ks_ticks_p_sec())   /* 2 seconds maximum to complete reset */
#define TIMEOUT_TYPICAL (12*ks_ticks_p_sec())   /* Max ticks for other commands not listed*/
#define TIMEOUT_FORMAT  (3*60*ks_ticks_p_sec()) /* three minute timeout on format */


/* Error codes. One  will be in c_s.error_code if an ide function fails. */
#define IDE_ERC_DIAG        1   /* Drive diagnostic failed in initialize */
#define IDE_ERC_ARGS        2   /* User supplied invalid arguments */
#define IDE_ERC_BUS         3   /* DRQ should be asserted but it isn't
                                    or driver and controller are out of phase*/
#define IDE_ERC_TIMEOUT     4   /* Timeout during some operation */
#define IDE_ERC_STATUS      5   /* Controller reported an error look in the error register */ 
#define IDE_ERC_BAD_CMD     6   /* Drive does't support command */                                  

/* Register file address offsets */
/* offsets for read ops and for write ops (where write==read) */
#define IDE_OFF_DATA                0
#define IDE_OFF_ERROR               1
#define IDE_OFF_FEATURE             1
#define IDE_OFF_SECTOR_COUNT        2
#define IDE_OFF_SECTOR_NUMBER       3
#define IDE_OFF_CYL_LOW             4
#define IDE_OFF_CYL_HIGH            5
#define IDE_OFF_DRIVE_HEAD          6
#define IDE_OFF_STATUS              7
#if (USE_CONTIG_IO)
#define IDE_OFF_ALT_STATUS          0xe
#define IDE_OFF_DRIVE_ADDRESS       0xf
#else
#define IDE_OFF_ALT_STATUS          0x206
#define IDE_OFF_DRIVE_ADDRESS       0x207
#endif
/* offsets for write ops when register usage differs from read. */
#define IDE_OFF_PRECOMP     IDE_OFF_ERROR
#define IDE_OFF_DIG_OUTPUT  IDE_OFF_ALT_STATUS
#define IDE_OFF_COMMAND     IDE_OFF_STATUS

/* Commands: These are placed in the command register to start an operation.
            The values put into the other registers are context dependent */

#define IDE_LONG_MASK                   0x02    /* Mask in to read/write ECC on 
                                                CMD_IDE_READS, CMD_IDE_WRITES */
#define IDE_RETRY_MASK                  0x01    /* Mask in to enable drive retries 
                                                CMD_IDE_READS, CMD_IDE_WRITES 
                                                CMD_IDE_READV */
#define IDE_CMD_READS                   0x20    /* Read sector(s) */
#define IDE_CMD_WRITES                  0x30    /* Write sector(s) */
#define IDE_CMD_WRITES_NE               0x38    /* Write sector(s) No pre-erase */
#define IDE_CMD_ERASES                  0xC0    /* Erase sector(s) */
#define IDE_CMD_DIAG                    0x90    /* Initiate drive diagnostics */
#define IDE_CMD_INITP                   0x91    /* Initialize drive parameters */
#define IDE_CMD_READM                   0xC4    /* Read multiple sectors/interrupt */
#define IDE_CMD_WRITEM                  0xC5    /* Write multiple sectors/interrupt */
#define IDE_CMD_WRITEM_NE               0xCD    /* Write multiple No pre-erase */
#define IDE_CMD_SETM                    0xC6    /* Set multiple mode */
#define IDE_CMD_IDENT                   0xEC    /* Return drive parameters */
#define IDE_CMD_SETF                    0xEF    /* Set Features */
#define IDE_CMD_GET_MEDIA_STATUS        0xDA    /* GET THE MEDIA STATUS */
#define IDE_CMD_SOFT_RESET              0x08    /* Soft Reset */

#define ATAPI_CMD_IDENT                 0xA1            /* Return drive parameters */
#define ATAPI_CMD_PKT                   0xA0            /* ATAPI Packet command */
#define ATAPI_CMD_GETMS                 0xDA            /* ATAPI GET MEDIA STATUS */ 
#define ATAPI_CMD_SERVICE               0xA2            /* ATAPI SERVICE */             /* CDROM Jerry */

#define ATAPI_PKT_CMD_READ              0x28    /* ATAPI PACKET READ COMMAND */
#define ATAPI_PKT_CMD_WRITE             0x2A    /* ATAPI PACKET WRITE COMMAND */
#define ATAPI_PKT_CMD_MODE_SENSE        0x5A    /* ATAPI MODE SENSE */          
#define ATAPI_PKT_CMD_TEST_UNIT_READY   0x00    /* ATAPI TEST UNIT READY */
#define ATAPI_PKT_CMD_FORMAT_UNIT       0x04    /* ATAPI FORMAT UNIT */
#define ATAPI_PKT_CMD_OLD_FORMAT_UNIT   0x24    /* ATAPI FORMAT UNIT */
#define ATAPI_PKT_CMD_REQUEST_SENSE     0x03    /* ATAPI CDROM Jerry */
#define ATAPI_PKT_CMD_START_STOP_UNIT   0x1B    /* Start Stop eject */


#define IDE_FEATURE_SETPERF             0x9A     /* Set Perfomance Option */
#define IDE_FEATURE_WCACHE_ON			0x02     /* Enable the write cache */
#define IDE_FEATURE_DEFECT_ON			0x04     /* Enable the defect re-assignment */
#define IDE_FEATURE_RLOOK_ON			0xAA     /* Enable read look-ahead */

#define IDE_FEATURE_SETPERF_VALUE       0xff     /* Default. Max performance (current) */



/*                          ============                                */

/* Error bits: These bits are returned in the error register. They are valid
                only if the error bit in the status register is set. */
#define IDE_ERB_AMNF        0x01            /* Address mark not found */
#define IDE_ERB_RECAL       0x02            /* Seek failed during recal */
#define IDE_ERB_ABORT       0x04            /* Drive error (write fault etc)
                                                or invalid command code */
#define IDE_ERB_MCR         0x08            /* Media change request */
#define IDE_ERB_IDNF        0x10            /* Read/Write or Seek failed
                                                requested sector not found */
#define IDE_ERB_MC          0x20            /* Media change requested */
#define IDE_ERB_UNC         0x40            /* Uncorrectable data error */
#define IDE_ERB_BADBLK      0x80            /* Requested Block Is Bad */
/*                          ============                                */

/* Status bits: These bits are returned in the status register. If the 
                busy bit is set no other bits are busy              */
#define IDE_STB_ERROR       0x01            /* Error occured: consult error reg */
#define IDE_STB_INDEX       0x02            /* Pulses as the disk rotates */
#define IDE_STB_CORRECTED   0x04            /* The drive had to use ECC on the data */
#define IDE_STB_DRQ     0x08            /* Drive will send or accept data */
#define IDE_STB_ONTRACK 0x10            /* Set when the head is on track */
#define IDE_STB_WFAULT      0x20            /* Drive write fault occured */
#define IDE_STB_READY       0x40            /* Drive is up and spinning if 1 */
#define IDE_STB_BUSY        0x80            /* Drive side cpu is busy. It owns
                                                the register file now. All register
                                                File accesses from the host side
                                                will return status register 
                                                contents */
#define IDE_IRR_IO          0x02
#define IDE_IRR_CoD         0x01                                                

/* Digital output register: Bitwise command latch */
#define IDE_OUT_IEN         0x02            /* Enable AT bus's IRQ14 line */
#define IDE_OUT_RESET       0x04            /* Hold high for 10 uSecs to
                                                reset drives */ 
                                                
#define HIMAWARI_FLEXIBLE_DISK_PAGE_CODE    0x05

typedef struct transfer_length
    {
    byte    msb;
    byte    lsb;
    }   TRANSFER_LENGTH;
                                                
typedef struct  himawari_flexible_disk_page
    {
    byte    page_code;                      /* should be x000 0101 */
    byte    page_length;                    /* should be 0001 1110 */
    byte    transfer_rate_msb;
    byte    transfer_rate_lsb;
    byte    number_of_heads;
    byte    sectors_per_track;
    byte    bytes_per_cylinder_msb;
    byte    bytes_per_cylinder_lsb;
    byte    number_of_cylinders_msb;
    byte    number_of_cylinders_lsb;
    byte    reserved1[10];
    byte    motor_off_delay;
    byte    swp_swpp;
    byte    reserved2[6];
    byte    medium_rotation_rate_msb;
    byte    medium_rotation_rate_lsb;
    byte    reserved3[2];
    } HIMAWARI_FLEXIBLE_DISK_PAGE;
    
typedef struct  Himawari_defect_list_header
    {
    byte    reserved;
    byte    control_byte;
    byte    length_msb;
    byte    length_lsb;
    }   HIMAWARI_DEFECT_LIST_HEADER;
    
typedef struct  Himawari_formattable_capacity_descriptor
    {
    byte    number_of_blocks[4];                            /*Big Endian format*/
    byte    reserved;
    byte    block_length[3];                                /*Big Endian format*/
    }   HIMAWARI_FORMATTABLE_CAPACITY_DESCRIPTOR;       
    
typedef struct  Himawari_format_descriptor
    {
    HIMAWARI_DEFECT_LIST_HEADER                 dlheader;
    HIMAWARI_FORMATTABLE_CAPACITY_DESCRIPTOR    capacity_descriptor;

⌨️ 快捷键说明

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