Giter VIP home page Giter VIP logo

usb3vision's Introduction

usb3vision

Driver for USB3 Vision(TM) class devices

This driver is the kernel piece of a larger driver intended to acquire images from USB3 Vision class devices. USB3 Vision utilizes GenICam, a usermode generic programming interface that translates high-level actions into register read/write operations. Therefore, significant application logic outside of this kernel module is needed to incorporate GenICam and be fully compatible with the USB3Vision specification.

Devices are enumerated at /sys/class/usbmisc/u3vX, where X is a number associated with the camera. From there you can check ./device/device_guid and ensure that you've found the device you are looking for. Then you can open /dev/devX to get a file handle to the device that you can use for interacting with the ioctl interface.

The ioctl interface is provided in u3v_shared.h:

  • U3V_IOCTL_READ
  • U3V_IOCTL_WRITE
  • U3V_IOCTL_GET_STREAM_ALIGNMENT
  • U3V_IOCTL_GET_OS_MAX_TRANSFER
  • U3V_IOCTL_CONFIGURE_STREAM
  • U3V_IOCTL_UNCONFIGURE_STREAM
  • U3V_IOCTL_CONFIGURE_BUFFER
  • U3V_IOCTL_UNCONFIGURE_BUFFER
  • U3V_IOCTL_QUEUE_BUFFER
  • U3V_IOCTL_WAIT_FOR_BUFFER
  • U3V_IOCTL_CANCEL_ALL_BUFFERS
  • U3V_IOCTL_CTRL_MSG
  • U3V_IOCTL_START_EVENTS
  • U3V_IOCTL_WAIT_FOR_EVENT
  • U3V_IOCTL_STOP_EVENTS
  • U3V_IOCTL_CONFIGURE_STREAM2

These functions take a struct as a parameter with any necessary information.

For example, let's look at configuring a buffer. The struct associated with that call looks like this:

struct u3v_configure_buffer {
  void __user *u_image_buffer;
  void __user *u_chunk_data_buffer;
  __u64 __user *u_buffer_handle;
};

Usermode code would create that struct and fill it in, then call the ioctl with the file descriptor you got from opening the device, the macro from u3v_shared, and the struct.

Here's an example:

// Do this just once, at the beginning
char* devicePath = "/dev/u3vX";
int fd = open(devicePath, O_RDWR);
if (fd == -1) {
  // error handling
}
----------------------------------------------------------
// Then ioctl calls would be something like this
struct u3v_configure_buffer configureBuffer;

configureBuffer.u_image_buffer = imageBuffer;           // pointer to user image data buffer
configureBuffer.u_chunk_data_buffer = chunkDataBuffer;  // pointer to user chunk data buffer
configureBuffer.u_buffer_handle = bufferHandle;         // pointer to uint64_t handle that will be populated by the kernel driver

int ret = ioctl(fd, U3V_IOCTL_CONFIGURE_BUFFER, &configureBuffer);
if (ret != 0) {
  // error handling
}

usb3vision's People

Contributors

katieensign avatar mmorin-ni avatar nivzqz avatar

Stargazers

 avatar Bangjie Deng avatar  avatar  avatar Amornthep Phunsin avatar  avatar  avatar DoubleFans avatar Matthias Fauconneau avatar Max Neupert avatar  avatar  avatar BA7LYA avatar Dozimas avatar nahiguchi avatar Martin Kaltenbrunner avatar  avatar 罗颖 avatar  avatar  avatar  avatar lwq avatar  avatar  avatar Gavin Baker avatar Ryan Govostes avatar Kaspter Ju avatar Sagar avatar zorro avatar  avatar Roman Roibu avatar yozora project avatar Kieran Bingham avatar Stefano Sinigardi avatar James Harrison avatar Guangwei Gao avatar wangyilong avatar  avatar Siim Meerits avatar  avatar Mikael Olenfalk avatar Kenzo avatar tasshi / Masaharu Tashiro avatar Dmitriy Lekomtsev avatar H.F. avatar Joe Speed avatar Jeff Galbraith avatar Hao Wu avatar  avatar Shirish Goyal avatar  avatar Mark Retallack avatar Trent Houliston avatar Andrew Straw avatar Emmanuel Pacaud avatar Qiang Zhang avatar Denir Li avatar  avatar  avatar  avatar Chao Qu avatar Steven Lovegrove avatar Eric Gross avatar

Watchers

Emmanuel Pacaud avatar James Cloos avatar Trent Houliston avatar qwer avatar Max Ho avatar  avatar  avatar Scot Salmon avatar  avatar Mark Retallack avatar Christophe Caltagirone avatar Andrew Kushchenko avatar Matthew Giassa avatar  avatar  avatar  avatar  avatar Vijay Sitaram avatar -promise avatar

usb3vision's Issues

Application example ?

Hello,

I would like to ask if there is an application example which shows how to aquire stream ?
I also tried to understand what is the difference between stream and stream2, and queue buffer, but could not understand it. (Is there a documented maybe, that can assist on this) ?
Is this driver functional and being used with applications ?

Thank you!
ranran

Octal check fails on newer kernels

in v3v_core.c:138 following code is not compiling well:

static DEVICE_ATTR(name, S_IWUGO | S_IRUGO, name##_show, name##_store);

Temporary solution is changing this line to :

static DEVICE_ATTR(name, 0660, name##_show, name##_store);

make error

when I try to make this project, error throw
make
make[1]: *** M=/home/nvidia/usb3vision: No such file or directory. Stop.
Makefile:56: recipe for target 'all' failed
make: *** [all] Error 2

I use Nvidia TX2, ubuntu 16.

How to build it?

Hi! I want to build it for my U3V local camera, but I don't know how to build it. When I compile it, it raises a "No such file or dictionary, Stop" error.

USB device number race condition with two Basler cameras...?

I'm trying to debug a device with two Basler cameras attached. The slightly unusual thing about the setup is that the two cameras get powered up long after the device itself has booted, which means that they power on within a few milliseconds of each other.

What happens next:

  • both camera devices get assigned to device number 2 [might this be a race condition?]
  • both then receive ioctl calls to read data (64 bytes @ 0x4, 64 bytes @ 0x44, 64 bytes @ 0x104, and 236 bytes @ 0xF2F01014), all of which execute successfully
  • both are then disconnected (though I can't see any reason why)
  • neither ever retries
[  274.907118] usb 7-1: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd
[  274.919114] usb 5-1: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd
[  274.930551] usb 7-1: New USB device found, idVendor=2676, idProduct=ba02, bcdDevice= 0.00
[  274.940094] usb 7-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  274.947543] usb 5-1: New USB device found, idVendor=2676, idProduct=ba02, bcdDevice= 0.00
[  274.948405] usb 7-1: Product: acA1920-40ucSIE
[  274.957893] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  274.962942] usb 7-1: Manufacturer: Basler
[  274.962958] usb 7-1: SerialNumber: xxxxxx61
[  274.971260] usb 5-1: Product: acA1920-40umSIR
[  274.985886] usb 5-1: Manufacturer: Basler
[  274.990574] usb 5-1: SerialNumber: xxxxxx46
[  276.902008] usb 7-1: USB3 Vision Driver: Registering device 2
[  276.917003] usb 5-1: USB3 Vision Driver: Registering device 2
[  279.736960] usb 5-1: USB disconnect, device number 2
[  279.743963] usb 5-1: u3v_disconnect: U3V device removed
[  279.744925] usb 7-1: USB disconnect, device number 2
[  279.756172] usb 7-1: u3v_disconnect: U3V device removed

If I attach just one USB camera:

  • that camera gets assigned to device number 2
  • it then fails (and gets disconnected)
  • it then retries but assigned to device number 3
  • it then succeeds
[  102.395806] usb 7-1: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd
[  102.419240] usb 7-1: New USB device found, idVendor=2676, idProduct=ba02, bcdDevice= 0.00
[  102.428777] usb 7-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  102.437075] usb 7-1: Product: acA1920-40ucSIE
[  102.442176] usb 7-1: Manufacturer: Basler
[  102.446864] usb 7-1: SerialNumber: xxxxxx61
[  104.382790] usb 7-1: USB3 Vision Driver: Registering device 2
[  116.217618] usb 7-1: USB disconnect, device number 2
[  116.223727] usb 7-1: u3v_disconnect: U3V device removed
[  126.427855] usb 7-1: new SuperSpeed Gen 1 USB device number 3 using xhci_hcd
[  126.451920] usb 7-1: New USB device found, idVendor=2676, idProduct=ba02, bcdDevice= 0.00
[  126.461444] usb 7-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  126.469749] usb 7-1: Product: acA1920-40ucSIE
[  126.474851] usb 7-1: Manufacturer: Basler
[  126.479537] usb 7-1: SerialNumber: xxxxxx61
[  128.411722] usb 7-1: USB3 Vision Driver: Registering device 3

To me, this feels like either a weird U3V error or a USB device number race condition deep inside Linux, though I could easily be wrong about both. What might be going on here? What should I be looking at?

Open() system call causes internal error

Hi,
Post deploying this driver I had tried to read the device file enumerated at /dev/U3V0 from a user application and just included some validating print statement to check whether the device file could be opened as shown in the code below.the open system call is causing the system to generate the internal error and the process hangs.
when i run dmesg i observe the following bug:
BUG:Unable to handle Kernel NULL pointer dereference at(null)
The system generates an internal errror.
However I get a Device file Opened succesfully message but the user process hangs.
Any suggestion on what could be prob and whats the solution is very much helpful.Thanks in advance

Scatter/gather list failure with Basler camera under Debian Bullseye...?

I'm trying to get the latest U3V working under Debian Bullseye, but this is yielding lots of scatter/gather list failures like this:

usb 7-1: calculate_sglist_entries: invalid buffer: if sg_constraint is true, a buffer can only have a scatterlist entry smaller than w_max_packet_size if it's the first or last in the list
usb 7-1: create_buffer: Creating sglist failed with error -131072

Enabling the debug output in calculate_urb_sizes prints out this:

[  121.185909] usb 7-1: calculate_urb_sizes: host image buffer size = 4608000
[  121.193996] usb 7-1: calculate_urb_sizes: device image buffer size = 4608000
[  121.202303] usb 7-1: calculate_urb_sizes: chunk data buffer size = 64
[  121.209867] usb 7-1: calculate_urb_sizes: payload size = 65536
[  121.216746] usb 7-1: calculate_urb_sizes: payload count = 70
[  121.223409] usb 7-1: calculate_urb_sizes: transfer1 = 20480
[  121.229981] usb 7-1: calculate_urb_sizes: transfer2 = 64
[  121.236223] usb 7-1: calculate_urb_sizes: transfer2_data = 64
[  121.242999] usb 7-1: calculate_urb_sizes: max_pglist_count = 1
[  121.249871] usb 7-1: calculate_urb_sizes: alignment_padding = 0
[  121.256818] usb 7-1: calculate_urb_sizes: segment_padding = 0
[  121.263565] usb 7-1: calculate_urb_sizes: segment_size = 4608000
[  121.270641] usb 7-1: calculate_urb_sizes: sg_constraint = true

The problem seems to be that if the desired first USB transaction length of a set is not a multiple of the max packet size (i.e. before being clipped), then the code can cause a second consecutive non-multiple of the max packet size to be emitted, depending on the page alignment.

The specific case causing the problem for me has bytes_remaining = 65536, which is triggering an initial bytes_to_transfer value of 2944, which is then being rounded down to 2048 (because the max packet size is 1024). The second packet is then getting sized to 896 bytes (to go to the page boundary), which is triggering the error condition.

My patch attempting to fix this issue looks like this:

			if (stream->config.sg_constraint) {
				if (bytes_to_transfer > w_max_packet_size) {
					// If this isn't the first packet or the last packet
					if ( (sg_count != 0) && (bytes_to_transfer != pglist_bytes_remaining) ) {
						// If the transfer size is not a multiple of the packet size
						int remainder = bytes_to_transfer % w_max_packet_size;
						if (remainder) {
							// Round the transfer size down to be a multiple of the packet size
							bytes_to_transfer -= remainder;
						}
					}
				} else if (bytes_to_transfer < w_max_packet_size

This prevents the scatter/gather failures, but instead yields a different warning when the packet is received:

[ 2382.175004] usb 7-1: stream_urb_completion: entry 90, urb 72: length = 40, expected >=64

So I'm not sure if my fix is actually fixing the problem.

Is this whole thing a known issue? Or might it be being triggered by something else entirely, e.g. the memory alignment of the USB buffers?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.