summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheyuanjie87 <[email protected]>2013-06-15 23:02:50 +0800
committerheyuanjie87 <[email protected]>2013-06-15 23:02:50 +0800
commit02869d7e6758231ca05776cc49582910db87972e (patch)
tree987e8baefe5dd37af83136ca95d80c1e41694d0d
parent4cdb0154ba7418df177f4d6a9afd1fc1be6aa0ae (diff)
udisk can be eject
-rw-r--r--components/drivers/include/drivers/usb_common.h1
-rw-r--r--components/drivers/usb/usbdevice/class/mstorage.c43
-rw-r--r--components/drivers/usb/usbdevice/core/core.c4
3 files changed, 31 insertions, 17 deletions
diff --git a/components/drivers/include/drivers/usb_common.h b/components/drivers/include/drivers/usb_common.h
index d8d32d8306..68944f43ef 100644
--- a/components/drivers/include/drivers/usb_common.h
+++ b/components/drivers/include/drivers/usb_common.h
@@ -368,6 +368,7 @@ typedef struct ureqest* ureq_t;
#define SCSI_INQUIRY_CMD 0x12
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1e
#define SCSI_MODE_SENSE_6 0x1a
+#define SCSI_START_STOP 0x1b
#define SCSI_READ_CAPACITIES 0x23
#define SCSI_READ_CAPACITY 0x25
#define SCSI_READ_10 0x28
diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c
index b97be204c2..f43a7525f9 100644
--- a/components/drivers/usb/usbdevice/class/mstorage.c
+++ b/components/drivers/usb/usbdevice/class/mstorage.c
@@ -33,6 +33,7 @@ static rt_device_t disk;
static rt_uint32_t _block;
static rt_uint32_t _count, _size;
static struct rt_device_blk_geometry geometry;
+static rt_uint32_t _removed = 0;
static struct udevice_descriptor dev_desc =
{
@@ -126,13 +127,13 @@ static rt_err_t _request_sense(udevice_t device, uep_t ep_in)
data.ErrorCode = 0x70;
data.Valid = 0;
- data.SenseKey = 5;
+ data.SenseKey = 2; //TODO
data.Information[0] = 0;
data.Information[1] = 0;
data.Information[2] = 0;
data.Information[3] = 0;
- data.AdditionalSenseLength = 0x0b;
- data.AdditionalSenseCode = 0x20;
+ data.AdditionalSenseLength = 0x0a;
+ data.AdditionalSenseCode = 0x3a; //TODO
data.AdditionalSenseCodeQualifier =0;
dcd_ep_write(device->dcd, ep_in, (rt_uint8_t*)&data, sizeof(struct request_sense_data));
@@ -299,6 +300,19 @@ static rt_err_t _verify_10(udevice_t device)
return RT_EOK;
}
+static void _send_status(udevice_t device, mass_eps_t eps, ustorage_csw_t csw)
+{
+ dcd_ep_write(device->dcd, eps->ep_in, (rt_uint8_t*)csw, SIZEOF_CSW);
+ dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer, SIZEOF_CBW);
+ status = STATUS_CBW;
+}
+
+static void _start_stop(ustorage_cbw_t cbw)
+{
+ //TODO
+ _removed = 1;
+}
+
/**
* This function will handle mass storage bulk in endpoint request.
*
@@ -313,13 +327,11 @@ static rt_err_t _ep_in_handler(udevice_t device, uclass_t cls, rt_size_t size)
RT_ASSERT(device != RT_NULL);
eps = cls->eps;
- if(status == STATUS_CSW)
+ if (status == STATUS_CSW)
{
- dcd_ep_write(device->dcd, eps->ep_in, (rt_uint8_t*)&csw, SIZEOF_CSW);
- status = STATUS_CBW;
- dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer, SIZEOF_CBW);
+ _send_status(device, eps, &csw);
}
- if(status == STATUS_SEND)
+ else if (status == STATUS_SEND)
{
rt_device_read(disk, _block, eps->ep_in->buffer, 1);
dcd_ep_write(device->dcd, eps->ep_in, eps->ep_in->buffer,
@@ -388,8 +400,8 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
switch(cbw->cb[0])
{
case SCSI_TEST_UNIT_READY:
- dcd_ep_write(device->dcd, eps->ep_in, (rt_uint8_t*)&csw, SIZEOF_CSW);
- dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer, SIZEOF_CBW);
+ csw.status = _removed;
+ _send_status(device, eps, &csw);
break;
case SCSI_REQUEST_SENSE:
_request_sense(device, eps->ep_in);
@@ -404,8 +416,7 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
status = STATUS_CSW;
break;
case SCSI_ALLOW_MEDIUM_REMOVAL:
- dcd_ep_write(device->dcd, eps->ep_in, (rt_uint8_t*)&csw, SIZEOF_CSW);
- dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer, SIZEOF_CBW);
+ _send_status(device, eps, &csw);
break;
case SCSI_READ_CAPACITIES:
_read_capacities(device, eps->ep_in);
@@ -425,6 +436,10 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
case SCSI_VERIFY_10:
_verify_10(device);
break;
+ case SCSI_START_STOP:
+ _start_stop(cbw);
+ _send_status(device, eps, &csw);
+ break;
}
}
else if(status == STATUS_RECEIVE)
@@ -439,9 +454,7 @@ static rt_err_t _ep_out_handler(udevice_t device, uclass_t cls, rt_size_t size)
_block ++;
if(_size == 0)
{
- dcd_ep_write(device->dcd, eps->ep_in, (rt_uint8_t*)&csw, SIZEOF_CSW);
- dcd_ep_read(device->dcd, eps->ep_out, eps->ep_out->buffer, SIZEOF_CBW);
- status = STATUS_CBW;
+ _send_status(device, eps, &csw);
}
else
{
diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c
index 48fc69895c..2be6bd76a9 100644
--- a/components/drivers/usb/usbdevice/core/core.c
+++ b/components/drivers/usb/usbdevice/core/core.c
@@ -734,8 +734,8 @@ rt_err_t _reset_notify(udevice_t device)
RT_ASSERT(device != RT_NULL);
- _stop_notify();
- _run_notify();
+ _stop_notify(device);
+ _run_notify(device);
return RT_EOK;
}