1
0
Fork 0
forked from len0rd/rockbox

USB related Cosmetics, whitespace and readability fixes (FS#10147 by Tomer Shalev)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20737 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Frank Gevaerts 2009-04-18 21:32:41 +00:00
parent 069191d9d4
commit 00b407b04f
6 changed files with 139 additions and 158 deletions

View file

@ -95,8 +95,7 @@ enum {
USB_DRIVER_CHARGING_ONLY,
USB_NUM_DRIVERS
};
#endif
#ifdef HAVE_USBSTACK
struct usb_transfer_completion_event_data
{
unsigned char endpoint;

View file

@ -46,7 +46,6 @@ static struct usb_interface_descriptor __attribute__((aligned(2)))
.iInterface = 0
};
static int usb_interface;
int usb_charging_only_request_endpoints(struct usb_class_driver *drv)

View file

@ -100,7 +100,6 @@ static struct usb_config_descriptor __attribute__((aligned(2)))
.bMaxPower = (USB_MAX_CURRENT+1) / 2, /* In 2mA units */
};
static const struct usb_qualifier_descriptor __attribute__((aligned(2)))
qualifier_descriptor =
{
@ -242,7 +241,6 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req);
static unsigned char response_data[256] USB_DEVBSS_ATTR;
static short hex[16] = {'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F'};
#ifdef IPOD_ARCH
@ -364,8 +362,8 @@ void usb_core_exit(void)
if (initialized) {
usb_drv_exit();
}
initialized = false;
}
usb_state = DEFAULT;
logf("usb_core_exit() finished");
}
@ -373,6 +371,7 @@ void usb_core_exit(void)
void usb_core_handle_transfer_completion(
struct usb_transfer_completion_event_data* event)
{
completion_handler_t handler;
int ep = event->endpoint;
switch(ep) {
@ -382,9 +381,9 @@ void usb_core_handle_transfer_completion(
(struct usb_ctrlrequest*)event->data);
break;
default:
if(ep_data[ep].completion_handler[event->dir>>7] != NULL)
ep_data[ep].completion_handler[event->dir>>7](ep,event->dir,
event->status,event->length);
handler = ep_data[ep].completion_handler[event->dir>>7];
if(handler != NULL)
handler(ep,event->dir,event->status,event->length);
break;
}
}
@ -403,8 +402,7 @@ bool usb_core_any_exclusive_storage(void)
{
int i;
for(i=0;i<USB_NUM_DRIVERS;i++) {
if(drivers[i].enabled &&
drivers[i].needs_exclusive_storage)
if(drivers[i].enabled && drivers[i].needs_exclusive_storage)
{
return true;
}
@ -418,8 +416,7 @@ void usb_core_hotswap_event(int volume,bool inserted)
{
int i;
for(i=0;i<USB_NUM_DRIVERS;i++) {
if(drivers[i].enabled &&
drivers[i].notify_hotswap!=NULL)
if(drivers[i].enabled && drivers[i].notify_hotswap!=NULL)
{
drivers[i].notify_hotswap(volume,inserted);
}
@ -762,19 +759,23 @@ void usb_core_bus_reset(void)
/* called by usb_drv_transfer_completed() */
void usb_core_transfer_complete(int endpoint, int dir, int status,int length)
{
struct usb_transfer_completion_event_data *completion_event;
switch (endpoint) {
case EP_CONTROL:
/* already handled */
break;
default:
ep_data[endpoint].completion_event.endpoint=endpoint;
ep_data[endpoint].completion_event.dir=dir;
ep_data[endpoint].completion_event.data=0;
ep_data[endpoint].completion_event.status=status;
ep_data[endpoint].completion_event.length=length;
completion_event = &ep_data[endpoint].completion_event;
completion_event->endpoint=endpoint;
completion_event->dir=dir;
completion_event->data=0;
completion_event->status=status;
completion_event->length=length;
/* All other endoints. Let the thread deal with it */
usb_signal_transfer_completion(&ep_data[endpoint].completion_event);
usb_signal_transfer_completion(completion_event);
break;
}
}
@ -782,18 +783,21 @@ void usb_core_transfer_complete(int endpoint, int dir, int status,int length)
/* called by usb_drv_int() */
void usb_core_control_request(struct usb_ctrlrequest* req)
{
ep_data[0].completion_event.endpoint=0;
ep_data[0].completion_event.dir=0;
ep_data[0].completion_event.data=(void *)req;
ep_data[0].completion_event.status=0;
ep_data[0].completion_event.length=0;
struct usb_transfer_completion_event_data *completion_event =
&ep_data[0].completion_event;
completion_event->endpoint=0;
completion_event->dir=0;
completion_event->data=(void *)req;
completion_event->status=0;
completion_event->length=0;
logf("ctrl received %ld",current_tick);
usb_signal_transfer_completion(&ep_data[0].completion_event);
usb_signal_transfer_completion(completion_event);
}
int usb_core_ack_control(struct usb_ctrlrequest* req)
{
if (req->bRequestType & 0x80)
if (req->bRequestType & USB_DIR_IN)
return usb_drv_recv(EP_CONTROL, NULL, 0);
else
return usb_drv_send(EP_CONTROL, NULL, 0);
@ -802,13 +806,6 @@ int usb_core_ack_control(struct usb_ctrlrequest* req)
#ifdef HAVE_USB_POWER
unsigned short usb_allowed_current()
{
if (usb_state == CONFIGURED)
{
return MAX(USB_MAX_CURRENT, 100);
}
else
{
return 100;
}
return (usb_state == CONFIGURED) ? MAX(USB_MAX_CURRENT, 100) : 100;
}
#endif

View file

@ -46,7 +46,8 @@ static struct usb_interface_descriptor __attribute__((aligned(2)))
};
static struct usb_endpoint_descriptor __attribute__((aligned(2))) endpoint_descriptor =
static struct usb_endpoint_descriptor __attribute__((aligned(2)))
endpoint_descriptor =
{
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = USB_DT_ENDPOINT,
@ -77,12 +78,10 @@ static int usb_interface;
int usb_serial_request_endpoints(struct usb_class_driver *drv)
{
ep_in = usb_core_request_endpoint(USB_DIR_IN, drv);
if (ep_in < 0)
return -1;
ep_out = usb_core_request_endpoint(USB_DIR_OUT, drv);
if (ep_out < 0) {
usb_core_release_endpoint(ep_in);
return -1;
@ -97,7 +96,6 @@ int usb_serial_set_first_interface(int interface)
return interface + 1;
}
int usb_serial_get_config_descriptor(unsigned char *dest, int max_packet_size)
{
unsigned char *orig_dest = dest;
@ -245,12 +243,9 @@ void usb_serial_transfer_complete(int ep,int dir, int status, int length)
}
if(buffer_length>0)
{
sendout();
}
break;
}
}
#endif /*USB_SERIAL*/

View file

@ -478,8 +478,7 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
#else
int result = storage_write_sectors(cur_cmd.lun,
cur_cmd.sector,
MIN(BUFFER_SIZE/SECTOR_SIZE,
cur_cmd.count),
MIN(BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count),
cur_cmd.data[cur_cmd.data_select]);
if(result != 0) {
send_csw(UMS_STATUS_FAIL);
@ -489,7 +488,6 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
break;
}
#endif
if(next_count==0) {
send_csw(UMS_STATUS_GOOD);
}
@ -499,7 +497,6 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
cur_cmd.sector = next_sector;
cur_cmd.count = next_count;
}
else {
logf("Transfer failed %X",status);
@ -622,7 +619,6 @@ bool usb_storage_control_request(struct usb_ctrlrequest* req, unsigned char* des
usb_drv_reset_endpoint(ep_in, false);
usb_drv_reset_endpoint(ep_out, true);
#endif
usb_drv_send(EP_CONTROL, NULL, 0); /* ack */
handled = true;
break;
@ -660,8 +656,7 @@ static void send_and_read_next(void)
#else
cur_cmd.last_result = storage_read_sectors(cur_cmd.lun,
cur_cmd.sector,
MIN(BUFFER_SIZE/SECTOR_SIZE,
cur_cmd.count),
MIN(BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count),
cur_cmd.data[cur_cmd.data_select]);
#endif
}
@ -834,6 +829,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
}
break;
}
case SCSI_MODE_SENSE_6: {
if(!lun_present) {
send_command_failed_result();
@ -907,18 +903,17 @@ static void handle_scsi(struct command_block_wrapper* cbw)
case SCSI_ALLOW_MEDIUM_REMOVAL:
logf("scsi allow_medium_removal %d",lun);
if((cbw->command_block[4] & 0x03) == 0)
{
if((cbw->command_block[4] & 0x03) == 0) {
locked[lun]=false;
queue_broadcast(SYS_USB_LUN_LOCKED, (lun<<16)+0);
}
else
{
else {
locked[lun]=true;
queue_broadcast(SYS_USB_LUN_LOCKED, (lun<<16)+1);
}
send_csw(UMS_STATUS_GOOD);
break;
case SCSI_READ_FORMAT_CAPACITY: {
logf("scsi read_format_capacity %d",lun);
if(lun_present) {
@ -934,8 +929,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
send_command_result(tb.format_capacity_data,
MIN(sizeof(struct format_capacity), length));
}
else
{
else {
send_command_failed_result();
cur_sense_data.sense_key=SENSE_NOT_READY;
cur_sense_data.asc=ASC_MEDIUM_NOT_PRESENT;
@ -943,6 +937,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
}
break;
}
case SCSI_READ_CAPACITY: {
logf("scsi read_capacity %d",lun);
@ -956,8 +951,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
send_command_result(tb.capacity_data,
MIN(sizeof(struct capacity), length));
}
else
{
else {
send_command_failed_result();
cur_sense_data.sense_key=SENSE_NOT_READY;
cur_sense_data.asc=ASC_MEDIUM_NOT_PRESENT;
@ -1004,8 +998,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
#else
cur_cmd.last_result = storage_read_sectors(cur_cmd.lun,
cur_cmd.sector,
MIN(BUFFER_SIZE/SECTOR_SIZE,
cur_cmd.count),
MIN(BUFFER_SIZE/SECTOR_SIZE, cur_cmd.count),
cur_cmd.data[cur_cmd.data_select]);
#ifdef TOSHIBA_GIGABEAT_S
@ -1049,10 +1042,8 @@ static void handle_scsi(struct command_block_wrapper* cbw)
}
else {
receive_block_data(cur_cmd.data[0],
MIN(BUFFER_SIZE,
cur_cmd.count*SECTOR_SIZE));
MIN(BUFFER_SIZE, cur_cmd.count*SECTOR_SIZE));
}
break;
default:
@ -1127,8 +1118,8 @@ static void copy_padded(char *dest, char *src, int len)
/* build SCSI INQUIRY */
static void fill_inquiry(IF_MV_NONVOID(int lun))
{
memset(tb.inquiry, 0, sizeof(struct inquiry_data));
struct storage_info info;
memset(tb.inquiry, 0, sizeof(struct inquiry_data));
storage_get_info(lun,&info);
copy_padded(tb.inquiry->VendorId,info.vendor,sizeof(tb.inquiry->VendorId));
copy_padded(tb.inquiry->ProductId,info.product,sizeof(tb.inquiry->ProductId));