@@ -267,7 +267,6 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
267267 struct usb_endpoint_descriptor * ep_desc ;
268268 struct usbh_msc_modeswitch_config * config ;
269269 int ret ;
270- int cnt ;
271270
272271 struct usbh_msc * msc_class = usbh_msc_class_alloc ();
273272 if (msc_class == NULL ) {
@@ -319,38 +318,6 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
319318 }
320319 }
321320
322- cnt = 0 ;
323- while (usbh_msc_scsi_testunitready (msc_class ) < 0 ) {
324- USB_LOG_WRN ("Device not ready, try again...\r\n" );
325- ret = usbh_msc_scsi_requestsense (msc_class );
326- if (ret < 0 ) {
327- USB_LOG_ERR ("Fail to scsi_testunitready\r\n" );
328- }
329- cnt ++ ;
330- if (cnt > CONFIG_USBHOST_MSC_READY_CHECK_TIMES ) {
331- return - USB_ERR_BUSY ;
332- }
333- }
334-
335- ret = usbh_msc_scsi_inquiry (msc_class );
336- if (ret < 0 ) {
337- USB_LOG_ERR ("Fail to scsi_inquiry\r\n" );
338- return ret ;
339- }
340- ret = usbh_msc_scsi_readcapacity10 (msc_class );
341- if (ret < 0 ) {
342- USB_LOG_ERR ("Fail to scsi_readcapacity10\r\n" );
343- return ret ;
344- }
345-
346- if (msc_class -> blocksize > 0 ) {
347- USB_LOG_INFO ("Capacity info:\r\n" );
348- USB_LOG_INFO ("Block num:%d,block size:%d\r\n" , (unsigned int )msc_class -> blocknum , (unsigned int )msc_class -> blocksize );
349- } else {
350- USB_LOG_ERR ("Invalid block size\r\n" );
351- return - USB_ERR_RANGE ;
352- }
353-
354321 snprintf (hport -> config .intf [intf ].devname , CONFIG_USBHOST_DEV_NAMELEN , DEV_FORMAT , msc_class -> sdchar );
355322
356323 USB_LOG_INFO ("Register MSC Class:%s\r\n" , hport -> config .intf [intf ].devname );
@@ -385,6 +352,50 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
385352 return ret ;
386353}
387354
355+ int usbh_msc_scsi_init (struct usbh_msc * msc_class )
356+ {
357+ int ret ;
358+ uint16_t cnt ;
359+
360+ if (msc_class -> is_ready ) {
361+ return 0 ;
362+ }
363+
364+ cnt = 0 ;
365+ while (usbh_msc_scsi_testunitready (msc_class ) < 0 ) {
366+ USB_LOG_WRN ("Device not ready, try again...\r\n" );
367+ ret = usbh_msc_scsi_requestsense (msc_class );
368+ if (ret < 0 ) {
369+ USB_LOG_ERR ("Fail to scsi_testunitready\r\n" );
370+ }
371+ cnt ++ ;
372+ if (cnt > CONFIG_USBHOST_MSC_READY_CHECK_TIMES ) {
373+ return - USB_ERR_NODEV ;
374+ }
375+ }
376+ ret = usbh_msc_scsi_inquiry (msc_class );
377+ if (ret < 0 ) {
378+ USB_LOG_ERR ("Fail to scsi_inquiry\r\n" );
379+ return ret ;
380+ }
381+
382+ ret = usbh_msc_scsi_readcapacity10 (msc_class );
383+ if (ret < 0 ) {
384+ USB_LOG_ERR ("Fail to scsi_readcapacity10\r\n" );
385+ return ret ;
386+ }
387+
388+ if (msc_class -> blocksize > 0 ) {
389+ USB_LOG_INFO ("Capacity info:\r\n" );
390+ USB_LOG_INFO ("Block num:%d,block size:%d\r\n" , (unsigned int )msc_class -> blocknum , (unsigned int )msc_class -> blocksize );
391+ } else {
392+ USB_LOG_ERR ("Invalid block size\r\n" );
393+ return - USB_ERR_RANGE ;
394+ }
395+ msc_class -> is_ready = true;
396+ return 0 ;
397+ }
398+
388399int usbh_msc_scsi_write10 (struct usbh_msc * msc_class , uint32_t start_sector , const uint8_t * buffer , uint32_t nsectors )
389400{
390401 struct CBW * cbw ;
0 commit comments