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

📄 ata_pcc.h

📁 PDA上的CF CARD 文件系统的建立程式
💻 H
字号:
/*********************************************************************
;*                                                                   *
;*                INSTUTITE FOR INFORMATION INDUSTRY                 *
;*                        ATA HEADER -- ATA                          *
;*                         APRIL 30, 1998                            *
;*                                                                   *
;********************************************************************/
#ifndef _FAT_ATA_H
#define _FAT_ATA_H

//#include "stddefs.h"

/**** added by chilong 8/21/2001 ****/
//#define ATA_MOVE_DATA_BY_DMA
/**** added by chilong 8/21/2001 ****/

/********************************************************************/
/*                                                                  */
/*                      Gloabal Definitions                         */
/*                                                                  */
/********************************************************************/

/*--------------------[ ATA USED PORT-ADDRESS ]---------------------*/

#define PRIMARY_IDE     0
#define SECOND_IDE      0

// irvin , Because the system A1 connected to A0 , the address must "<<1"
/* marked by chilong 01/30/2002
#define DATA_REG        (0x0 << 1)
//#define ERROR_REG       (0x1 << 1)
#define COUNT_REG       (0x2 << 1)
#define SECTOR_REG      (0x3 << 1)
#define CYLINDER_L_REG  (0x4 << 1)
#define CYLINDER_H_REG  (0x5 << 1)
#define DEV_HEADER_REG  (0x6 << 1)
#define STATUS_REG      (0x7 << 1)
#define COMMAND_REG     (0x7 << 1)
   marked by chilong 01/30/2002 */
   
/**** modified by chilong 01/30/2002 ****/
#define DATA_REG        (0x0)
//#define ERROR_REG       (0x1 << 1)
#define COUNT_REG       (0x2)
#define SECTOR_REG      (0x3)
#define CYLINDER_L_REG  (0x4)
#define CYLINDER_H_REG  (0x5)
#define DEV_HEADER_REG  (0x6)
#define STATUS_REG      (0x7)
#define COMMAND_REG     (0x7)
/**** modified by chilong 01/30/2002 ****/

// We need to access the error reg. from "Dup. Error" , because /CE1,/CE2 shorted (always word access)
#define DUP_ERROR_REG   (0xD)


// irvin
//#define ALTER_REG       0x206   /* 0x1F0 + 0x206 = 0x3F6 */
//#define CONTROL_REG     0x206
//#define ADDRESS_REG     0x207

/*---------------------[  ATA USED STATUS FLAG  ]-------------------*/
// chilong: compared to ata.h, we append two zeroes at the end because
//      CF card only puts useful data in even bytes.

#define ATA_COMMAND_BUSY         0x8000    // BSY
#define ATA_DRIVE_READY          0x4000    // RDY
#define ATA_COMMAND_ERROR        0x0100    // ERR
#define ATA_DATA_READY           0x0800    // DRQ, 1: data can be transfered
#define ATA_BUSY_OR_ERROR        0x8100
#define ATA_DATA_ERROR_AND_READY 0x0900

/*
#define ATA_COMMAND_BUSY         0x80    // BSY
#define ATA_DRIVE_READY          0x40    // RDY
#define ATA_COMMAND_ERROR        0x01    // ERR
#define ATA_DATA_READY           0x08    // DRQ, 1: data can be transfered
#define ATA_BUSY_OR_ERROR        0x81
#define ATA_DATA_ERROR_AND_READY 0x09
*/
/*------------------[ ATA USED HARDDISK DEVICE ]--------------------*/

#define ATA_MASTER_DRV          0xA0    /*10100000B*/
#define ATA_SLAVER_DRV          0xB0    /*10110000B*/
#define ATA_LBA_MODE            0x40    /*01000000B*/
#define DISABLE_ATA_IRQ         0x02    /*00000010B*/
#define ENABLE_ATA_IRQ          0x00    /*00000000B*/

/*-----------------[ PARAMETER ADDREESS CONSTANT ]------------------*/

#define COUNT_ADDR              0
#define SECTOR_START_ADDR       1
#define HEADER_START_ADDR       2
#define CYLINDER_L_ADDR         3
#define CYLINDER_H_ADDR         4

/*-----------------[ ATA COMMAND ERROR REG MASK ]------------------*/

#define ERR_BBK                 0x80
#define ERR_UNC                 0x40
#define ERR_IDNF                0x10
#define ERR_ABRT                0x04
#define ERR_AMNF                0x01

#define ERR_ALL                 ( ERR_BBK | ERR_UNC | ERR_IDNF | ERR_ABRT | ERR_AMNF )

/*----[ ATA Drive Diagnostic COMMAND return value in ERROR REG ]----*/
#define DIAG_ERR_NO             0x01
#define DIAG_ERR_FMT            0x02
#define DIAG_ERR_SEC_BUF        0x03
#define DIAG_ERR_ECC            0x04
#define DIAG_ERR_CTRL           0x05

#define DIAG_ERR_IDE            0x80


/*-----------------[ ATA COMMAND EXECUTED RESULT ]------------------*/

#define ATA_OK                  0x00
#define ATA_FAILURE             0xff

// Bad Block is detected
#define ATA_FAIL_BBK            0x10
// Uncorrectable error is encountered
#define ATA_FAIL_UNC            0x11
// the requested sector ID is in error or cannot be found
#define ATA_FAIL_IDNF           0x12
// the command is aborted because of CompactFlash Card status (not ready , write fail , etc. )
#define ATA_FAIL_ABRT           0x13
// general error
#define ATA_FAIL_AMNF           0x14

// *******   diagnostic error return value
// formatter device error
#define ATA_FAIL_DIAG_FMT       0x21
// sector buffer error
#define ATA_FAIL_DIAG_SEC_BUF   0x22
// ECC circuitry  error
#define ATA_FAIL_DIAG_ECC       0x23
// controlling microprocessor error
#define ATA_FAIL_DIAG_CTRL      0x24
// the other error return  from diagnost
#define ATA_FAIL_DIAG_ERR       0x25



/*------------------------[ ATA COMMAND SET ] ----------------------*/

#define POWER_CHK_ATA_CMD       0x0E5
#define DIAG_ATA_CMD            0x090
#define ERASE_SEC_ATA_CMD       0x0C0
#define FORMAT_TRK_ATA_CMD      0x050
#define ID_ATA_CMD              0x0EC
#define IDLE_ATA_CMD            0x0E3
#define IDLE_IM_ATA_CMD         0x0E1
#define INIT_PARM_ATA_CMD       0x091

#define READ_BUF_ATA_CMD        0x0E4
#define MREAD_ATA_CMD           0x0C4
#define LREAD_ATA_CMD           0x022
#define READ_ATA_CMD            0x020
#define VREAD_ATA_CMD           0x040

#define RECALIBRATE_ATA_CMD     0x010

#define REQUEST_ATA_CMD         0x003
#define SEEK_ATA_CMD            0x070
#define SET_FEATURE_ATA_CMD     0x0EF
#define SET_MULTIPE_ATA_CMD     0x0C6
#define SET_SLEEP_CMD           0x0E6
#define STAND_BY_ATA_CMD        0x0E2
#define STAND_BY_IM_ATA_CMD     0x0E0
#define TRANS_SEC_ATA_CMD       0x087
#define WEAR_LEVEL_ATA_CMD      0x0F5

#define WRITE_BUF_ATA_CMD       0x0E8
#define WRITE_ATA_CMD           0x030
#define LWRITE_ATA_CMD          0x032
#define MWRITE_ATA_CMD          0x0C5
#define MWRITE_NO_ERASE_ATA_CMD 0x0CD
#define WRITE_NO_ERASE_ATA_CMD  0x038
#define WRITE_VERIFY_ATA_CMD    0x03C

/*--------------------[ DISK RELATED CONSTANTS ] -------------------*/

#define SECTOR_SIZE             512
#define WORDS_PER_SECTOR        (SECTOR_SIZE / 2)
#define NO_OF_RESERVED_CLUSTER  2
#define FAT_TIMEOUT             10      // in seconds

/********************************************************************/
/*                                                                  */
/*      Function Prototypes                                         */
/*                                                                  */
/********************************************************************/

/*=====================[ ATA-2 COMMAND Related ]====================*/

unsigned short WAIT_COMMAND_AVAILABLE(int, unsigned long);
unsigned short GET_ERROR_RESULT(int driver);
unsigned short WAIT_COMMAND_RESULT(int, unsigned long);
unsigned short ATA_GET_PARAMETER(int, unsigned short *);

unsigned short ATA_READ_SECTOR(int, unsigned char, unsigned long, unsigned short *);
unsigned short ATA_WRITE_SECTOR(int, unsigned char, unsigned long, unsigned short *);
unsigned short ATA_READ(int, unsigned char, unsigned long, unsigned short *);
unsigned short ATA_WRITE(int, unsigned char, unsigned long, unsigned short *);
//short           ATA_DISABLE_IRQ14(int);
//short           ATA_ENABLE_IRQ14(int);
//void            SOFTWARE_RESET(void);
//void            ATA_DELAY(int driver);
unsigned short ATA_WRITE_VERIFY(int driver, unsigned long startSec, unsigned short *buf);
unsigned short ATA_DRIVE_DIAG(int driver);


/**** added by chilong 8/21/2001 ****/
#ifdef ATA_MOVE_DATA_BY_DMA

unsigned short ATA_READ_SECTOR_BY_DMA(int driver , unsigned char secCount , unsigned short * pDest );
unsigned short ATA_WRITE_SECTOR_BY_DMA(int driver , unsigned char secCount , unsigned short * pSrc );

#endif

/**** added by chilong 8/21/2001 ****/

/*========================[ ATA-2 COMMAND End ]=====================*/


/********************************************************************/
/*                                                                  */
/*      Structures                                                  */
/*                                                                  */
/********************************************************************/

struct FAT_C_H_S
{
   unsigned char CylLow;
   unsigned char CylHigh;
   unsigned short Cylinder;
   unsigned char Head;
   unsigned char Sector;

   /**** added by chilong ****/
   unsigned short driveSerialNum[10];
   /**** added by chilong ****/
};

struct FAT_sectorCache
{
  unsigned long sec_no;                 /* the clsuter number of the cached cluster */
  unsigned short *buffer;       /* pointer to cache buffers */
  unsigned long luCount;        /* the use count */
  int dirty;                    /* TRUE means this buffer has been modified */
};


extern void FAT_logical_sector_to_chs(unsigned long sectorNO, struct FAT_C_H_S *p);



#endif

⌨️ 快捷键说明

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