5.4. Fields in a URB

A URB contains four main fields which the driver can manipulate and read when performing transactions. The structure does contain additional fields for use by the USB system these are detailed in the host controller writing book.

Direct manipulation of the fields when not using the C api is discouraged, instead two library calls have been provided, one to examine the URB fields (USBLib_URBInfo (SWI &56360)) and one to set the URB fields (USBLib_SetURB (SWI &56361))

The four fields of interest are shown in the (incomplete) structure definition below (the definition drivers should use is in Section 2.14, “structs.h”). The offsets and specific values can be found in Table A.10, “URB driver fields”.

struct usb_io_buffer_s
{
  void *pointer_to_data;
  unsigned long size;
  unsigned long used_size;
  unsigned long actual_position;
};
    
pointer_to_data is the pointer to the actual allocated storage the URB refers to.
size is the size of the allocated storage and hence the maximum amount of data that can be held in a URB.
used_size is the amount of data to transfer in a transaction. I.e. the amount of data to transfer from host to device or the maximum amount of data to transfer device to host.
actual_position is the amount of data actually transfered in a transaction. I.e. the amount of data in the buffer that was actually transfered from the device to the host which may be less than the used_size value set if the device doesn't transfer the full amount of data requested.