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

📄 atapi.h

📁 Cy68013的应用——USB2.0接口转IDE、CF卡接口
💻 H
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
//   File:      atapi.h
//   Contents:   Header file
//
// Copyright (c) 1999-2002 Cypress Semiconductor, Inc. All rights reserved
//
// $Workfile: atapi.h $
// $Date: 7/16/02 9:49a $
// $Revision: 23 $
//-----------------------------------------------------------------------------
#ifndef ATAPI_H
#define ATAPI_H

///////////////////////////////////////////////////////////////////////////////
// Configuration Settings
///////////////////////////////////////////////////////////////////////////////

// APM_VALUE - ATA Device Automatic Power Management Value. If an attached ATA
// device supports APM and this field contains other than 0x00, the Initialization
// state machines will issue a SET FEATURES command to Enable APM with the register
// value during the drive initialization process. Setting APM Value to 0x00 disables
// this functionality. This register value is ignored with ATAPI devices. 
#define APM_VALUE                   0x00

// ATA_INIT_TIMEOUT - Time in 128 millisecond granularity before the firmware
// stops polling the ALT STAT register for reset complete and restarts the reset
// process (0x80 = 16.4 seconds).
#define ATA_INIT_TIMEOUT            0x80

// ATA_UDMA_ENABLE - Enable Ultra Mode data transfer support for ATA devices. If
// enabled, AND the ATA device reports UDMA support, the firmware will utilize
// UDMAdata transfers.
#define ATA_UDMA_ENABLE             TRUE

// ATAPI_UDMA_ENABLE - Enable Ultra Mode data transfer support for ATAPI devices.
// If enabled,AND the ATAPI device reports UDMA support, the CY7C68200 will
// utilizeUDMA data transfers.
#define ATAPI_UDMA_ENABLE           TRUE

// WAIT_FOR_BUSY_BIT - If set to TRUE, enables a delay of up to 120ms at each
// read of the DRQ bit where the device data length does not match the host data
// length. This allows the firmware to work with most devices that incorrectly
// clear the BUSY bit before a valid status is present.
#define WAIT_FOR_BUSY_BIT           FALSE

// SHORT_PACKET_BEFORE_STALL - Determines if a short packet is sent prior to
// the STALL ofan IN endpoint. The USB Mass Storage Class Bulk-Only
// Specification allows a device to send a short or zero-length IN packet
// prior to returning a STALL handshake for certain cases. Certain host
// controller drivers may require a short packet prior to STALL.
#define SHORT_PACKET_BEFORE_STALL   TRUE

// SRST_ENABLE - If srt to TRUE, firmware will perform a SRST reset during
// drive initialization. Note: At least one reset must be en-abled.
// Do not set SRST to FALSE and Skip Pin Reset to TRUE at the
// same time.
#define SRST_ENABLE                 TRUE

// SKIP_PIN_RESET - Skip ATA_NRESET assertion. Note: SRST Enable must be
// set in conjunction with Skip Pin Reset. Setting this bit causes the
// firmware to bypass ARESET# during initialization.  All reset events except
// a power-on reset utilize SRST as the drive mechanism.
//
// FALSE = Allow ARESET# assertion for all resets.
// TRUE  = Disable ARESET# assertion except for power-on reset cycles.
#define SKIP_PIN_RESET              TRUE

// UDMA_MODES - These bits select which UDMA modes, if supported, are
// enabled. Setting to 1 enables. Multiple bits may be set. The
// firmware will operate in the highest enabled UDMA mode supported by
// the device. 
//
// Recommended Setting: 0x14 (UDMA mode2 and mode4 only)
#define UDMA_MODES                  0x14

// PIO_MODES - These bits select which PIO modes, if supported, are
// en-abled.  Setting to 1 enables. Multiple bits may be set. The
// firmware will operate in the highest enabled PIO mode supported by
// the device. The firmware supports PIO modes 0, 3, and 4 only. PIO
// mode 0 is always enabled.
// Bit Descriptions
// 1 Enable PIO mode 4.
// 0 Enable PIO mode 3.
#define PIO_MODES                   0xFF

// ATA_ENABLE_PIN - If set to TRUE, the firmware will periodically check
// for tri-state signal on WAKEUP pin
#define ATA_ENABLE_PIN              FALSE

// USE_ATA_DEVICE_SERIAL_NUMBER - For ATA devices, determines if the firmware
// uses the serial number reported by the device as the USB serial number.
// If TRUE, firmware uses the serial number reported by the device in
// response to IDENTIFY_DEVICE command.  If FALSE, the firmware sets
// the USB serial number index to 0 (i.e. no serial number string is
// reported in the device descriptor).
//
// Recommended Setting: FALSE
#define USE_ATA_DEVICE_SERIAL_NUMBER      FALSE

// USE_ATAPI_DEVICE_SERIAL_NUMBER - For ATAPI devices, determines
// if the firmware uses the serial number reported by the device as
// the USB serial number. If TRUE, firmware uses the serial number
// reported by the device in response to IDENTIFY_DEVICE command. 
// If FALSE, the firmware sets the USB serial number index to 0
// (i.e. no serial number string is reported in the device descriptor).
// Many ATAPI devices do not report a unique serial number.  It is 
// better to report no serial number than to report a non-unique
// serial number.
//
// Recommended Setting: FALSE 
#define USE_ATAPI_DEVICE_SERIAL_NUMBER    FALSE

// NIBBLE_CONVERT_SERIAL_NUMBER - Determines if the firmware converts
// each nibble of the serial number reported by the device into a
// single character of the USB serial number.  The Bulk-only mass
// storage class spec only allows HEX characters (0-9 and A-F) in the
// device serial number.  Some devices report other ASCII characters.
// Converting each nibble into HEX assures spec compliance while
// maintaining the uniqueness of the serial number.
//
// Recommended Setting: FALSE
#define NIBBLE_CONVERT_SERIAL_NUMBER      FALSE

// DELAY_AFTER_RESET is the time (in milliseconds) that the firmware
// will pause after a ATA bus reset (soft or pin reset).  Certain devices
// (in particular ATAPI devices in multi-LUN configurations) cannot be
// detected if they are accessed right after an ATA reset.  This pause
// gives them time to recover from reset.
#define DELAY_AFTER_POWERUP 2000    /* This delay is recommended to allow for power stability before startup */
#define DELAY_AFTER_RESET 1000      /*  */

// struct for holding device info
typedef struct
{
   BYTE NumCylindersMSB; // #Cyl MSB
   BYTE NumCylindersLSB; // #Cyl LSB
   BYTE NumHeads;        // #Heads
   BYTE NumSectPerTrack; // #SectorsPerTrack
   BYTE MaxPIO;
   BYTE udmaMode;      // global to keep track of which udma mode we are in
   DWORD driveCapacity;
} DEVICE_CONFIG_DATA;


///////////////////////////////////////////////////////////////////////////////
// Interface specific function definitions
///////////////////////////////////////////////////////////////////////////////
void hardwareReset();
void cfHardwareReset();
void writePIO8(char addr, WORD indata);
void writePIO16(char addr, WORD count);
void readPIO16(char addr, WORD count);
BYTE readPIO8(char addr);
BYTE readATAPI_STATUS_REG(void);
WORD readWordPIO8(char addr);
void initUdmaRead();
void initUdmaWrite();
void readUDMA(DWORD count);
void writeUDMA(DWORD count);
void abortGPIF();
bit waitForIntrq(BYTE timeoutEnable);
void initUSB(void);
void LoadandVerifyWaveForm(BYTE *WaveForm);
WORD getDriveDataLen();
void ResetAndArmEp2();
void configureATATransferMode(BYTE mode);
void EEPROMWrite(WORD length);
void detectSCSIvsATA();

void waitForInBuffer();
BYTE checkCBW();
#define FAIL_IN_ON_TIMEOUT 1
#define DONT_FAIL_IN_ON_TIMEOUT 0
//#define FX2_56PIN_PACKAGE 1         // need to compile code for internal space
//#define DEVICE_TYPE_IS_IDE 0
//#define DEVICE_TYPE_IS_SCSI 1

///////////////////////////////////////////////////////////////////////////////
// Common function definitions
///////////////////////////////////////////////////////////////////////////////

//------------ ide ------------------------------
void softReset();
void TD_Poll(void);
void SetupCommand(void);
void stallEP2OUT();
BYTE SCSITestUnitReady();
void resetATADevice();
void resetATAPIDevice();
void processCBWHeader();
void processCBW();
BYTE processConfigCBCommand();
void SCSIInquiryToATAPI();
void sendUSBS(BYTE passOrFail);
void sendRAMData(BYTE xdata *inData, WORD dataTransferLen);
BYTE generalSCSIInCommand();
BYTE generalSCSIOutCommand();
bit generalIDEInCommand();
bit generalIDEOutCommand();
bit sendSCSICommand(char xdata *cmdbuf, BYTE cmdLen);
void failedIn();
void ATAPIIdDevice();
WORD readPIO16toXdata(char addr, char xdata *inbuffer, WORD count, bit ignoreDriveLen);
bit waitForBusyBit();
BYTE inDataFromDrive();
void prepareForIDECommand();
void mymemmovexx(BYTE xdata * dest, BYTE xdata * src, WORD len);
void mymemmove(BYTE data * dest, BYTE data * src, BYTE len);
bit checkForMedia(bit commandProcessing);
void writeATA_DRIVESEL_REG();
void SendDeviceIdentifyCommand();
void FetchDeviceIdentifyIntoEp8();


#define IGNORE_DRIVE_LEN 1
#define LISTEN_TO_DRIVE_LEN 0
#define BUFFER_SIZE 0x200

extern void serialNumber();

extern WORD DeviceDscrOffset;
extern WORD DeviceQualDscrOffset;
extern WORD HighSpeedConfigDscrOffset;
extern WORD FullSpeedConfigDscrOffset;
extern WORD StringDscrOffset;
extern WORD UserDscrOffset;
extern WORD IntrfcSubClassHighSpeedOffset;
extern WORD IntrfcSubClassFullSpeedOffset;
extern WORD SerialNumberStringDscrOffset;
extern WORD SerialNumberIndexOffset;
extern WORD DscrEndOffset;
#if BUS_POWERED
extern code DEVICEDSCR        HIDDeviceDscr;
extern WORD HIDDeviceDscrEndOffset;
extern WORD HIDDscrOffset;
extern WORD HIDReportDscrOffset;
extern WORD HIDReportDscrEndOffset;
extern WORD HIDDscr;
extern WORD HIDDscrEndOffset;
extern WORD DscrPIDOffset;
extern WORD DscrClassOffset;
extern WORD DscrIntrfcClassFSOffset;
extern WORD DscrIntrfcClassHSOffset;

#endif

extern char code * sensePtr;
extern const char code senseCRCError[] ;    // Set on CRC error.  Causes host to retry  
extern const char code senseInvalidFieldInCDB[] ;    // ISD300 calls this InvalidCommandField   
extern const char code senseOk[] ; 
extern const char code senseNoMedia[] ; 
extern const char code senseWriteFault[] ; 
extern const char code senseReadError[] ; 
extern const char code senseAddrNotFound[] ; 
extern const char code senseInvalidOpcode[] ; 

⌨️ 快捷键说明

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