Porting the HID Class to an RTOS
The HID class uses its own RTOS layer for different purposes:
- A locking system is used to protect a given Input report. A host can get an Input report by sending a
GET_REPORT
request to the device using the control endpoint or with an interrupt IN transfer.GET_REPORT
request processing is done by the device stack while the interrupt IN transfer is done by the application. When the application executes the interrupt IN transfer, the Input report data is stored internally. This report data stored will be sent via a control transfer whenGET_REPORT
is received. The locking system ensures the data integrity between the Input report data storage operation done within an application task context and theGET_REPORT
request processing done within the device stack’s internal task context. - A locking system is used to protect the Output report processing between an application task and the device stack’s internal task when the control endpoint is used. The application provides to the HID class a receive buffer for the Output report in the application task context. This receive buffer will be used by the device stack’s internal task upon reception of a
SET_REPORT
request. The locking system ensures the receive buffer and related variables integrity. - A locking system is used to protect the interrupt IN endpoint access from multiple application tasks.
- A synchronization mechanism is used to implement the blocking behavior of
USBD_HID_Rd()
when the control endpoint is used. - A synchronization mechanism is used to implement the blocking behavior of
USBD_HID_Wr()
because the HID class internally uses the asynchronous interrupt API for HID write. - A task is used to process periodic Input reports. Refer to the Periodic Input Reports Task page for more details about this task.
By default, Micrium will provide an RTOS layer for both μC/OS-II and μC/OS-III. However, it is possible to create your own RTOS layer. Your layer will need to implement the functions listed in Table - HID OS Layer API Summary. For a complete API description, refer to the HID API Reference.
Table - HID OS Layer API Summary
Function name | Operation |
---|---|
USBD_HID_OS_Init | Creates and initializes the task and semaphores. |
USBD_HID_OS_InputLock | Locks Input report. |
USBD_HID_OS_InputUnlock | Unlocks Input report. |
USBD_HID_OS_InputDataPend | Waits for Input report data write completion. |
USBD_HID_OS_InputDataPendAbort | Aborts the wait for Input report data write completion. |
USBD_HID_OS_InputDataPost | Signals that Input report data has been sent to the host. |
USBD_HID_OS_OutputLock | Locks Output report. |
USBD_HID_OS_OutputUnlock | Unlocks Output report. |
USBD_HID_OS_OutputDataPend | Waits for Output report data read completion. |
USBD_HID_OS_OutputDataPendAbort | Aborts the wait for Output report data read completion. |
USBD_HID_OS_OutputDataPost | Signals that Output report data has been received from the host. |
USBD_HID_OS_TxLock | Locks class transmit. |
USBD_HID_OS_TxUnlock | Unlocks class transmit. |
USBD_HID_OS_TmrTask | Task processing periodic input reports. Refer to the Periodic Input Reports Task page for more details about this task. |