主题 : 关于s3c2410_udc_read_fifo这个函数 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 34579
精华: 0
发帖: 18
金钱: 90 两
威望: 18 点
综合积分: 36 分
注册时间: 2010-12-17
最后登录: 2013-05-28
楼主  发表于: 2013-03-05 11:50

 关于s3c2410_udc_read_fifo这个函数

/*
* 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字节的情况如何能确定这就是最后一包数据
级别: 新手上路
UID: 12707
精华: 0
发帖: 12
金钱: 60 两
威望: 12 点
综合积分: 24 分
注册时间: 2010-01-12
最后登录: 2021-03-23
1楼  发表于: 2013-03-26 23:23
请问楼主:
你有没有MATRIX V便携式单板机简介(型号S3C-2410X):

的光盘资料吗?