2.2.2.1 Abstraction Model
The Device Layer in the MPLAB Harmony USB Device Stack handles enumeration requests from the USB Host and provides an abstracted access to Control Transfers and Non-Control Endpoint Management. The Device Layer intercepts all Control transfers issues by the host. Only those control transfers that require application or function driver intervention are forwarded. Standard device control transfers are completely handled by the Device Layer. All access to the bus is routed via the Device Layer.
The following block diagram shows the USB Device Layer interaction with USB Controller Driver, Function Drivers, User Application and the Harmony System module.
Harmony System Module Interaction
The MPLAB Harmony System Module initializes the Device Layer in the SYS_Initialize() function. It calls the USB Device Layer task routine periodically from the SYS_Tasks() function.
USB Controller Driver Interaction
The Device Layer opens the USB Controller Driver exclusively. It is the only client to the controller driver. The Device Layer manages Endpoint 0 and has exclusive access to this endpoint. It maintains the Control Transfer state machine and seeks intervention from the Application or the Function Drivers where required. The Device Layer provides layered access to the required USB Controller Driver functions.
Function Driver Interaction
The USB Device Layer interaction with the function driver involves the following:
- It initializes the function driver when device is configured by the Host. This happens when the Host issues the standard USB Set Configuration Request to the device. The device_layer initializes only those function drivers that are part of the selected configuration.
- Deinitializes the function driver when the Host issues a bus reset or when device is detached from the host or when the Host issues a Set Configuration request with configuration value set to '0'.
- The Device Layer executes the Function driver task routines from within its own tasks routine (USB_DEVICE_Tasks() function). In an RTOS application, this implies that the function driver task routines run at the same priority and context as the device_layer task routine.
- Forwards class/interface specific control transfer requests from host to function drivers for processing. The function drivers can use Device layer_API routines to read and write data to Endpoint 0.
The Device Layer initiates all of the above interactions with the function driver independent of function driver type. Each function driver implements a set of common APIs. These common API allow the Device Layer to initialize/deinitialize the function driver, forward control transfers and invoke the function driver's task routine. Function Drivers are registered with the Device Layer as a part of the Device Stack Configuration. This is a compile time step. Function driver registration is explained elsewhere in this help section.
User Application (Client) Interaction
The user application opens the Device Layer and becomes a Device Layer client. It registers an event callback function with the Device_layer to get Device Layer event notifications. Other than receiving such notifications, the application client can also interact with the Device Layer_to determine device status such as USB speed or initiate a remote wake-up. The Device Layer will forward Control Transfers, whose recipient field is set to Other, to the application. The application must use the Device Layer Control Transfer Routines to complete these control transfers.