Data Reading with LinuxUSB driver

Source: Internet
Author: User
Linux universal technology-Linux technology and application information. For details, see the following section. I used a USB driver framework to rewrite a driver that communicates with the ARM Development Board, but found that reading data from the device was slow.
I took the Development Board to windows for reading. The speed is very fast and it is normal. If the Frame Rate in windows is 50 frames, I will use this driver for about 10 frames in linux!
The read code is as follows:
CODE: static ssize_t device_driver_read (struct file * filp, char * user_buffer, size_t count, loff_t * ppos)
{
Struct device_device * dev;
Int retval = 0;
Int readed_size = 0;
Int bytes_read;

Dev = (struct usb_skel *) filp-> private_data;

While (1)
{
Retval = usb_bulk_msg (dev-> device,
Usb_rcvbulkpipe (dev-> device, dev-> bulk_in_endpoint_addr ),
Dev-> bulk_in_buffer,
Dev-> bulk_in_size,
& Bytes_read, 1000 );

If (retval = 0)
{
If (readed_size + bytes_read <= count)
{
If (bytes_read> 0)
{
If (copy_to_user (user_buffer + readed_size, dev-> bulk_in_buffer, bytes_read ))
{
Err ("copy_to_use error ");
Retval =-EFAULT;
Break;
}
}
}
Readed_size + = bytes_read;
If (bytes_read <64)
{
Retval = readed_size;
Break;
}
}
Else
{
Err ("usb_bulk_msg error: % d", retval );
Break;
}
}

Return retval;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.