亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? scsi.c

?? HIGH_SPEED_USB_To_ATA(IDE)Firmware相關代碼(EZ USB FX2芯片)
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
//   File:      scsi.c
//   Contents:   Functions to handle a scsi device.
//
// indent 3.  NO TABS!
//
// Description:
//    SCSI devices differ from IDE device as follows:
//    - SCSI devices may accept or return data according to the value of
//       its byte count registers which may differ from the host request
//       indicated in the CBW variable 'dataTransferlen'. 
//
//       If the host requests to write a greater amount than the byte count 
//       registers indicate, the extra data is processed by throwing it on 
//       the floor and reporting it as a residue.
//
//       If the host requests a read greater than what is indicated in the 
//       byte count registers, and the last packet is a full packet, a short 
//       packet is sent to terminate the transfer.
//
//    - generalSCSIInCommand() and generalSCSIOutCommand() are called from
//       periph.c.  Their conditional compile flags are kept inside the function
//       to maintain original code for periph.c.  All other functions in this
//       module are specific for SCSI and are static to this file.  They are
//       under one conditional compile flag.
//
//-----------------------------------------------------------------------------
// $Archive: /USB/atapifx2/software/scsi.c $
// $Date: 1/21/02 2:38p $
// $Revision: 41 $
//
//-----------------------------------------------------------------------------
//  Copyright (c) 1999 Cypress Semiconductor, Inc. All rights reserved
//-----------------------------------------------------------------------------
#include "fx2.h"
#include "fx2regs.h"
#include "scsi.h"
#include "gpif.h"

static BYTE scsiWrite(void);
static BYTE scsiWriteUdma();
static void prepareForATAPICommand();
static bit inDataFromDriveUdma();


// this bit determines if the current transfer is to be carried out using UDMA (1) or
// PIO (0)
bit useUdma;
bit bShortPacketSent;
BYTE udmaErrorCount;

#define SENSE_LEN 18

//-----------------------------------------------------------------------------
// Function:  generalSCSIInCommand()
//
// Input:   none
// Output:  bit flag
//          0 = success, 1 = failure
//
// Global data:
//    CBW from EP2FIFOBUF.
//
// Description:
//    Top level handler for scsi read.  The scsi command packet is 
//    a 12-byte packet extracted from the CBW contained in EP2FIFOBUF 
//    starting from byte 15.  If the command fails, the IN endpoint buffer
//    is stalled and the transaction is failed.
//
//    If the command was processed successfully, data is extracted from the 
//    drive till the byte count from the drive is exhausted.  If the byte count
//    indicated by the drive is less than what is requested by the host, the IN
//    endpoint is stalled, but the transaction is passed.  The remainder of bytes
//    the host still expects is reported as a residue.
//-----------------------------------------------------------------------------
BYTE generalSCSIInCommand()
{
#if DEVICE_TYPE_IS_SCSI

   BYTE result = 0;

   // Clear the bit telling us if we need a STALL to terminat the IRP on the host side   
   bShortPacketSent = 0;

   // if the drive is configured for udma then use udma depending on the
   // scsi command
   if (udmaMode)
   {
      switch(EP2FIFOBUF[0xf])
      {
         case 0x28:
         case 0xA8:
            useUdma = 1;     
            break;
         default:
            useUdma = 0;
            break;
      }
   }

   result = sendSCSICommand(EP2FIFOBUF + CBW_DATA_START);

   // relinquish control of the bulk buffer occupied by the CBW
   EP2BCL = 0x80; 
   
   // Need to modify this code so that we know if we sent a short packet to terminate the xfer.
   // Although the STALL is required, the ScanLogic driver and Mac driver will not properly handle it.
   
   if(result != USBS_PASSED)
      {
      failedIn();    // stalls EP8 
      return(USBS_FAILED);
      }

   // no need to do the data xfer phase if the host isn't expecting any data.
   if (!dataTransferLenLSW && !dataTransferLenMSW)
      {
      // Make sure the status is correct
      while (readATAPI_STATUS_REG() & ATAPI_STATUS_BUSY_BIT)
         ;

      if (readATAPI_STATUS_REG() & ATAPI_STATUS_DRQ_BIT)
         return(USBS_PHASE_ERROR);       // USBS_PHASE_ERROR -- Hn < Di (case 2)
      else
         return(USBS_PASSED);
      }

   //////////////////////////////////////////////////////////////////
   // Start of data xfer phase
   //////////////////////////////////////////////////////////////////
   if (useUdma) 
   {
      result = inDataFromDriveUdma();
   }
   else
   {
      result = inDataFromDrive();
   }

   if (dataTransferLen)    
      {
      // Case H(i) > D(i) or H(i) > D(n)
      // "terminate the transfer with a short packet, then STALL the IN endpoint"
      failedIn();       // only stalls EP8, does not return error
     
      // Pass the result to the next layer up.
      return(result);  
      }

   else
      return(result);       // No residue, just return status

#else
   return(0);
#endif
}   


//-----------------------------------------------------------------------------
// Function:  generalSCSIOutCommand()
//
// Input:   none
// Output:  bit flag
//          0 = success, 1 = failure
//
// Global data:
//    CBW from EP2FIFOBUF.
//
// Local data:
//    cmd      - command op code from CBW
//    result   - return status
//
// Description:
//    The scsi command packet is a 12-byte packet extracted from the CBW 
//    contained in EP2FIFOBUF starting from byte 15.  If the command fails, 
//    the OUT endpoint buffer is stalled and the transaction is failed.
//
//    If the command is successful, data is sent to the drive.
//    When the write encounters an error, the endpoint is stalled and the
//    transaction is failed.
//
//-----------------------------------------------------------------------------
BYTE generalSCSIOutCommand()
{
#if DEVICE_TYPE_IS_SCSI
   // Init local vars.

   BYTE result = USBS_FAILED;

   useUdma = 0;

   // if the drive is configured for udma then use udma depending on the
   // scsi command
   if (udmaMode)
   {
      switch(EP2FIFOBUF[0xf])
      {
         case 0x2A:
         case 0xAA:
            useUdma = 1;   //syk
            break;
         default:
            useUdma = 0;
            break;
      }
   }

   result = sendSCSICommand(EP2FIFOBUF + CBW_DATA_START);

   // relinquish control of the bulk buffer occupied by the CBW
   EP2BCL = 0x80;     

   // If the command failed, stall the endpoint and get out
   if (result != USBS_PASSED)
   {
      // If the transfer still contains data, and the xfer has not been terminated by a short packet
      // then we must stop the transfer with a STALL.
      if (dataTransferLen > 0)
      {
         // We may want to stall the endpoint here, but we must be careful to make sure that 
         // we don't set the stall bit when the xfer has completed!
          stallEP2OUT();
      }
      return(USBS_FAILED);
   }

   if (!dataTransferLen)
      return(result);

   if (useUdma)
   {
      result = scsiWriteUdma();
   }
   else
   {
      result = scsiWrite();
   }

   return(result);
#endif

#if DEVICE_TYPE_IS_IDE
   return(0);
#endif
}



#define SENSE_LEN 18
const char code testUnitReady[12] = { 0x00, 0x00, 0x00, 0x00, 00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
const char code requestSense[12] = {  0x03, 0x00, 0x00, 0x00, SENSE_LEN, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// Send a TestUnitReady command to the device.
// If the device fails the testUnitReady command, return the sense code, else return 0
BYTE SCSITestUnitReady()
{

   bit result = 0;
   //char count;
    
   if (!scsi)
      return(result);

#if DEVICE_TYPE_IS_SCSI
   useUdma = 0;
   result = sendSCSICommand((char xdata *) testUnitReady);
   if (result != USBS_PASSED)
   {
      result = sendSCSICommand((char xdata *) requestSense);
      if (result != USBS_PASSED)
         {
         }

      //result = waitForIntrq();

      readPIO16toXdata(ATAPI_DATA_REG, halfKBuffer, SENSE_LEN, LISTEN_TO_DRIVE_LEN);
      return(halfKBuffer[12]);
    }
#endif
}   


// Read the Inquiry info into our internal data structures.
// NOT prompted by the host.
#define INQUIRY_LEN 0x2c
const char code inquiryCommand[12] = { 0x12, 0x00, 0x00, 0x00, INQUIRY_LEN, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
void SCSIInquiryToATAPI()
{
#if DEVICE_TYPE_IS_SCSI

    bit result;

    useUdma = 0;
    result = sendSCSICommand((char xdata *) inquiryCommand);
    if (result != USBS_PASSED)
    {
        failedIn();    //This is an internal command, just leave if it fails.
        return;
    }

     result = waitForIntrq();

     readPIO16toXdata(ATAPI_DATA_REG, halfKBuffer, INQUIRY_LEN, LISTEN_TO_DRIVE_LEN);
  

   if (halfKBuffer[SCSI_INQUIRY_DEVICE_CLASS] == 5)
   {
      intrfcSubClass = USB_MS_CD_ROM_SUBCLASS;  
   }
#endif
}   


WORD getDriveDataLen()
{
    WORD driveDataLen;


    driveDataLen = readPIO8(ATAPI_BYTE_COUNT_MSB) << 8;
    driveDataLen += readPIO8(ATAPI_BYTE_COUNT_LSB);
    return(driveDataLen);
}
 


///////////////////////////////////////////////////////////////////////////////
#if DEVICE_TYPE_IS_SCSI
///////////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------------
// Function:  scsiWrite()
//
// Input:   none
// Output:  bit flag
//          0 = success, 1 = failure
//
// Global data:
//    dataTransferLen   - Amount of data requested by the host.  Counts down.
//    EP2CS             - Endpoint buffer status byte.
//    EP2BCL            - Endpoint LSB byte count register.
//
// Local data:
//    wDriveDataLen     - Amount of data drive will accept.
//    wAmountToWrite    - Amount of data to write to the drive.  This is typically
//                         a portion wDriveDataLen, and is qualified by the packet lenght.
//    wAmountSent       - Amount of data sent to the drive.  Counts up to ensure we don't
//                         exceed the packet size.
//    driveStatus       - Drive status from last action.  
//    bDone             - loop control flag     
//
// Description:
//    This function handles the special case of scsi MODE PAGE write (MODE SELECT command).
//    The drive byte count and the DRQ bit are used to determine how much data to send.
//    Typically, the host requests to send data that is much larger than what the
//    drive wants to accept.  
//
//    The drive may want to receive data in chunks less than a packet size, and the 
//    total number of bytes to satisfy the command may be less or greater than
//    a packet length.  Drive data request is processed as follows:
//    
//    (1) Total number of bytes is less than a packet, and drive wants to receive it in
//    increments.  The rest of the packet must be processed out of the buffer in
//    the size requested by the drive.  This transaction is governed by the
//    DRQ bit in the status register.
//
//    (2) Total number of bytes is greater than a packet, but drive wants it
//    in increments less than a packet lenght.  Full packet(s) are processed out
//    of the buffer using logic from (1) until the drive is satisfied.  This 
//    transaction is governed by the DRQ bit in the status register as well as the
//    byte count from the drive.  Any data residue in the endpoint buffer is sent 
//    to ATAPI_NULL_REGISTER.
//
//    If the host is determined to queue up packets to the buffer after the drive 
//    byte count has been satisfied (DRQ=0), the data is processed out of the endpoint 
//    buffer and discarded by setting the skip bit in the endpoint's byte count
//    register.
//
//    The DRQ bit is valid.
//
//    If a write encounters an error, we return an error and let caller 
//    stall the endpoint.
//
//-----------------------------------------------------------------------------
static BYTE scsiWrite(void)
{

   WORD wDriveDataLen = 0;
   BYTE driveStatus = 0;
   WORD wAmountToWrite = 0;
   WORD wAmountSent = 0;  
   bit bDone = 0;
   bit bShortPacketReceived = 0;
   BYTE cReturnStatus = USBS_PASSED;
   

   // See if drive is finished processing command and
   // is ready for data.
   while(readATAPI_STATUS_REG() & ATAPI_STATUS_BUSY_BIT)
      ;

   driveStatus = readATAPI_STATUS_REG();

   if (driveStatus & ATAPI_STATUS_DRQ_BIT)
   {
      while( (!(driveStatus & ATAPI_STATUS_ERROR_BIT)) && (!bDone) && dataTransferLen)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美mv日韩mv国产| 午夜婷婷国产麻豆精品| 亚洲在线免费播放| 国产精品一级黄| 制服丝袜亚洲色图| 亚洲欧洲在线观看av| 韩国女主播一区二区三区| 色一情一伦一子一伦一区| 国产亚洲一本大道中文在线| 日韩在线观看一区二区| 色综合天天综合网国产成人综合天 | 伊人性伊人情综合网| 国产一区二区三区四区五区入口| 在线视频你懂得一区| 亚洲欧洲在线观看av| 国产精品香蕉一区二区三区| 欧美不卡一区二区三区| 日韩和的一区二区| 欧美三级电影网| 亚洲国产综合视频在线观看| 99国产精品久| 亚洲欧美日韩在线| 99久久精品国产一区| 国产精品萝li| bt欧美亚洲午夜电影天堂| 国产欧美一区二区精品性色超碰| 欧美综合一区二区三区| 亚洲人成亚洲人成在线观看图片| 成人中文字幕合集| 18成人在线视频| 色综合色综合色综合色综合色综合| 中文字幕不卡在线观看| 成人v精品蜜桃久久一区| 亚洲欧洲一区二区在线播放| 99久久精品情趣| 亚洲精品一卡二卡| 欧美日韩一级视频| 捆绑紧缚一区二区三区视频| 日韩精品中文字幕在线不卡尤物 | 日韩欧美激情一区| 青青草国产精品亚洲专区无| 欧美一区午夜精品| 国产原创一区二区三区| 久久精品综合网| 国产91对白在线观看九色| 中文一区二区在线观看| 一本色道a无线码一区v| 亚洲成a人片在线不卡一二三区| 欧美精品电影在线播放| 精品综合久久久久久8888| 精品日本一线二线三线不卡| 国产成人综合视频| 一区二区在线观看免费视频播放| 欧美日韩免费一区二区三区视频| 亚洲超碰精品一区二区| 久久中文娱乐网| 91麻豆精品秘密| 免费高清在线一区| 国产精品每日更新| 日韩视频一区二区在线观看| 国产成人在线影院| 午夜精品久久一牛影视| 国产亚洲欧美日韩在线一区| 国产精品福利影院| 亚洲三级小视频| www.欧美日韩国产在线| 亚洲国产精品久久人人爱| 久久久国产精华| 亚洲欧美综合色| 欧美美女一区二区在线观看| 国产高清一区日本| 五月激情综合网| 国产精品久久久久久亚洲毛片 | 悠悠色在线精品| 日韩免费电影一区| 在线看国产日韩| 国产东北露脸精品视频| 视频一区二区国产| 中文字幕一区二区三区不卡 | 欧美亚洲动漫精品| 久久黄色级2电影| 一区二区三区四区激情| 国产日韩精品一区二区浪潮av| 欧美人动与zoxxxx乱| 99re视频精品| 国产iv一区二区三区| 免费日本视频一区| 亚洲一区二区视频在线| 国产精品福利一区二区三区| 精品国产3级a| 欧美一区二区在线免费播放| 99久久精品国产网站| 成人夜色视频网站在线观看| 麻豆一区二区三| 男人的天堂亚洲一区| 亚洲大型综合色站| 亚洲色图丝袜美腿| 国产精品天美传媒| 国产欧美一区二区精品久导航 | 麻豆精品视频在线| 日韩在线一区二区| 丝袜a∨在线一区二区三区不卡| 亚洲四区在线观看| 亚洲日穴在线视频| 亚洲免费成人av| 亚洲欧美日韩一区| 亚洲免费观看高清在线观看| 国产精品久久看| 中文字幕亚洲不卡| 中文字幕一区二区三| 亚洲欧洲精品一区二区精品久久久 | 色94色欧美sute亚洲线路二| 精品三级在线看| 97超碰欧美中文字幕| 欧美极品少妇xxxxⅹ高跟鞋| 中文字幕一区视频| 久久精品在线免费观看| 精品日本一线二线三线不卡| 精品国产sm最大网站免费看| 日韩欧美美女一区二区三区| 精品免费国产二区三区 | 99精品视频免费在线观看| 国产成人超碰人人澡人人澡| 成人h动漫精品一区二区| 成人av电影免费在线播放| 91色视频在线| 欧美日韩一区在线| 日韩一二三四区| 国产日韩欧美精品一区| 中文字幕一区二区在线观看| 亚洲欧美日韩电影| 五月婷婷激情综合| 激情成人午夜视频| 成人黄色在线网站| 欧美性色aⅴ视频一区日韩精品| 欧美日韩国产成人在线免费| 精品久久久久一区| 中文字幕日韩精品一区| 亚洲主播在线观看| 国产在线精品一区二区| 99精品视频在线观看免费| 欧美日韩在线综合| 久久午夜电影网| 亚洲国产一区视频| 精品影视av免费| 91一区二区在线| 666欧美在线视频| 中文av一区二区| 视频一区二区三区入口| 亚洲精品在线电影| 亚洲天堂精品视频| 久久99在线观看| 91啪九色porn原创视频在线观看| 欧美精品色综合| 国产精品日产欧美久久久久| 日韩成人免费电影| 91丨九色丨蝌蚪富婆spa| 精品日韩在线观看| 亚洲乱码一区二区三区在线观看| 精品一区二区成人精品| 色久优优欧美色久优优| 精品国一区二区三区| 一区二区不卡在线播放| 国产精品一区二区免费不卡| 3atv一区二区三区| 一区二区三区资源| 国产麻豆视频精品| 日韩欧美成人一区二区| 亚洲激情自拍视频| 国产69精品久久久久777| 在线观看91av| 樱花影视一区二区| 成人国产视频在线观看| 欧美videofree性高清杂交| 亚洲电影一级黄| 99re热视频这里只精品| 久久精品一区四区| 久久精品国产**网站演员| 欧美性xxxxxx少妇| 一区二区三区日韩在线观看| 成人h动漫精品一区二区| 国产网站一区二区| 国产在线国偷精品产拍免费yy| 欧美精品1区2区| 一区二区高清免费观看影视大全| 国产一区二区毛片| 日韩精品中文字幕一区二区三区 | 国产精品福利影院| 国产酒店精品激情| 久久久综合网站| 黑人精品欧美一区二区蜜桃 | 欧美性xxxxx极品少妇| 亚洲色图在线播放| 99视频热这里只有精品免费| 国产亚洲一区二区三区四区| 韩国毛片一区二区三区| 日韩精品最新网址| 精品一区二区免费视频| 久久久亚洲高清| 国产成人精品在线看|