Added new USB_DeviceState variable to keep track of the current Device mode USB state.
Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers. Removed vague USB_IsConnected global - test USB_DeviceState or USB_HostState explicitly to gain previous functionality. Removed USB_IsSuspended global - test USB_DeviceState against DEVICE_STATE_Suspended instead. Fixed possible enumeration errors from spinloops which may fail to exit if the USB connection is severed before the exit condition becomes true.
This commit is contained in:
parent
44179abcf8
commit
e071f3897a
58 changed files with 666 additions and 463 deletions
|
@ -98,7 +98,7 @@
|
|||
* which is not always accurate (host may suspend the bus while still connected). If the actual connection state
|
||||
* needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
|
||||
* passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
|
||||
* and disconnection events may be manually fired, and the \ref USB_IsConnected global changed manually.
|
||||
* and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
|
||||
*
|
||||
* \see USBTask.h for more information on the USB management task and reducing CPU usage.
|
||||
*/
|
||||
|
@ -116,7 +116,7 @@
|
|||
* which is not always accurate (host may suspend the bus while still connected). If the actual connection state
|
||||
* needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
|
||||
* passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
|
||||
* and disconnection events may be manually fired, and the \ref USB_IsConnected global changed manually.
|
||||
* and disconnection events may be manually fired, and the \ref USB_DeviceState global changed manually.
|
||||
*
|
||||
* \see USBTask.h for more information on the USB management task and reducing CPU usage.
|
||||
*/
|
||||
|
|
|
@ -78,19 +78,17 @@ ISR(USB_GEN_vect, ISR_BLOCK)
|
|||
{
|
||||
EVENT_USB_VBUSConnect();
|
||||
|
||||
if (USB_IsConnected)
|
||||
if (USB_DeviceState != DEVICE_STATE_Unattached)
|
||||
EVENT_USB_Disconnect();
|
||||
|
||||
USB_ResetInterface();
|
||||
|
||||
USB_IsConnected = true;
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Powered;
|
||||
EVENT_USB_Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_IsConnected = false;
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
EVENT_USB_Disconnect();
|
||||
|
||||
USB_Detach();
|
||||
|
@ -117,16 +115,12 @@ ISR(USB_GEN_vect, ISR_BLOCK)
|
|||
if (!(USB_Options & USB_OPT_MANUAL_PLL))
|
||||
USB_PLL_Off();
|
||||
|
||||
USB_IsSuspended = true;
|
||||
|
||||
EVENT_USB_Suspend();
|
||||
|
||||
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
|
||||
if (USB_IsConnected)
|
||||
{
|
||||
USB_IsConnected = false;
|
||||
EVENT_USB_Disconnect();
|
||||
}
|
||||
USB_DeviceState = DEVICE_STATE_Unattached;
|
||||
EVENT_USB_Disconnect();
|
||||
#else
|
||||
USB_DeviceState = DEVICE_STATE_Suspended;
|
||||
EVENT_USB_Suspend();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -146,22 +140,19 @@ ISR(USB_GEN_vect, ISR_BLOCK)
|
|||
USB_INT_Enable(USB_INT_SUSPEND);
|
||||
|
||||
#if defined(USB_SERIES_2_AVR) && !defined(NO_LIMITED_CONTROLLER_CONNECT)
|
||||
if (!(USB_IsConnected))
|
||||
{
|
||||
USB_IsConnected = true;
|
||||
EVENT_USB_Connect();
|
||||
}
|
||||
USB_DeviceState = DEVICE_STATE_Powered;
|
||||
EVENT_USB_Connect();
|
||||
#else
|
||||
USB_DeviceState = DEVICE_STATE_Configured;
|
||||
EVENT_USB_WakeUp();
|
||||
#endif
|
||||
|
||||
USB_IsSuspended = false;
|
||||
|
||||
EVENT_USB_WakeUp();
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_EORSTI) && USB_INT_IsEnabled(USB_INT_EORSTI))
|
||||
{
|
||||
USB_INT_Clear(USB_INT_EORSTI);
|
||||
|
||||
USB_DeviceState = DEVICE_STATE_Default;
|
||||
USB_ConfigurationNumber = 0;
|
||||
|
||||
USB_INT_Clear(USB_INT_SUSPEND);
|
||||
|
@ -217,7 +208,7 @@ ISR(USB_GEN_vect, ISR_BLOCK)
|
|||
|
||||
USB_INT_Enable(USB_INT_DDISCI);
|
||||
|
||||
USB_HostState = HOST_STATE_Attached;
|
||||
USB_HostState = HOST_STATE_Powered;
|
||||
}
|
||||
|
||||
if (USB_INT_HasOccurred(USB_INT_BCERRI) && USB_INT_IsEnabled(USB_INT_BCERRI))
|
||||
|
@ -227,7 +218,7 @@ ISR(USB_GEN_vect, ISR_BLOCK)
|
|||
EVENT_USB_DeviceEnumerationFailed(HOST_ENUMERROR_NoDeviceDetected, 0);
|
||||
EVENT_USB_DeviceUnattached();
|
||||
|
||||
if (USB_IsConnected)
|
||||
if (USB_HostState != HOST_STATE_Unattached)
|
||||
EVENT_USB_Disconnect();
|
||||
|
||||
USB_ResetInterface();
|
||||
|
@ -239,13 +230,16 @@ ISR(USB_GEN_vect, ISR_BLOCK)
|
|||
{
|
||||
USB_INT_Clear(USB_INT_IDTI);
|
||||
|
||||
if (USB_IsConnected)
|
||||
{
|
||||
if (USB_CurrentMode == USB_MODE_HOST)
|
||||
EVENT_USB_DeviceUnattached();
|
||||
if (USB_DeviceState != DEVICE_STATE_Unattached)
|
||||
EVENT_USB_Disconnect();
|
||||
|
||||
if (USB_HostState != HOST_STATE_Unattached)
|
||||
{
|
||||
EVENT_USB_Disconnect();
|
||||
EVENT_USB_DeviceUnattached();
|
||||
}
|
||||
|
||||
EVENT_USB_Disconnect();
|
||||
|
||||
EVENT_USB_UIDChange();
|
||||
|
||||
|
|
|
@ -33,8 +33,6 @@
|
|||
#define INCLUDE_FROM_USBTASK_C
|
||||
#include "USBTask.h"
|
||||
|
||||
volatile bool USB_IsSuspended;
|
||||
volatile bool USB_IsConnected;
|
||||
volatile bool USB_IsInitialized;
|
||||
USB_Request_Header_t USB_ControlRequest;
|
||||
|
||||
|
@ -42,6 +40,10 @@ USB_Request_Header_t USB_ControlRequest;
|
|||
volatile uint8_t USB_HostState;
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
volatile uint8_t USB_DeviceState;
|
||||
#endif
|
||||
|
||||
void USB_USBTask(void)
|
||||
{
|
||||
#if defined(USB_HOST_ONLY)
|
||||
|
@ -59,7 +61,7 @@ void USB_USBTask(void)
|
|||
#if defined(USB_CAN_BE_DEVICE)
|
||||
static void USB_DeviceTask(void)
|
||||
{
|
||||
if (USB_IsConnected)
|
||||
if (USB_DeviceState != DEVICE_STATE_Unattached)
|
||||
{
|
||||
uint8_t PrevEndpoint = Endpoint_GetCurrentEndpoint();
|
||||
|
||||
|
|
|
@ -55,23 +55,6 @@
|
|||
|
||||
/* Public Interface - May be used in end-application: */
|
||||
/* Global Variables: */
|
||||
/** Indicates if the USB interface is currently connected to a host if in device mode, or to a
|
||||
* device while running in host mode.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
*
|
||||
* \note For the smaller USB AVRs (AT90USBXX2) with limited USB controllers, VBUS is not available to the USB controller.
|
||||
* this means that the current connection state is derived from the bus suspension and wake up events by default,
|
||||
* which is not always accurate (host may suspend the bus while still connected). If the actual connection state
|
||||
* needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by
|
||||
* passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection
|
||||
* and disconnection events may be manually fired, and the \ref USB_IsConnected global changed manually.
|
||||
*
|
||||
* \ingroup Group_USBManagement
|
||||
*/
|
||||
extern volatile bool USB_IsConnected;
|
||||
|
||||
/** Indicates if the USB interface is currently initialized but not necessarily connected to a host
|
||||
* or device (i.e. if \ref USB_Init() has been run). If this is false, all other library globals are invalid.
|
||||
*
|
||||
|
@ -90,39 +73,43 @@
|
|||
*/
|
||||
extern USB_Request_Header_t USB_ControlRequest;
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
|
||||
/** Indicates if the USB interface is currently suspended by the host when in device mode. When suspended,
|
||||
* the device should consume minimal power, and cannot communicate to the host. If Remote Wakeup is
|
||||
* supported by the device and \ref USB_RemoteWakeupEnabled is true, suspension can be terminated by the device
|
||||
* by issuing a Remote Wakeup request.
|
||||
*
|
||||
* \note This global is only present if the user application can be a USB device.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value.
|
||||
*
|
||||
* \ingroup Group_Device
|
||||
*/
|
||||
extern volatile bool USB_IsSuspended;
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST) || defined(__DOXYGEN__)
|
||||
/** Indicates the current host state machine state. When in host mode, this indicates the state
|
||||
* via one of the values of the \ref USB_Host_States_t enum values in Host.h.
|
||||
* via one of the values of the \ref USB_Host_States_t enum values.
|
||||
*
|
||||
* This value may be altered by the user application to implement the \ref HOST_STATE_Addressed,
|
||||
* \ref HOST_STATE_Configured, \ref HOST_STATE_Ready and \ref HOST_STATE_Suspended states which
|
||||
* are not implemented by the library.
|
||||
* \ref HOST_STATE_Configured and \ref HOST_STATE_Suspended states which are not implemented by
|
||||
* the library.
|
||||
*
|
||||
* \note This global is only present if the user application can be a USB host.
|
||||
*
|
||||
* \see \ref USB_Host_States_t for a list of possible host states
|
||||
* \see \ref USB_Host_States_t for a list of possible device states
|
||||
*
|
||||
* \ingroup Group_Host
|
||||
*/
|
||||
extern volatile uint8_t USB_HostState;
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)
|
||||
/** Indicates the current device state machine state. When in device mode, this indicates the state
|
||||
* via one of the values of the \ref USB_Device_States_t enum values.
|
||||
*
|
||||
* This value should not be altered by the user application as it is handled automatically by the
|
||||
* library. The only exception to this rule is if the NO_LIMITED_CONTROLLER_CONNECT token is used
|
||||
* (see \ref EVENT_USB_Connect() and \ref EVENT_USB_Disconnect() events).
|
||||
*
|
||||
* \note This global is only present if the user application can be a USB device.
|
||||
*
|
||||
* \note This variable should be treated as read-only in the user application, and never manually
|
||||
* changed in value except in the circumstances outlined above.
|
||||
*
|
||||
* \see \ref USB_Device_States_t for a list of possible device states
|
||||
*
|
||||
* \ingroup Group_Device
|
||||
*/
|
||||
extern volatile uint8_t USB_DeviceState;
|
||||
#endif
|
||||
|
||||
/* Function Prototypes: */
|
||||
/** This is the main USB management task. The USB driver requires that this task be executed
|
||||
* continuously when the USB system is active (device attached in host mode, or attached to a host
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue