Class and Core Layers Interaction Through Callbacks
Upon reception of standard, class-specific and/or vendor requests, the Core layer can notify the Class layer about the event associated with the request via the use of class callbacks. Each Micrium class must define a class callbacks structure of type USBD_CLASS_DRV
that contains function pointers. Each callback allows the class to perform a specific action if it is required. Listing - Class Callback Structure shows a generic example of class callback structure. In the listing, XXXX
could be replaced with Audio
, CDC, HID, MSC, PHDC
or Vendor
.
static USBD_CLASS_DRV USBD_XXXX_Drv = { USBD_XXXX_Conn, (1) USBD_XXXX_Disconn, (2) USBD_XXXX_AltSettingUpdate, (3) USBD_XXXX_EP_StateUpdate, (4) USBD_XXXX_IF_Desc, (5) USBD_XXXX_IF_DescSizeGet, (6) USBD_XXXX_EP_Desc, (7) USBD_XXXX_EP_DescSizeGet, (8) USBD_XXXX_IF_Req, (9) USBD_XXXX_ClassReq, (10) USBD_XXXX_VendorReq, (11) #if (USBD_CFG_MS_OS_DESC_EN == DEF_ENABLED) USBD_XXXX_MS_GetCompatID, (12) USBD_XXXX_MS_GetExtPropertyTbl, (13) #endif };
(1) Notify the class that a configuration has been activated.
(2) Notify the class that a configuration has been deactivated.
(3) Notify the class that an alternate interface setting has been updated.
(4) Notify the class that an endpoint state has been updated by the host. The state is generally stalled or not stalled.
(5) Ask the class to build the interface class-specific descriptors.
(6) Ask the class for the total size of interface class-specific descriptors.
(7) Ask the class to build endpoint class-specific descriptors.
(8) Ask the class for the total size of endpoint class-specific descriptors.
(9) Ask the class to process a standard request whose recipient is an interface.
(10) Ask the class to process a class-specific request.
(11) Ask the class to process a vendor-specific request.
(12) Ask the class to provide the Microsoft Compatible ID and Subcompatible ID for this interface. This callback must not be defined when USBD_CFG_MS_OS_DESC_EN
is set to DEF_DISABLED
.
(13) Ask the class to provide a table of Microsoft Extended properties for this interface. This callback must not be defined when USBD_CFG_MS_OS_DESC_EN
is set to DEF_DISABLED
.
A class is not required to provide all the callbacks. If a class for instance does not define alternate interface settings and does not process any vendor requests, the corresponding function pointer will be a null-pointer. Listing - Class Callback Structure with Null Function Pointers presents the callback structure for that case.
static USBD_CLASS_DRV USBD_XXXX_Drv = { USBD_XXXX_Conn, USBD_XXXX_Disconn, 0, USBD_XXXX_EP_StateUpdate, USBD_XXXX_IF_Desc, USBD_XXXX_IF_DescSizeGet, USBD_XXXX_EP_Desc, USBD_XXXX_EP_DescSizeGet, USBD_XXXX_IF_Req, USBD_XXXX_ClassReq, 0, #if (USBD_CFG_MS_OS_DESC_EN == DEF_ENABLED) 0, 0, #endif };
If a class is composed of one interface then one class callback structure is required. If a class is composed of several interfaces then the class may define several class callback structures. In that case, a callback structure may be linked to one or several interfaces. For instance, the Communication Device Class (CDC) is composed of one Communication Interface and one or more Data Interfaces. The Communication interface will be linked to a callback structure. The Data interfaces may be linked to another callback structure common to all Data interfaces.
The class callbacks are called by the core task when receiving a request from the host sent over control endpoints (refer to the Task Model page for more details on the core task). Table - Class Callbacks and Requests Mapping indicates which callbacks are mandatory and optional and upon reception of which request the core task calls a specific callback.
Request type | Callback | Request | Mandatory? / Note |
---|---|---|---|
Standard | Conn() | SET_CONFIGURATION | Yes / Host selects a non-null configuration number. |
Standard | Disconn() | SET_CONFIGURATION | Yes / Host resets the current configuration or device physically detached from host. |
Standard | AltSettingUpdate() | SET_INTERFACE | No / Callback skipped if no alternate settings are defined for one or more interfaces. |
Standard | EP_StateUpdate() | SET_FEATURE CLEAR_FEATURE | No / Callback skipped if the state of the endpoint is not used. |
Standard | IF_Desc() | GET_DESCRIPTOR | No / Callback skipped if no class-specific descriptors for one or more interfaces. |
Standard | IF_DescSizeGet() | GET_DESCRIPTOR | No / Callback skipped if no class-specific descriptors for one or more interfaces. |
Standard | EP_Desc() | GET_DESCRIPTOR | No / Callback skipped if no class-specific descriptors for one or more endpoints. |
Standard | EP_DescSizeGet() | GET_DESCRIPTOR | No / Callback skipped if no class-specific descriptors for one or more endpoints. |
Standard | IF_Req() | GET_DESCRIPTOR | No / Callback skipped if no standard descriptors provided by a class. |
Class | ClassReq() | - | No / Callback skipped if no class-specific requests defined by the class specification. |
Vendor | VendorReq() | - | No / Callback skipped if no vendor requests. |
Microsoft | MS_GetCompatID() | GET_MS_DESCRIPTOR | No / Callback skipped if no Microsoft compatible ID required. |
Microsoft | MS_GetExtPropertyTbl() | GET_MS_DESCRIPTOR | No / Callback skipped if no Microsoft Extended properties required. |