The present invention relates to a method and in particular, but not exclusively to a method of controlling the behaviour of two devices connected to each other. The present invention also relates to a device, a computer program and a system.
USB (Universal Serial Bus) is a technology which provides a fast, cabled data connection between a complex device (e.g. a PC) which is called the Host and a connected peripheral (e.g. a mouse, keyboard, personal organizer or the like) which is called the Device. The standard is managed by the USB Implementer's forum.
Some implementations of USB contain functionality to operate as a USB Device and support functionality such as modern functionality, PIM Personal Information Management synchronization, mass storage and printing.
The USB standard has been extended to include connections between mobile devices such as mobile phones or mobile data devices in the USB OTG (On-The-Go) supplement. This supplement allows a peripheral at either end of the connection to take a Host or Device role. The initial roles are decided by the direction of the cable connection i.e. the type of plug A or B inserted into the peripheral.
The peripheral with the USB OTG A-plug inserted is called the A-Device. The A-Device supplies power for the duration of the connection and initially takes the Host role. The peripheral with the USB OTG B-plug inserted is called the B-Device. The B-Device draws power from the A-Device and initially takes a Device role.
Two protocols are defined by the USB OTG standard:
Firstly there is the Session Request Protocol (SRP). This enables an A-Device to turn off its power supply (called VBUS—Voltage line of the USB interface). This is because it provides a mechanism for the B-Device to signal that this power supply should be re-established in order to commence a new session.
Secondly, there is Host Negotiation Protocol or HNP. This allows a B-Device to request a role as Host. The protocol works by firstly, the A-Device enabling this capability in the B-Device. After this point, whenever the A-Device suspends the bus the B-Device may use HNP to request the host role. Suspending the bus means that there is no activity on the bus including the normal USB framing indicated by SOF (Start of Frame) packets. However, the standard allows for the A-Device to take back the host role at any point.
The following constraints underlie the state machine in
There are two timeouts which are active before the cable is connected. These can also be seen in
For completeness sake, a description of the arrangement of
State A is the case where VBUS is off and the cable is unattached.
State B is VBUS on and the cable unattached.
State D is where VBUS is on, the cable is attached and the Host is the A-Device.
State E is VBUS is off and the cable is attached.
State F is VBUS on, the cable is attached and the host is the B-Device.
State G is VBUS off, SRP polling on and the cable unattached.
To go from State A to State B (arrow ab), this occurs when there is A-Device User interaction.
To go from State B to State A (arrow ba), this occurs when there is a session time out.
To go from State B to State D (arrow bd), this occurs when the cable is attached.
To go from State D to State D (arrow dd), this occurs when there is B-Device interaction.
To go from State D to State E (arrow de), this occurs when the A-Device activity is completed.
To go from State E to State D (arrow ed), this occurs when there is A-Device activity.
To go from State A to State E (arrow ae), this occurs when the cable is attached.
To go from State F to State E (arrow fe), this occurs when the B-Device completes activity.
To go from State E to State F (arrow ef), this occurs when there is B-Device user interaction. The B-Device performs SRP followed by HNP.
To go from State F to State F (arrow ff), this occurs when there is A-Device user interaction. The A-Device realizes that B-device is currently host and makes not attempt to take control.
To go from State G to State F (arrow gf), this occurs when the cable is attached. The B-Device performs SRP followed by HNP.
To go from State G to State A (arrow ga), this occurs when there is a SRP Timeout.
To go from State A to State G (arrow ag), this occurs when there is B-Device user interaction.
One problem with the arrangement of
In the following scenarios the behaviour is asymmetric from an end user perspective:
The user expects that the last device interacted with before attaching the cable becomes the host.
The arrangement of
There is a new state, State C which is when VBUS is on, the SRP polling is on and the cable is unattached. The SRP polling is repeated performed by the B-Device in this state and in State G until SRP equals SRP timeout which is equal to the A-Device session time out.
The new transitions are:
To go from State B to State C (arrow bc), this occurs when there is B-Device user interaction.
To go from State C to State B (arrow cb), this occurs when there is SRP timeout. This SRP timeout will occur when the A-Device user interaction is followed by a B-Device user interaction since the SRP and session timeout periods are equal.
To go from State C to State D (arrow cd), this occurs when the cable is attached. The B-Device stops the SRP because VBUS is asserted. HNP does not succeed because the A-device believes it should be host.
To go from State G to State C (arrow gc), this occurs when there is A-Device user interaction.
To go from State C to State G (arrow cg), this occurs when there is session timeout. This session time out will occur when A-Device user interaction is followed by B-Device user interaction since the SRP and session timeout periods are equal.
It is an aim of at least some embodiments of the invention to address or at least mitigate one or more of the above described problems.
Various aspects of the invention can be seen from the appended claims.
For good usability of USB OTG, the end user is preferably unaware of the underlying technology. Preferably the host role should be taken by the device which the device is currently using. Preferably the user is also unaware of the direction of the cable. Embodiments of the present invention may achieve this.
For a better understanding of the present invention and as to how the same may be carried into effect, reference will now be made by way of example only to the accompanying drawings in which:
Embodiments of the invention may provide a mechanism where the behaviour of two connected OTG devices is symmetrical from the end user perspective in every case. This may address the problem above where two devices display asymmetric behaviour before they are connected.
The last used device now becomes the host. Alternatively, it would be possible; using the same mechanism, to make the first used device the host but the expression defined in
Embodiments of the invention uses an extensions of the standard USB protocols to share the values of the session timeout and SRP timeout counters so that these can be compared. The counter which has been running for the shortest time indicates the host. That which has been running the longest indicates the device. These two values allow the A-Device to decide on who should become host.
Each OTG peripheral has a timeout counter. This is referred to as the session timeout when the peripheral becomes the A-Device and SRP timeout when the peripheral becomes a B-Device. On user interaction this counters is set to a common specification value fixed for all OTG peripherals. The counter counts down in discrete steps each lasting a fixed period of time until it reaches zero. A host flag will also be set indicating that in the case of the peripheral becoming the B-Device it will attempt to become the host.
With no cable attached or a B-plug attached the device will generate SRP all of the time its counter is >0. If an A-plug is attached and the timeout is >0 then SRP will cease and VBUS will be asserted until the timeout=0.
The diagram shown in
State A is the case with VBUS off and the cable is unattached.
State B is VBUS on and the cable unattached.
State C is VBUS on, the SRP polling is on and the cable is unattached. The B-Device repeatedly performs SRP until SRP timeout which is equal to the A-Device session timeout
State D is where VBUS is on, the cable is attached and the Host is the A-Device.
State E is VBUS is off and the cable is attached.
State F is VBUS on, the cable is attached and the host is the B-Device.
State G is VBUS off, SRP polling on and the cable unattached.
To go from State A to State B (arrow ab), this occurs when there is A-Device User interaction.
To go from State B to State A (arrow ba), this occurs when there is a session time out.
To go from State B to State C (arrow bc), this occurs when there is B-Device user interaction.
To go from State C to State B (arrow cb), this occurs when there is SRP timeout. This SRP timeout will occur when the B-Device user interaction is followed by A-Device user interaction since the SRP and session timeout periods are equal.
To go from State C to State D (arrow cd), this occurs when the cable is attached and it is determined that the A-Device interaction was the latest. On connection, the devices compare time out values to determine which device has the latest user interaction.
To go from State B to State D (arrow bd), this occurs when the cable is attached.
To go from State D to State D (arrow dd), this occurs when there is B-Device interaction.
To go from State D to State E (arrow de), this occurs when the A-Device activity is completed.
To go from State E to State D (arrow ed), this occurs when there is A-Device activity.
To go from State A to State E (arrow ae), this occurs when the cable is attached.
To go from State F to State E (arrow fe), this occurs when the B-Device completes activity.
To go from State E to State F(arrow ef), this occurs when there is B-Device user interaction. The B-Device performs SRP followed by HNP
To go from State F to State F (arrow ff), this occurs when there is A-Device user interaction.
To go from State F to State C (arrow fc), this occurs when the cable is attached and it is discovered that the B-Device interaction was the latest. On connection, the devices compare timeout values to determine which device has the latest user interaction.
To go from State G to State F (arrow gf), this occurs when the cable is attached. The B-Device performs SRP followed by HNP.
To go from State G to State A (arrow ga), this occurs when there is a SRP Timeout.
To go from State A to State G (arrow ag), this occurs when there is B-Device user interaction.
To go from State G to State C (arrow gc), this occurs when there is A-Device user interaction.
To go from State C to State G (arrow cg), this occurs when there is session timeout. This session time out will occur when A-Device user interaction is followed by B-Device user interaction since the SRP and session timeout periods are equal.
This causes the session timeout counter to be started in step S2.
The cable is connected at both ends with the A-plug being inserted into this peripheral or device. This occurs in step S3.
The insertion of the A-plug into this particular device causes the session timeout counter to be stopped and for VBUS to be asserted in step S4.
The A-Device will then request the value of the host flag from the B-Device using a GetStatus request which is sent from the current device to the device that it will be connected to (the B-Device). This occurs in step S5.
In step S6, the B-Device returns, that is sends, the GetStatus response, ie the value of the Host Flag at the B-Device. This value is received at the A-Device.
In step S7, the A-Device checks the value of the B-Device host flag.
If the B-Device host flag is set to false the B-Device has no intention of becoming the host and therefore the A-Device will assume this role and the next step will be S15. In step S15, the A-Device takes host role.
In step S16, which follows step S15, the A-Device sends to the B-Device a clear_feature request. This is to request the B-Device to clear its host flag.
If, on the other hand, the host flag is true the A-Device will then request the value of the SRP timeout counter in step S8 by sending a GetStatus request which effectively requests the value of the SRP timer. This is sent to the B-Device.
In step S9, the A-Device receives a response from the B-Device which provides the value of the SRP timeout counter.
If it is determined in step S10 that the SRP timeout timer has reached zero, the next step will be step S15 where the A-Device becomes the host. This is as previously described. Step S16 will follow step S15.
If in step S10, it is determined that the SRP timer is not zero, the next step is step S11. In step S11, it is determined if the A-Device's session timeout timer has a larger value than the B-Device's SRP timeout timer. If this is determined to be the case, this means that the A-Device was used last and the next step will be step S11 followed by step S16. The A-Device can then take the host role and clear the B-Device's host flag so that the B-Device does not attempt to become the host later.
If there is a contention i.e. the session timeout timer and the SRP timeout timer have the same non-zero value then the A-Device will take precedence and become host and again the next steps will be steps S15 and S16.
If it is determined in step S11 that the SRP timeout timer is larger than the session timeout timer then the B-Device was used last. In this case, the next step is step S12 where the A-Device yields by suspending the bus.
In step S13, the B-Device carries out HNP in order to take the host role in step S14.
In step T1, the user interacts with this device.
This causes, in step T2, the SRP timeout counter to be started and for the host flag to be set. The host flag indicates that the B-Device has the intention to become host when it next gets the opportunity.
In step T3, the cable is connected at both ends with the B-plug being inserted into this peripheral.
This causes, in step T4, the SRP timeout counter to be stopped. It should also be noted that, since VBUS has been asserted by the A-Device, the B-Device will not attempt SRP even though its host flag is set.
The B-Device receives, in step T5, a GetStatus request from the A-Device for the host flag value of the B-Device.
The value of the B-Device host flag is provided in a response to the A-Device, in step T6.
The B-device then receives a GetStatus request from the A-Device for the SRP timeout timer value in step T7.
In step T8, the value of the SRP timeout timer is provided by the B-Device to the A-Device.
If the B-Device receives in step T9 a ClearFeature request from the A-Device to reset the host flag, the host flag in the B-Device is set to false in step T10.
The B-Device detects that the A-Device has suspended the USB bus i.e. VBUS is asserted but there is no data activity including SOF. This is done in step T11.
If it is determined in step T12 that the host flag is set to true, then the B-Device will initiate HNP in step T14 and in step T15 takes the host role.
If it is determined in step T12 that the host flag is reset, ie has the false value, it will not attempt HNP and therefore takes the device role in step T13.
In order to roll out this functionality the B-Device may need to indicate to the A-Device that it has support for this feature. This could be implemented via a USB descriptor, which is used to describe support in the USB device. Currently there is a descriptor to indicate HNP support. This could be extended to include support for this feature. The information can be provided via any other signalling method.
Reference is made to
The devices 100 and 102 are connected together via a cable 108. Each device has respective socket or the like 104 and 106 which allows respective connections to each end of the cable.
The structure of only the first device 100 is shown. It should be appreciated that the second device 102 may have a similar structure.
The first device comprises a counter 116. This counter can be implemented in any suitable form. It can be a count down timer, a count up timer, a clock or any other suitable circuitry which is able to provide information indicative about how long ago a user interacted with that device. The counter can be implemented in hardware, software or a combination thereof.
The second device also has memory 114 for storing the status of the flag. The memory can take any suitable form such as a latch, a register, a specific address in a memory or the like.
A processor 112 is provided. This is arranged to provide control. It receives the output of the counter 116, the flag memory and is arranged to be connected to the socket 110. The processor is arranged to be able to start the counter 116 when the controller determines that there is interaction between the user and the device. The controller will therefore output a control signal to the counter. The user interaction can comprise the actuation of a key or button, the switching on of the device, movement of the device or any other such indication. In some embodiments of the invention, the interaction can comprise the plugging of the USB cable into the socket.
The controller is able to read the value of the host flag when required and also to write a new value to the host flag memory 114.
The controller 112 is able to formulate messages or requests for information to be sent to the other device 102 via the cable 108. The controller is also able to formulate responses in response to requests received from the other device 102.
The controller 112 is thus able to control the device to provide the method set out in
It should be appreciated that the controller may be implemented in hardware, software or a combination thereof.
It should be appreciated that at least some of the steps shown in
Embodiments of the invention may provide symmetry in all cases.
Devices to which embodiments of the invention can be applied can take any suitable form. The list below provides some examples of possible devices. It should be appreciated that the two devices which are connected together may be the same or different:
Mobile telephone; camera; MP3 player; picture frame; personal digital assistant (PDA); portable computer; music player; communication device; and printer.
In the example described, the connection is between two devices. It is possible that embodiments of the invention can be used with three or more connected devices.
Embodiments of the invention have been described in the context of a USB environment. It should be appreciated that embodiments of the invention may be used in non USB environments where a decision needs to be made as to which device is to be a master device or the device in control. It should be appreciated that alternative embodiments of the invention may have a wireless connection between the devices instead of a cable connection.
Number | Date | Country | Kind |
---|---|---|---|
0614258.2 | Jul 2006 | GB | national |