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

📄 msd_fn_scsi.c

📁 MSTAR03的数码相框的代码
💻 C
📖 第 1 页 / 共 3 页
字号:
       #endif
       */
     }
     else if (cbw.cmd_bytes[0] == SCSI_FN_TEST_UNIT_READY)
     {
	   //printf("\r\n Test_Rdy",0);
       status = FnTestRdy_Command(cbw);
       #if ENABLE_NAND
       if(gu8LunMapping[cbw.max_lun]==eNAND)
       {
          MDrv_NAND_ForceWriteBack();
       }
       #endif
     }
     else if (cbw.cmd_bytes[0] == SCSI_FN_VERIFY)
     {
       status = FnVerify_Command(cbw);
     }
     else if (cbw.cmd_bytes[0] == SCSI_FN_RD_FMT_CAPC )
     {
        switch(gu8LunMapping[cbw.max_lun])
        {
        #if ENABLE_SD_MS_XD_MULTISLOT
        case(eSD_MS_XD):
            _u8DriveNo = Dev_CARD;
            status = FnRdFmtCap_Command(cbw,msAPI_MSD_ReadCapacity(),SCSI_BLOCK_SIZE); //for test use
            break;
        #else

        #if ENABLE_SD_MMC
        case(eSDMMC):

            break;
        #endif
        #if (ENABLE_MS||ENABLE_MSPRO)
        case(eMSMSP):

            break;
        #endif
        #if (ENABLE_SM||ENABLE_XD)
        case(eSMXD):

            break;
        #endif

        #endif
        #if ENABLE_CF
        case(eCF):
            _u8DriveNo = Dev_CF;
            status = FnRdFmtCap_Command(cbw,msAPI_MSD_ReadCapacity(),SCSI_BLOCK_SIZE); //for test use
            break;
        #endif

        #if ENABLE_NAND
        case(eNAND):
            status = FnRdFmtCap_Command(cbw,MDrv_NAND_GetCapacity(),SCSI_BLOCK_SIZE);
            break;
        #endif

        #if ENABLE_NOR_DEBUG
        case(eNOR):
            status = FnRdFmtCap_Command(cbw,(MDrv_Nor_FS_Capacity()/0x200),SCSI_BLOCK_SIZE);
            break;
        #endif
        }
        /*
       //status = FnRdFmtCap_Command(cbw,GetSDCapa(),SCSI_BLOCK_SIZE);
       if(cbw.max_lun==CARD_MODE)
         status = FnRdFmtCap_Command(cbw,msAPI_MSD_ReadCapacity(),SCSI_BLOCK_SIZE); //for test use
       #ifdef SUPPORT_NAND_DISK
	   if(cbw.max_lun==NAND_MODE)
	     status = FnRdFmtCap_Command(cbw,MDrv_NAND_GetCapacity(),SCSI_BLOCK_SIZE);
       #endif
       */
     }
     else if (cbw.cmd_bytes[0] == SCSI_FN_MODE_SENSE )
     {
       status = FnModeSense_Command(cbw);
     }
     else if (cbw.cmd_bytes[0] == SCSI_FN_READ10  )
     {
	   //printf("\r\n READ\n",0);
       status = FnRd10_Command(cbw);
     }
     else if (cbw.cmd_bytes[0] == SCSI_FN_WRITE10  )
     {
       status = FnWt10_Command(cbw);
     }
     else if (cbw.cmd_bytes[0] == SCSI_FN_PREVENT )
     {
       status = FnPrevent_Command(cbw);
     }

     else
     {
       if (cbw.dxfer_length!=0)
	   {
	     if (cbw.dir_flag &0x80)
		   USB_Endpoint_Bulk_In_Stall();
		 else
		   USB_Endpoint_Bulk_Out_Stall();
	   }
       otgFSenseKey = 0x05;
       otgFASC = 0x24;
       otgFASCQ = 0x00;
	   printf("\r\n SCSI Command not Support",0);
     }
     // Derek added
     if(!usbConnectFlag)
     {
        usbSet_ClrRXMode1();
        return;
     }
     if (status == USB_ST_NOERROR)
     {
	   //USB_MSDFN_BOT_Err_Hndlr(cbw,(U8) MSDFN_BOT_COMMAND_PASSED);
	   //printf("ret CSW\n");
	   Return_CSW_to_Host(cbw,(__u8) MSDFN_BOT_COMMAND_PASSED);
	 }
     else
       Return_CSW_to_Host(cbw,(__u8) MSDFN_BOT_COMMAND_FAILED);
     usbSet_ClrRXMode1();
   }
}

__u8 FnRdFmtCap_Command(MSDFN_BOT_CBW_STRU cbw,__u32 noblk,__u32 blksize)
{
   __s8 status;
   __u8 fmt_capacity[] =
        {
          0x00, 0x00, 0x00,       /* Reserved */
          0x08,                   /* Capacity List Length */
          0x00, 0x00, 0x00, 0x00, /* Number of Blocks Updated Later */
          0x02,                   /* Formatted Media */
          0x00, 0x00, 0x00 };     /* Block Length to be Updated Later*/

   fmt_capacity[7] = (__u8) (noblk & 0x00FF);
   fmt_capacity[6] = (__u8) ((noblk >> 8) & 0x00FF);
   fmt_capacity[5] = (__u8) ((noblk >> 16) & 0x00FF);
   fmt_capacity[4] = (__u8) ((noblk >> 24) & 0x00FF);

   fmt_capacity[2] = (__u8) (blksize & 0xFF);
   fmt_capacity[1] = (__u8) ((blksize >> 8) & 0xFF);
   fmt_capacity[0] = (__u8) ((blksize >> 16) & 0xFF);

   otgactualXfer_len = FMT_CACP_LEN;
   otgdataXfer_dir = DATA_IN;
   if (cbw.dxfer_length < FMT_CACP_LEN)
     otgfun_residue = -1;
   else
     otgfun_residue = cbw.dxfer_length-FMT_CACP_LEN;

   status=SDRAM2USB_Bulk((__u32)&fmt_capacity,FMT_CACP_LEN);
   //printf("\r\n RdFmtCap_status:%bx ",status);

   return status;
}

__u8 FnRdCap_Command(MSDFN_BOT_CBW_STRU cbw,__u32 noblk,__u32 blksize)
{
   __s8 status;

   __u8 rd_capacity[] =
        {
          0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
        };

   rd_capacity[3] = (__u8) (noblk & 0x00FF);
   rd_capacity[2] = (__u8) ((noblk >> 8) & 0x00FF);
   rd_capacity[1] = (__u8) ((noblk >> 16) & 0x00FF);
   rd_capacity[0] = (__u8) ((noblk >> 24) & 0x00FF);

   rd_capacity[7] = (__u8) (blksize & 0x00FF);
   rd_capacity[6] = (__u8) ((blksize >> 8) & 0x00FF);
   rd_capacity[5] = (__u8) ((blksize >> 16) & 0x00FF);
   rd_capacity[4] = (__u8) ((blksize >> 24) & 0x00FF);

   otgactualXfer_len = RD_CAPCY_LEN;
   otgdataXfer_dir = DATA_IN;
   if (cbw.dxfer_length < RD_CAPCY_LEN)
     otgfun_residue = -1;
   else
     otgfun_residue = cbw.dxfer_length-RD_CAPCY_LEN;

   status=SDRAM2USB_Bulk((__u32)&rd_capacity,RD_CAPCY_LEN);
   //printf("\r\n ReadCapacity_status:%bx ",status);

   return status;
}

__u8 FnTestRdy_Command(MSDFN_BOT_CBW_STRU cbw)
{
   __s8 status = USB_ST_NOERROR;

   if (cbw.dxfer_length)
     otgactualXfer_len = 0;

   otgactualXfer_len = 0;
   otgdataXfer_dir = 0;
   otgfun_residue = 0;

   return status;
}

__u8 FnVerify_Command(MSDFN_BOT_CBW_STRU cbw)
{
   __s8 status = USB_ST_NOERROR;

   if (cbw.dxfer_length)
     otgactualXfer_len = 0;

   otgactualXfer_len = 0;
   otgdataXfer_dir = 0;
   otgfun_residue = 0;

   return status;
}

__u8 FnInquiry_Command(MSDFN_BOT_CBW_STRU cbw)
{
   __s8 status;

   __u8 inquiry[] =
	    {
          0x00, /* Device is connected to LUN   : Disk Drive */
          0x80, /* Removable */
          0x00, /* Device supports SCSI-2 */
          0x00, /* Data Format  : SCSI-2 */
          31,   /* Number of additional Bytes to Follow */
          0x00, /* Reserved */
          0x00, /* Reserved  : Some fields suported in SCSI-3 */
          0x00, /* Device Supports Synchronus Transfer */

          /* These 8-bytes describe the Manufacturer */
          'G','C','R','E','A','D','E','R',

          /* These 16 bytes describe Product */
          0x0,0x0,0x0,0x0,
          0x0,0x0,0x0,0x0,
          0x0,0x0,0x0,0x0,
          0x0,0x0,0x0,0x0,

          0x0,0x0,0x0,0x0
	    };
   __u8 inquiry_card[] =
	    {
          0x00, /* Device is connected to LUN   : Disk Drive */
          0x80, /* Removable */
          0x00, /* Device supports SCSI-2 */
          0x00, /* Data Format  : SCSI-2 */
          31,   /* Number of additional Bytes to Follow */
          0x00, /* Reserved */
          0x00, /* Reserved  : Some fields suported in SCSI-3 */
          0x00, /* Device Supports Synchronus Transfer */

          /* These 8-bytes describe the Manufacturer */
          'M','S','R','E','A','D','E','R',

          /* These 16 bytes describe Product */
          0x0,0x0,0x0,0x0,
          0x0,0x0,0x0,0x0,
          0x0,0x0,0x0,0x0,
          0x0,0x0,0x0,0x0,

          0x0,0x0,0x0,0x0
	    };
   otgactualXfer_len = INQ_DATA_LEN;
   otgdataXfer_dir = DATA_IN;
   if (cbw.dxfer_length < INQ_DATA_LEN)
     otgfun_residue = -1;
   else
     otgfun_residue = cbw.dxfer_length - INQ_DATA_LEN;
   if(gu8LunMapping[cbw.max_lun]==eNAND)
   status=SDRAM2USB_Bulk((__u32)&inquiry,INQ_DATA_LEN);
   else
       status=SDRAM2USB_Bulk((__u32)&inquiry_card,INQ_DATA_LEN);
   //printf("\r\n Inquiry_status:%bx",status);

   return status;
}

__u8 FnModeSense_Command(MSDFN_BOT_CBW_STRU cbw)
{
   __s8 status;
   __u8 mode_sense[] = {0x03,0x00,0x00,0x00};

   otgactualXfer_len = MODE_SEN_LEN;
   otgdataXfer_dir = DATA_IN;
   if (cbw.dxfer_length < MODE_SEN_LEN)
     otgfun_residue = -1;
   else
     otgfun_residue = cbw.dxfer_length-MODE_SEN_LEN;

   status=SDRAM2USB_Bulk((__u32)&mode_sense,MODE_SEN_LEN);

   return status;
}

__u8 FnReqSen_Command(MSDFN_BOT_CBW_STRU cbw)
{
   __s8 status;
   __u8 req_sense[] =
	    {
          0x70, /* Error Code */
          0x00,
          0x00, /* ILLEGAL Request */

          0x00, 0x00, 0x00, 0x00,
          0x0A, 0x00, 0x00, 0x00,
          0x00, 0x00, 0x00, 0x00,
          0x00, 0x00, 0x00
        };
   req_sense[2] = otgFSenseKey;
   req_sense[12] = otgFASC;
   req_sense[13] = otgFASCQ;

   otgactualXfer_len = REQ_SENS_LEN;
   otgdataXfer_dir = DATA_IN;
   if (cbw.dxfer_length < REQ_SENS_LEN)
     otgfun_residue = -1;
   else
     otgfun_residue = cbw.dxfer_length-REQ_SENS_LEN;

   status=SDRAM2USB_Bulk((__u32)&req_sense,REQ_SENS_LEN);

   return status;
}


__u8 FnPrevent_Command(MSDFN_BOT_CBW_STRU cbw)
{
   __s8 status;

   otgactualXfer_len = 0;
   otgdataXfer_dir = 0;
   otgfun_residue = 0;

   if (cbw.cmd_bytes[4]!=0)
   {
     status = MSDFN_BOT_COMMAND_FAILED;
     otgFSenseKey = 0x05;
     otgFASC= 0x24;
     otgFASCQ = 0x00;
   }
   else
     status = USB_ST_NOERROR;

   return status;
}


__u8 FnRd10_Command(MSDFN_BOT_CBW_STRU cbw)
{
   __s8 status=0,CRSts=0;
   __u16 nblocks;
   __u32 block_num,XferSize,tmpactXfer;
   //unsigned char *databuf;
   __u32 databuf;

   if (cbw.cmd_bytes[0] & 0x20)
   {
     *((__u8 *)&block_num+0)=cbw.cmd_bytes[2];
     *((__u8 *)&block_num+1)=cbw.cmd_bytes[3];
     *((__u8 *)&block_num+2)=cbw.cmd_bytes[4];
     *((__u8 *)&block_num+3)=cbw.cmd_bytes[5];
     *((__u8 *)&nblocks+0)=cbw.cmd_bytes[7];
     *((__u8 *)&nblocks+1)=cbw.cmd_bytes[8];
   }

   otgactualXfer_len = (__u32)nblocks * SCSI_BLOCK_SIZE;
   tmpactXfer = otgactualXfer_len;  //wayne add
   otgdataXfer_dir = DATA_IN;

   if (cbw.dxfer_length < otgactualXfer_len)
     otgfun_residue = -1;
   else

⌨️ 快捷键说明

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