There are the following functions to configure USB Module:
Before an USB host controller driver can use the USB Module it must register itself. Of course it must deregister itself if it wants to stop. One registration must be done for each USB. This means that the same USB host controller driver can control multiple USB controllers but it must register itself one time for each of USB controllers to the USB Module.
Due to USB concept connection of devices to the USB can be detected only by scanning the USB-Hubs. For USB-Hubs are a special kind of devices there is a special module to handle them. This module makes usage of device registration and deregistration functions of the USB module. It also usage the transfer functions of the USB module.
USB concept allows to select a configuration of a device by the programs on the host. A configuration is not only a single value but may change the behaviour of a device completely! It determines the interfaces which can used. The interfaces can be set to different choices which will determine the endpoints which can be used.
Table 1.1. Constants used for Device Numbering
Definition | Value | Description |
---|---|---|
USB_DEVICE_MAX | 127 | Maximal number which can be used for devices (USB 1.1) |
USB_DEVICE_AUTO_NUMBER | 0xFFFFFFFF | Device number is generated automatically. |
USB_DEVICE_DEFAULT_NUMBER | 0 | Device default number. This number is used by a device after it has been attached to a bus. |
Table 1.2. Constants used for device speed
Definition | Value | Description |
---|---|---|
USB_DEVICE_SPEED_SLOW | 0x00 | Device speed is 1.5Mbit/s. |
USB_DEVICE_SPEED_NORMAL | 0x01 | Device speed is 12Mbit/s. |
USB_DEVICE_SPEED_MAX | 0x01 | Maximal device speed (USB 1.1) |
Table 1.3. Constants used for device states
Definition | Value | Description |
---|---|---|
USB_DEVICE_STATE_UNPLUGGED | 0x00 | Device has been registered at USB module. |
USB_DEVICE_STATE_ATTACHED | 0x01 | Device is attached to the USB but not powered. |
USB_DEVICE_STATE_POWERED | 0x02 | Device is attached and powered but has not been reset. The USB Hub module will detect that a new device has been connected. Of course there may be the case that more than one device connected at the same time. In this case the Hub module is rensponsible to switch exactly one device to the bus per time by configuring the according hub. |
USB_DEVICE_STATE_DEFAULT | 0x03 | Device is attached and powered and has been reset. It is responding at the default address. To set this address you must send a SET_ADDRESS standard device request to the device at the default address on the default pipe. |
USB_DEVICE_STATE_ADDRESS | 0x04 | Device is attached and powered, has been reset and has got its own unique number. But device has not been configured. This can be done sending configuration on the default pipe. |
USB_DEVICE_STATE_CONFIGURED | 0x05 | Device is attached and powered, has been reset, has got its own unique number and has been configured. The host programms can now use the device. |
USB_DEVICE_STATE_SUSPENDED | 0x40 | This overlays actual device state. Device must be powered. The device enters this state if it hasn't seen an idle USB (that means also frame token are not sent!) for 3ms. |
USB Module is keeping internal data structures and will pass pointers to this structures as results of many functions. In a lot of cases a program must only keep this pointers for the next function call. But there are some situations where a program can use the structures itself. However a lot of programs may access the same data structures parallel or may call functions which affects data structures used by other programs. USB Module is managing access to this structures internally by using semaphores and the programs must not worry about that. There is an ugly case which will cause trouble to the programs. This is the dropping of structures. Most structures are allocated dynamically from memory. If now a program calls a function which drops a structure which is used by another program, this other program would crash because its structure pointer is invalid but it is not knowing about this. Therefore a special concept has been implemented which grants that a structure will be only dropped after all programs which have been using it, had agreed that it can be dropped.
Therefore it is registered how many programs or other data structures are helding pointers to this structure. A structure may be marked as going dropped and every program which tries to access this structure is informed about this fact, but the pointer to the structure is still valid until the last program removes its pointer to this structure.
Normally this deregistration is done automatically inside some functions. There is an according remark inside the description of the functions. But there are some situations where a program must do the deregistration itself.
It is important to deregister references to structures which are no longer used, because this memory will be blocked for other applications. In worst case if a program forgots the deregistration of a reference memory will be kept until reset of computer.
Note that reference handling is an ugly part inside programming. If dropping a reference to early or assuming that a reference is still valid but in fact it has been automatically or manually deregistered nay cause a program crashing. If you are keeping to much references on a structure it will block unused memory. Therefore check carefully wether you have registered a reference for every structure you are using inside your programs and how the functions of the USB-Module will handle the reference.
Table 1.4. Object reference types
Definition | Value | Description |
---|---|---|
USB_REFERENCE_ENDPOINT | 0 | Selects an endpoint at USB_ReferenceDeregister or USB_FindObject |
USB_REFERENCE_DEVICE | 1 | Selects a device at USB_ReferenceDeregister or USB_FindObject |
USB_REFERENCE_CONTROLLER | 2 | Selects a host controller at USB_ReferenceDeregister or USB_FindObject |