コード例 #1
0
ファイル: msd_commands.c プロジェクト: 3ben1189/mcuoneclipse
static void usb_host_mass_test_storage
   (
      void
   )
{ /* Body */
   static USB_STATUS                                 status = USB_OK;
   static uint_8                                     bLun = 0;
   static INQUIRY_DATA_FORMAT                        inquiry;
   static MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO read_capacity;
   static CAPACITY_LIST                              capacity_list;
   static REQ_SENSE_DATA_FORMAT                      req_sense;
   static FORMAT_UNIT_PARAMETER_BLOCK                formatunit = { 0};
   static CBW_STRUCT_PTR cbw_ptr; 
   static CSW_STRUCT_PTR csw_ptr;

   uint_8 res;

   switch(test)
   {
    case 0:
      cbw_ptr = pCmd.CBW_PTR;
      csw_ptr = pCmd.CSW_PTR;

      memset(buff_in, 0, BUFF_IN_SIZE);
      memset(buff_out, 0, 0x0F);
      memset(pCmd.CSW_PTR, 0, sizeof(CSW_STRUCT));
      memset(pCmd.CBW_PTR, 0, sizeof(CBW_STRUCT));
      memset(&pCmd, 0, sizeof(COMMAND_OBJECT_STRUCT));
      
      pCmd.CBW_PTR  = cbw_ptr;
      pCmd.CSW_PTR  = csw_ptr;
      pCmd.LUN      = bLun;
      pCmd.CALL_PTR = (pointer)&mass_device.class_intf;
      pCmd.CALLBACK = callback_bulk_pipe;

      printf("\n ================ START OF A NEW SESSION ================");
      test++;
      ontest = 1;
      count = 0;
      break;
      
      
    case 1:
        count++;
        /* Send standard commands once, after each enumeration in order to 
         * communicate well with most usb sticks */
        if(count == 1){
#if 0
            /* Read LUN info (type, and some strings) */
            res = disk_ioctl(0, UFI_INQUIRY, NULL);
            //res = disk_ioctl(0, UFI_READ_FORMAT_CAPACITY, NULL);
            res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
            //res = disk_ioctl(0, UFI_READ_FORMAT_CAPACITY, NULL);
#endif
#if 1
            res = disk_ioctl(0, UFI_INQUIRY, NULL);
            res = disk_ioctl(0, UFI_TEST_UNIT_READY, NULL);
            //res = disk_ioctl(0, UFI_READ_CAPACITY, NULL);
            printf("");
#endif
        }
        
      /* Test the GET MAX LUN command */
      if (1 == ontest)
      {
        printf("\n Testing: GET MAX LUN Command");
        bCallBack = FALSE;

        status = usb_class_mass_getmaxlun_bulkonly(
          (pointer)&mass_device.class_intf, &bLun,
          usb_host_mass_ctrl_callback);
          ontest = 0;
      } 
      else 
      {
        if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
        {
          printf (".......................ERROR");
          return;
        }
        else
        {
          /* Wait till command comes back */
          if (!bCallBack) {break;}
          if (!bStatus) 
          {
             printf("..........................OK\n");
             test++;
             ontest = 1;
          }
          else 
          {
             printf("...Unsupported (bStatus=0x%08x)\n", (unsigned int)bStatus);
             test++;
             ontest = 1;
          }
        }
      }
      break;
      
    case 2:
        if (1 == ontest)
        {
            printf(" Testing: TEST UNIT READY Command");
            bCallBack = FALSE;

            status =  usb_mass_ufi_test_unit_ready(&pCmd);
            ontest = 0;
        } 
        else 
        {
            if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
            {
                printf ("...................ERROR");
                return;
            }
            else
            {
                /* Wait till command comes back */
                if (!bCallBack) {break;}
                if (!bStatus)
                {
                    printf("......................OK\n");
                    test++;
                    ontest = 1;
                }
                else 
                {
                    printf("...Unsupported(bStatus=0x%08x)\n", (unsigned int)bStatus);
                    test++;
                    ontest = 1;
                }
            }
        }
        break;
      
    case 3:
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: INQUIRY Command");
        res = disk_ioctl(0, UFI_INQUIRY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        time_delay(2000);
        printf(" Testing: READ CAPACITY Command");
        res = disk_ioctl(0, UFI_READ_CAPACITY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: READ FORMAT CAPACITIES Command");
        res = disk_ioctl(0, UFI_READ_FORMAT_CAPACITY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: MODE SENSE Command");
        res = disk_ioctl(0, UFI_MODE_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: PREVENT-ALLOW MEDIUM REMOVAL Command");
        res = disk_ioctl(0, UFI_PREVENT_ALLOW_MEDIUM_ROMVAL, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: VERIFY Command");
        res = disk_ioctl(0, UFI_VERIFY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: WRITE(10) Command");
        res = disk_ioctl(0, UFI_WRITE10, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: READ(10) Command");
        res = disk_ioctl(0, UFI_READ10, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: START-STOP UNIT Command");
        res = disk_ioctl(0, UFI_START_STOP, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        /* ------------------------------------------------------------------ */
        test++;
      break;
      
    case 4:
      printf("\n Test done!\n");
      test++;
      break;
      
    default:
      break;
   } /* End of switch */
   
   /* ------------------------------------------------------------------ */
   if(test == 19)
   {
       
   }

} /* Endbody */
コード例 #2
0
ファイル: msd_commands.c プロジェクト: gxliu/MQX_3.8.0
static void usb_host_mass_test_storage
   (
      void
   )
{ /* Body */
   USB_STATUS                                 status = USB_OK;
   uint_8                                     bLun = 0;
   INQUIRY_DATA_FORMAT                        inquiry;
   CAPACITY_LIST                              capacity_list;
   #if 0
   MODE_SELECT_PARAMETER_LIST                 md_list;
   #endif
   MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO read_capacity;
   REQ_SENSE_DATA_FORMAT                      req_sense;
   FORMAT_UNIT_PARAMETER_BLOCK                formatunit = { 0};
   _mqx_int                                   block_len;
   DEVICE_DESCRIPTOR_PTR                      pdd;
   CBW_STRUCT_PTR cbw_ptr = pCmd->CBW_PTR;
   CSW_STRUCT_PTR csw_ptr = pCmd->CSW_PTR;

   USB_mem_zero(buff_out,0x0F);
   USB_mem_zero(buff_in,0x400C);
   USB_mem_zero(pCmd->CSW_PTR,sizeof(CSW_STRUCT));
   USB_mem_zero(pCmd->CBW_PTR,sizeof(CBW_STRUCT));
   USB_mem_zero(pCmd,sizeof(COMMAND_OBJECT_STRUCT));
   
   pCmd->CBW_PTR  = cbw_ptr;
   pCmd->CSW_PTR  = csw_ptr;
   pCmd->LUN      = bLun;
   pCmd->CALL_PTR = (pointer)&mass_device.class_intf;
   pCmd->CALLBACK = usb_host_mass_bulk_callback;

   printf("\n =============START OF A NEW SESSION==================");

   if (USB_OK != _usb_hostdev_get_descriptor(
      mass_device.dev_handle,
      NULL,
      USB_DESC_TYPE_DEV,
      0,
      0,
      (pointer *) &pdd))
   {
      printf ("\nCould not retrieve device descriptor.");
      return;
   }
   else
      printf("\nVID = 0x%04x, PID = 0x%04x", SHORT_LE_TO_HOST(*(uint_16*)pdd->idVendor), SHORT_LE_TO_HOST(*(uint_16*)pdd->idProduct));

   /* Test the GET MAX LUN command */
   printf("\nTesting: GET MAX LUN Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_class_mass_getmaxlun_bulkonly(
      (pointer)&mass_device.class_intf, &bLun,
      usb_host_mass_ctrl_callback);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack) {;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the TEST UNIT READY command */
   printf("Testing: TEST UNIT READY Command");
   fflush(stdout);

   bCallBack = FALSE;

   status =  usb_mass_ufi_test_unit_ready(pCmd);
   
   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the INQUIRY command */
   printf("Testing: INQUIRY Command");
   fflush(stdout);

   bCallBack = FALSE;

   status = usb_mass_ufi_inquiry(pCmd, (uchar_ptr) &inquiry,
      sizeof(INQUIRY_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the READ FORMAT CAPACITY command */
   printf("Testing: READ FORMAT CAPACITIES Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_format_capacity(pCmd, (uchar_ptr)&capacity_list,
      sizeof(CAPACITY_LIST));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the READ CAPACITY command */
   printf("Testing: READ CAPACITY Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_read_capacity(pCmd, (uchar_ptr)&read_capacity,
      sizeof(MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   block_len = HOST_TO_BE_LONG(* (uint_32 *) &read_capacity.BLENGTH);

#if 0
   /* Test the MODE SELECT command */
   printf("Testing: MODE SELECT Command");
   fflush(stdout);
   bCallBack = FALSE;

   //md_list. Fill parameters here
   USB_mem_zero (&md_list, sizeof (MODE_SELECT_PARAMETER_LIST));
   md_list.MODE_PARAM_HEADER.BLENGTH[1] = 0x06;
   
   status = usb_mass_ufi_mode_select(pCmd, &md_list, 8);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
#endif

   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the READ(10) command */
   printf("Testing: READ(10) Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_read_10(pCmd, 0, buff_in, block_len, 1);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the MODE SENSE command */
   printf("Testing: MODE SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_mode_sense(pCmd,
      2, //PC
      0x3F, //page code
      buff_in,
      (uint_32)0x08);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the PREVENT ALLOW command */
   printf("Testing: PREVENT-ALLOW MEDIUM REMOVAL Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_prevent_allow_medium_removal(
      pCmd,
      1 // prevent
      );

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the VERIFY command */
   printf("Testing: VERIFY Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_verify(
      pCmd,
      0x400, // block address
      1 //length to be verified
      );

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the WRITE(10) command */
   printf("Testing: WRITE(10) Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_write_10(pCmd, 8, buff_out, block_len, 1);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the START-STOP UNIT command */
   printf("Testing: START-STOP UNIT Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_start_stop(pCmd, 0, 1);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   printf("\nTest done!");
   fflush(stdout);
} /* Endbody */