本文整理汇总了C++中USB_STOR_PRINTF函数的典型用法代码示例。如果您正苦于以下问题:C++ USB_STOR_PRINTF函数的具体用法?C++ USB_STOR_PRINTF怎么用?C++ USB_STOR_PRINTF使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了USB_STOR_PRINTF函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: usb_stor_CB_reset
/* FIXME: this reset function doesn't really reset the port, and it
* should. Actually it should probably do what it's doing here, and
* reset the port physically
*/
static int usb_stor_CB_reset(struct us_data *us)
{
unsigned char cmd[12];
int result;
USB_STOR_PRINTF("CB_reset\n");
memset(cmd, 0xff, sizeof(cmd));
cmd[0] = SCSI_SEND_DIAG;
cmd[1] = 4;
result = usb_control_msg(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev, 0),
US_CBI_ADSC,
USB_TYPE_CLASS | USB_RECIP_INTERFACE,
0, us->ifnum, cmd, sizeof(cmd),
USB_CNTL_TIMEOUT * 5);
/* long wait for reset */
mdelay(1500);
USB_STOR_PRINTF("CB_reset result %d: status %lX"
" clearing endpoint halt\n", result,
us->pusb_dev->status);
usb_clear_halt(us->pusb_dev, usb_rcvbulkpipe(us->pusb_dev, us->ep_in));
usb_clear_halt(us->pusb_dev, usb_rcvbulkpipe(us->pusb_dev, us->ep_out));
USB_STOR_PRINTF("CB_reset done\n");
return 0;
}
示例2: usb_stor_CB_transport
int usb_stor_CB_transport(ccb *srb, struct us_data *us)
{
int result,status;
ccb *psrb;
ccb reqsrb;
int retry,notready;
psrb=&reqsrb;
status=USB_STOR_TRANSPORT_GOOD;
retry=0;
notready=0;
/* issue the command */
do_retry:
result=usb_stor_CB_comdat(srb,us);
USB_STOR_PRINTF("command / Data returned %d, status %X\n",result,us->pusb_dev->status);
/* if this is an CBI Protocol, get IRQ */
if(us->protocol==US_PR_CBI) {
status=usb_stor_CBI_get_status(srb,us);
/* if the status is error, report it */
if(status==USB_STOR_TRANSPORT_ERROR) {
USB_STOR_PRINTF(" USB CBI Command Error\n");
return status;
}
srb->sense_buf[12]=(unsigned char)(us->ip_data>>8);
srb->sense_buf[13]=(unsigned char)(us->ip_data&0xff);
if(!us->ip_data) {
/* if the status is good, report it */
if(status==USB_STOR_TRANSPORT_GOOD) {
USB_STOR_PRINTF(" USB CBI Command Good\n");
return status;
}
}
}
示例3: usb_stor_scan
/*********************************************************************************
* scan the usb and reports device info
* to the user if mode = 1
* returns current device or -1 if no
*/
int usb_stor_scan(int mode)
{
unsigned char i;
struct usb_device *dev;
USB_STOR_PRINTF("%s\n ",__FUNCTION__);
/* GJ */
memset(usb_stor_buf, 0, sizeof(usb_stor_buf));
if(mode==1) {
printf("scanning bus for storage devices...\n");
}
usb_disable_asynch(1); /* asynch transfer not allowed */
for(i=0; i<USB_MAX_STOR_DEV; i++) {
memset(&usb_dev_desc[i],0,sizeof(block_dev_desc_t));
usb_dev_desc[i].target=0xff;
usb_dev_desc[i].if_type=IF_TYPE_USB;
usb_dev_desc[i].dev=i;
usb_dev_desc[i].part_type=PART_TYPE_UNKNOWN;
usb_dev_desc[i].block_read=usb_stor_read;
}
usb_max_devs=0;
for(i=0; i<USB_MAX_DEVICE; i++) {
dev=usb_get_dev_index(i); /* get device */
USB_STOR_PRINTF("i=%d\n",i);
if(dev==NULL) {
break; /* no more devices avaiable */
}
if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
/* OK, it's a storage device. Iterate over its LUNs
* and populate `usb_dev_desc'.
*/
int lun, max_lun, start = usb_max_devs;
max_lun = usb_get_max_lun(&usb_stor[usb_max_devs]);
for (lun = 0; lun <= max_lun && usb_max_devs < USB_MAX_STOR_DEV; lun++) {
usb_dev_desc[usb_max_devs].lun = lun;
if (usb_stor_get_info(dev, &usb_stor[start],
&usb_dev_desc[usb_max_devs]) == 1) {
usb_max_devs++;
}
}
}
/* if storage device */
if(usb_max_devs==USB_MAX_STOR_DEV) {
printf("max USB Storage Device reached: %d stopping\n",usb_max_devs);
break;
}
} /* for */
usb_disable_asynch(0); /* asynch transfer allowed */
printf("%d Storage Device(s) found\n", usb_max_devs);
if(usb_max_devs>0)
return 0;
else
return-1;
}
示例4: usb_get_max_lun
static unsigned int usb_get_max_lun(struct us_data *us)
{
int len;
unsigned char result;
USB_STOR_PRINTF("%s\n ",__FUNCTION__);
len = usb_control_msg(us->pusb_dev,
usb_rcvctrlpipe(us->pusb_dev, 0),
US_BBB_GET_MAX_LUN,
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
0, us->ifnum,
&result, sizeof(result),
1);
USB_STOR_PRINTF("Get Max LUN -> len = %i, result = %i\n", len, (int) result);
return (len > 0) ? result : 0;
}
示例5: usb_stor_BBB_comdat
/*
* Set up the command for a BBB device. Note that the actual SCSI
* command is copied into cbw.CBWCDB.
*/
static int usb_stor_BBB_comdat(ccb *srb, struct us_data *us)
{
int result;
int actlen;
int dir_in;
unsigned int pipe;
ALLOC_CACHE_ALIGN_BUFFER(umass_bbb_cbw_t, cbw_buf, 1);
umass_bbb_cbw_t *cbw = (umass_bbb_cbw_t *)KSEG1ADDR(cbw_buf);
dir_in = US_DIRECTION(srb->cmd[0]);
#ifdef BBB_COMDAT_TRACE
printf("dir %d lun %d cmdlen %d cmd %p datalen %lu pdata %p\n",
dir_in, srb->lun, srb->cmdlen, srb->cmd, srb->datalen,
srb->pdata);
if (srb->cmdlen) {
for (result = 0; result < srb->cmdlen; result++)
printf("cmd[%d] %#x ", result, srb->cmd[result]);
printf("\n");
}
#endif
/* sanity checks */
if (!(srb->cmdlen <= CBWCDBLENGTH)) {
USB_STOR_PRINTF("usb_stor_BBB_comdat:cmdlen too large\n");
return -1;
}
/* always OUT to the ep */
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
cbw->dCBWSignature = cpu_to_le32(CBWSIGNATURE);
cbw->dCBWTag = cpu_to_le32(CBWTag++);
cbw->dCBWDataTransferLength = cpu_to_le32(srb->datalen);
cbw->bCBWFlags = (dir_in ? CBWFLAGS_IN : CBWFLAGS_OUT);
cbw->bCBWLUN = srb->lun;
cbw->bCDBLength = srb->cmdlen;
/* copy the command data into the CBW command data buffer */
/* DST SRC LEN!!! */
memcpy(cbw->CBWCDB, srb->cmd, srb->cmdlen);
result = usb_bulk_msg(us->pusb_dev, pipe, cbw, UMASS_BBB_CBW_SIZE,
&actlen, USB_CNTL_TIMEOUT * 5);
if (result < 0)
USB_STOR_PRINTF("usb_stor_BBB_comdat:usb_bulk_msg error\n");
return result;
}
示例6: usb_stor_scan
/*******************************************************************************
* scan the usb and reports device info
* to the user if mode = 1
* returns current device or -1 if no
*/
int usb_stor_scan(int mode)
{
unsigned char i;
struct usb_device *dev;
/* GJ */
memset(usb_stor_buf, 0, sizeof(usb_stor_buf));
if (mode == 1)
printf(" scanning bus for storage devices... ");
usb_disable_asynch(1); /* asynch transfer not allowed */
for (i = 0; i < USB_MAX_STOR_DEV; i++) {
memset(&usb_dev_desc[i], 0, sizeof(block_dev_desc_t));
usb_dev_desc[i].target = 0xff;
usb_dev_desc[i].if_type = IF_TYPE_USB;
usb_dev_desc[i].dev = i;
usb_dev_desc[i].part_type = PART_TYPE_UNKNOWN;
usb_dev_desc[i].block_read = usb_stor_read;
usb_dev_desc[i].block_write = usb_stor_write;
}
usb_max_devs = 0;
for (i = 0; i < USB_MAX_DEVICE; i++) {
dev = usb_get_dev_index(i); /* get device */
USB_STOR_PRINTF("i=%d\n", i);
if (dev == NULL)
break; /* no more devices avaiable */
if (usb_storage_probe(dev, 0, &usb_stor[usb_max_devs])) {
/* ok, it is a storage devices
* get info and fill it in
*/
if (usb_stor_get_info(dev, &usb_stor[usb_max_devs],
&usb_dev_desc[usb_max_devs]) == 1)
usb_max_devs++;
}
/* if storage device */
if (usb_max_devs == USB_MAX_STOR_DEV) {
printf("max USB Storage Device reached: %d stopping\n",
usb_max_devs);
break;
}
} /* for */
usb_disable_asynch(0); /* asynch transfer allowed */
printf("%d Storage Device(s) found\n", usb_max_devs);
if (usb_max_devs > 0)
return 0;
return -1;
}
示例7: usb_get_max_lun
static unsigned int usb_get_max_lun(struct us_data *us)
{
int len;
ALLOC_CACHE_ALIGN_BUFFER(unsigned char, result, 1);
len = usb_control_msg(us->pusb_dev,
usb_rcvctrlpipe(us->pusb_dev, 0),
US_BBB_GET_MAX_LUN,
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
0, us->ifnum,
result, sizeof(char),
USB_CNTL_TIMEOUT * 5);
USB_STOR_PRINTF("Get Max LUN -> len = %i, result = %i\n",
len, (int) *result);
return (len > 0) ? *result : 0;
}
示例8: usb_stor_CB_comdat
/* FIXME: we also need a CBI_command which sets up the completion
* interrupt, and waits for it
*/
int usb_stor_CB_comdat(ccb *srb, struct us_data *us)
{
int result = 0;
int dir_in,retry;
unsigned int pipe;
unsigned long status;
retry=5;
dir_in=US_DIRECTION(srb->cmd[0]);
if(dir_in)
pipe=usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
else
pipe=usb_sndbulkpipe(us->pusb_dev, us->ep_out);
while(retry--) {
USB_STOR_PRINTF("CBI gets a command: Try %d\n",5-retry);
#ifdef USB_STOR_DEBUG
usb_show_srb(srb);
#endif
/* let's send the command via the control pipe */
result = usb_control_msg(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev,0),
US_CBI_ADSC, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
0, us->ifnum,
srb->cmd, srb->cmdlen, USB_CNTL_TIMEOUT*5);
USB_STOR_PRINTF("CB_transport: control msg returned %d, status %X\n",result,us->pusb_dev->status);
/* check the return code for the command */
if (result < 0) {
if(us->pusb_dev->status & USB_ST_STALLED) {
status=us->pusb_dev->status;
USB_STOR_PRINTF(" stall during command found, clear pipe\n");
usb_clear_halt(us->pusb_dev, usb_sndctrlpipe(us->pusb_dev,0));
us->pusb_dev->status=status;
}
USB_STOR_PRINTF(" error during command %02X Stat = %X\n",srb->cmd[0],us->pusb_dev->status);
return result;
}
/* transfer the data payload for this command, if one exists*/
USB_STOR_PRINTF("CB_transport: control msg returned %d, direction is %s to go 0x%lx\n",result,dir_in ? "IN" : "OUT",srb->datalen);
if (srb->datalen) {
result = us_one_transfer(us, pipe, (char *)srb->pdata,srb->datalen);
USB_STOR_PRINTF("CBI attempted to transfer data, result is %d status %lX, len %d\n", result,us->pusb_dev->status,us->pusb_dev->act_len);
if(!(us->pusb_dev->status & USB_ST_NAK_REC))
break;
} /* if (srb->datalen) */
else
break;
}
/* return result */
return result;
}
示例9: usb_stor_CBI_get_status
int usb_stor_CBI_get_status (ccb * srb, struct us_data *us)
{
int timeout;
us->ip_wanted = 1;
submit_int_msg (us->pusb_dev, us->irqpipe,
(void *) &us->ip_data, us->irqmaxp, us->irqinterval);
timeout = 1000;
while (timeout--) {
if ((volatile int *) us->ip_wanted == 0)
break;
wait_ms (10);
}
if (us->ip_wanted) {
printf (" Did not get interrupt on CBI\n");
us->ip_wanted = 0;
return USB_STOR_TRANSPORT_ERROR;
}
USB_STOR_PRINTF
("Got interrupt data 0x%x, transfered %d status 0x%lX\n",
us->ip_data, us->pusb_dev->irq_act_len,
us->pusb_dev->irq_status);
/* UFI gives us ASC and ASCQ, like a request sense */
if (us->subclass == US_SC_UFI) {
if (srb->cmd[0] == SCSI_REQ_SENSE ||
srb->cmd[0] == SCSI_INQUIRY)
return USB_STOR_TRANSPORT_GOOD; /* Good */
else if (us->ip_data)
return USB_STOR_TRANSPORT_FAILED;
else
return USB_STOR_TRANSPORT_GOOD;
}
/* otherwise, we interpret the data normally */
switch (us->ip_data) {
case 0x0001:
return USB_STOR_TRANSPORT_GOOD;
case 0x0002:
return USB_STOR_TRANSPORT_FAILED;
default:
return USB_STOR_TRANSPORT_ERROR;
} /* switch */
return USB_STOR_TRANSPORT_ERROR;
}
示例10: usb_stor_BBB_comdat
/*
* Set up the command for a BBB device. Note that the actual SCSI
* command is copied into cbw.CBWCDB.
*/
int usb_stor_BBB_comdat(ccb *srb, struct us_data *us)
{
int result;
int actlen;
int dir_in;
unsigned int pipe;
umass_bbb_cbw_t cbw;
dir_in = US_DIRECTION(srb->cmd[0]);
#ifdef BBB_COMDAT_TRACE
printf("dir %d lun %d cmdlen %d cmd %p datalen %d pdata %p\n", dir_in, srb->lun, srb->cmdlen, srb->cmd, srb->datalen, srb->pdata);
if (srb->cmdlen) {
for(result = 0; result < srb->cmdlen; result++)
printf("cmd[%d] %#x ", result, srb->cmd[result]);
printf("\n");
}
printf(" us->ep_in %d us->ep_out %d dir_in %d \n", us->ep_in, us->ep_out,dir_in);
#endif
/* sanity checks */
if (!(srb->cmdlen <= CBWCDBLENGTH)) {
USB_STOR_PRINTF("usb_stor_BBB_comdat:cmdlen too large\n");
return -1;
}
/* always OUT to the ep */
pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
cbw.dCBWSignature = swap_32(CBWSIGNATURE);
cbw.dCBWTag = swap_32(CBWTag++);
cbw.dCBWDataTransferLength = swap_32(srb->datalen);
cbw.bCBWFlags = (dir_in? CBWFLAGS_IN : CBWFLAGS_OUT);
cbw.bCBWLUN = srb->lun;
cbw.bCDBLength = srb->cmdlen;
/* copy the command data into the CBW command data buffer */
/* DST SRC LEN!!! */
memcpy(cbw.CBWCDB, srb->cmd, 0x10);
result = usb_bulk_msg(us->pusb_dev, pipe, &cbw, UMASS_BBB_CBW_SIZE, &actlen, USB_CNTL_TIMEOUT);//Charles
return 0 ;
}
示例11: usb_stor_BBB_transport
int usb_stor_BBB_transport(ccb *srb, struct us_data *us)
{
int result, retry;
int dir_in;
int actlen, data_actlen;
unsigned int pipe, pipein, pipeout;
#ifdef BBB_XPORT_TRACE
unsigned char *ptr;
int index;
#endif
dir_in = US_DIRECTION(srb->cmd[0]);
/* COMMAND phase */
USB_STOR_PRINTF("COMMAND phase\n");
result = usb_stor_BBB_comdat(srb, us);
if (result < 0) {
USB_STOR_PRINTF("failed to send CBW status %ld\n",
us->pusb_dev->status);
usb_stor_BBB_reset(us);
return USB_STOR_TRANSPORT_FAILED;
}
pipein = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
pipeout = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
/* DATA phase + error handling */
data_actlen = 0;
/* no data, go immediately to the STATUS phase */
if (srb->datalen == 0)
goto st;
USB_STOR_PRINTF("DATA phase\n");
if (dir_in)
pipe = pipein;
else
pipe = pipeout;
result = usb_bulk_msg(us->pusb_dev, pipe, srb->pdata, srb->datalen, &data_actlen, USB_CNTL_TIMEOUT*5);
/* special handling of STALL in DATA phase */
if((result < 0) && (us->pusb_dev->status & USB_ST_STALLED)) {
USB_STOR_PRINTF("DATA:stall\n");
/* clear the STALL on the endpoint */
result = usb_stor_BBB_clear_endpt_stall(us, dir_in? us->ep_in : us->ep_out);
if (result >= 0)
/* continue on to STATUS phase */
goto st;
}
if (result < 0) {
USB_STOR_PRINTF("usb_bulk_msg error status %ld\n",
us->pusb_dev->status);
usb_stor_BBB_reset(us);
return USB_STOR_TRANSPORT_FAILED;
}
#ifdef BBB_XPORT_TRACE
for (index = 0; index < data_actlen; index++)
printf("pdata[%d] %#x ", index, srb->pdata[index]);
printf("\n");
#endif
/* STATUS phase + error handling */
st:
retry = 0;
again:
USB_STOR_PRINTF("STATUS phase\n");
result = usb_bulk_msg(us->pusb_dev, pipein, &csw, UMASS_BBB_CSW_SIZE,
&actlen, USB_CNTL_TIMEOUT*5);
/* special handling of STALL in STATUS phase */
if((result < 0) && (retry < 1) && (us->pusb_dev->status & USB_ST_STALLED)) {
USB_STOR_PRINTF("STATUS:stall\n");
/* clear the STALL on the endpoint */
result = usb_stor_BBB_clear_endpt_stall(us, us->ep_in);
if (result >= 0 && (retry++ < 1))
/* do a retry */
goto again;
}
if (result < 0) {
USB_STOR_PRINTF("usb_bulk_msg error status %ld\n",
us->pusb_dev->status);
usb_stor_BBB_reset(us);
return USB_STOR_TRANSPORT_FAILED;
}
#ifdef BBB_XPORT_TRACE
ptr = (unsigned char *)&csw;
for (index = 0; index < UMASS_BBB_CSW_SIZE; index++)
printf("ptr[%d] %#x ", index, ptr[index]);
printf("\n");
#endif
/* misuse pipe to get the residue */
pipe = swap_32(csw.dCSWDataResidue);
if (pipe == 0 && srb->datalen != 0 && srb->datalen - data_actlen != 0)
pipe = srb->datalen - data_actlen;
if (CSWSIGNATURE != swap_32(csw.dCSWSignature)) {
USB_STOR_PRINTF("!CSWSIGNATURE\n");
usb_stor_BBB_reset(us);
return USB_STOR_TRANSPORT_FAILED;
} else if ((CBWTag - 1) != swap_32(csw.dCSWTag)) {
USB_STOR_PRINTF("!Tag\n");
usb_stor_BBB_reset(us);
return USB_STOR_TRANSPORT_FAILED;
} else if (csw.bCSWStatus > CSWSTATUS_PHASE) {
USB_STOR_PRINTF(">PHASE\n");
//.........这里部分代码省略.........
示例12: us_one_transfer
static int us_one_transfer(struct us_data *us, int pipe, char *buf, int length)
{
int max_size;
int this_xfer;
int result;
int partial;
int maxtry;
int stat;
/* determine the maximum packet size for these transfers */
max_size = usb_maxpacket(us->pusb_dev, pipe) * 16;
/* while we have data left to transfer */
while (length) {
/* calculate how long this will be -- maximum or a remainder */
this_xfer = length > max_size ? max_size : length;
length -= this_xfer;
/* setup the retry counter */
maxtry = 10;
/* set up the transfer loop */
do {
/* transfer the data */
USB_STOR_PRINTF("Bulk xfer 0x%x(%d) try #%d\n",
(unsigned int)buf, this_xfer, 11 - maxtry);
result = usb_bulk_msg(us->pusb_dev, pipe, buf,
this_xfer, &partial, USB_CNTL_TIMEOUT*5);
USB_STOR_PRINTF("bulk_msg returned %d xferred %d/%d\n",
result, partial, this_xfer);
if(us->pusb_dev->status!=0) {
/* if we stall, we need to clear it before we go on */
#ifdef USB_STOR_DEBUG
display_int_status(us->pusb_dev->status);
#endif
if (us->pusb_dev->status & USB_ST_STALLED) {
USB_STOR_PRINTF("stalled ->clearing endpoint halt for pipe 0x%x\n", pipe);
stat = us->pusb_dev->status;
usb_clear_halt(us->pusb_dev, pipe);
us->pusb_dev->status=stat;
if(this_xfer == partial) {
USB_STOR_PRINTF("bulk transferred with error %X, but data ok\n",us->pusb_dev->status);
return 0;
}
else
return result;
}
if (us->pusb_dev->status & USB_ST_NAK_REC) {
USB_STOR_PRINTF("Device NAKed bulk_msg\n");
return result;
}
if(this_xfer == partial) {
USB_STOR_PRINTF("bulk transferred with error %d, but data ok\n",us->pusb_dev->status);
return 0;
}
/* if our try counter reaches 0, bail out */
USB_STOR_PRINTF("bulk transferred with error %d, data %d\n",us->pusb_dev->status,partial);
if (!maxtry--)
return result;
}
/* update to show what data was transferred */
this_xfer -= partial;
buf += partial;
/* continue until this transfer is done */
} while ( this_xfer );
}
/* if we get here, we're done and successful */
return 0;
}