|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2013-3-5 11:52:39
|
显示全部楼层
modelsim 发表于 2013-3-1 20:46 ![](static/image/common/back.gif)
63字节 65字节都可以 反正不能是64字节 应该和是否溢出也没多大关系吧
bug好像就在这一块
/*
* return: 0 = still running, 1 = queue empty, negative = errno
*/
static int s3c2410_udc_read_fifo(struct s3c2410_ep *ep,
struct s3c2410_request *req)
{
u8 *buf = NULL;
u32 ep_csr;
unsigned bufferspace;
int is_last=1;
unsigned avail;
int fifo_count = 0;
u32 idx;
int fifo_reg;
idx = ep->bEndpointAddress & 0x7F;
switch (idx) {
default:
idx = 0;
case 0:
fifo_reg = S3C2410_UDC_EP0_FIFO_REG;
break;
case 1:
fifo_reg = S3C2410_UDC_EP1_FIFO_REG;
break;
case 2:
fifo_reg = S3C2410_UDC_EP2_FIFO_REG;
break;
case 3:
fifo_reg = S3C2410_UDC_EP3_FIFO_REG;
break;
case 4:
fifo_reg = S3C2410_UDC_EP4_FIFO_REG;
break;
}
if (!req->req.length)
return 1;
printk("%s req->req.length : %d\n", "s3c2410_udc_read_fifo", req->req.length);//tyc
printk("%s req->req.actual : %d\n", "s3c2410_udc_read_fifo", req->req.actual);//tyc
again:
buf = req->req.buf + req->req.actual;
bufferspace = req->req.length - req->req.actual;
if (!bufferspace)
return -1;
udc_write(idx, S3C2410_UDC_INDEX_REG);
fifo_count = s3c2410_udc_fifo_count_out();
printk("%s fifo_count : %d\n", "s3c2410_udc_fifo_count_out", fifo_count); //tyc
if (fifo_count > ep->ep.maxpacket) {
avail = ep->ep.maxpacket;
}
else {
avail = fifo_count;
}
fifo_count = s3c2410_udc_read_packet(fifo_reg, buf, req, avail);
printk("%s fifo_count : %d\n", "s3c2410_udc_read_packet", fifo_count); //tyc
// checking this with ep0 is not accurate as we already read a control request
if (idx != 0 && fifo_count < ep->ep.maxpacket) { //这个地方只能判断当数据小于64字节时认为是最后一包数据,如果最后一包数据恰好是64字节呢
is_last = 1;
// overflowed this request? flush extra data
if (fifo_count != avail)
req->req.status = -EOVERFLOW;
}
else {
is_last = (req->req.length <= req->req.actual) ? 1 : 0;
printk("%s req->req.length : %d\n", "s3c2410_udc_read_fifo_is_last", req->req.length);//tyc
printk("%s req->req.actual : %d\n", "s3c2410_udc_read_fifo_is_last", req->req.actual);//tyc
}
udc_write(idx, S3C2410_UDC_INDEX_REG);
fifo_count = s3c2410_udc_fifo_count_out();
// Only ep0 debug messages are interesting
if (idx == 0)
dprintk(DEBUG_NORMAL,"%s fifo count : %d [last %d]\n", __func__, fifo_count,is_last);
if (is_last) {
if (idx == 0) {
s3c2410_udc_set_ep0_de_out(base_addr);
ep->dev->ep0state = EP0_IDLE;
}
else {
udc_write(idx, S3C2410_UDC_INDEX_REG);
ep_csr = udc_read(S3C2410_UDC_OUT_CSR1_REG);
udc_write(idx, S3C2410_UDC_INDEX_REG);
udc_write(ep_csr & ~S3C2410_UDC_OCSR1_PKTRDY, S3C2410_UDC_OUT_CSR1_REG);
s3c2410_udc_done(ep, req, 0);
}
}
else {
if (idx == 0)
s3c2410_udc_clear_ep0_opr(base_addr);
else {
udc_write(idx, S3C2410_UDC_INDEX_REG);
ep_csr = udc_read(S3C2410_UDC_OUT_CSR1_REG);
udc_write(idx, S3C2410_UDC_INDEX_REG);
udc_write(ep_csr & ~S3C2410_UDC_OCSR1_PKTRDY, S3C2410_UDC_OUT_CSR1_REG);
}
}
//udc_write(idx, S3C2410_UDC_INDEX_REG);
fifo_count = s3c2410_udc_fifo_count_out();
if( (( EP_FIFO_SIZE == fifo_count) || ((req->req.length - req->req.actual) == fifo_count) )&& (!is_last) )
goto again;
return is_last;
}
请问这段代码,当最后一包数据恰好是64字节的情况如何能确定这就是最后一包数据 |
|