2.3. Application Drivers

Application drivers are the simplest drivers to implement. The USB side of their implementation probably represents a small part of the total code that will be written. The general areas that need to be considered are:-

Locating a device

Locating a device is discussed in Chapter 3, Driver Initialisation support routines are provided for most operations a driver needs to perform, the suggested approach is that a driver should parse its command line using usblib_parse_cmd_line(USBLib_ParseCmdLine (SWI &56375)) looking for a new device message and if that does not exist (driver not run by USB system) use the usb_devmgr_find_free(USBLib_DevMgrFindFree (SWI &5635A)) calls to find and then claim the device. This simply obtains the new device message by either means and gives the driver writer the flexibility to have their driver started by the USB system if they require. The command line scanning may be omitted if required.

Obtaining necessary pipes

Once a device has been located the information in the message can be used to open pipes, and configure the device as required. Most drivers allocate several URBs at this point to use throughout the drivers lifetime, this is especially useful if the control pipe has been opened and the driver is likely to be sending a number of control messages.

Performing transactions

The driver will then proceed to issue transactions as required using the pipes it opened during its initialisation phase. It has been noted that the waiting constructs cause some driver writers problems understanding their concept, please refer to Chapter 6, Waiting for more details on the waiting concept.

Stopping and freeing resources

All resources including references must be suitably freed or dereferenced as appropriate. If this does not happen resources may be lost and become unavailable until the USB system is re-started. Care should be taken to release the device back into the unclaimed device pool and ensure all URBs are freed otherwise the driver will not be able to obtain the device for use a second time.