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 when GET_REPORT is received. The locking system ensures the data integrity between the Input report data storage operation done within an application task context and the GET_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 nameOperation
USBD_HID_OS_InitCreates and initializes the task and semaphores.
USBD_HID_OS_InputLockLocks Input report.
USBD_HID_OS_InputUnlockUnlocks Input report.
USBD_HID_OS_InputDataPendWaits for Input report data write completion.
USBD_HID_OS_InputDataPendAbortAborts the wait for Input report data write completion.
USBD_HID_OS_InputDataPostSignals that Input report data has been sent to the host.
USBD_HID_OS_OutputLockLocks Output report.
USBD_HID_OS_OutputUnlockUnlocks Output report.
USBD_HID_OS_OutputDataPendWaits for Output report data read completion.
USBD_HID_OS_OutputDataPendAbortAborts the wait for Output report data read completion.
USBD_HID_OS_OutputDataPostSignals that Output report data has been received from the host.
USBD_HID_OS_TxLockLocks class transmit.
USBD_HID_OS_TxUnlockUnlocks class transmit.
USBD_HID_OS_TmrTaskTask processing periodic input reports. Refer to the Periodic Input Reports Task page for more details about this task.