Porting the Core Layer to an RTOS

The core RTOS port is located in a separate file named usbd_os.c. A template file can be found in the following folder:

\Micrium\Software\uC-USB-Device-V4\OS\Template

Table - Core OS port API summary summarizes all the functions that need to be implemented in the RTOS port file. For more information on how these functions should be implemented, refer to the Core Layer RTOS Model page and to the Core OS Functions reference.

Table - Core OS port API summary
Function nameOperation
USBD_OS_Init() Initializes all internal members / tasks.
USBD_OS_EP_SignalCreate() Creates OS signal used to synchronize synchronous transfers.
USBD_OS_EP_SignalDel() Deletes OS signal used to synchronize synchronous transfers.
USBD_OS_EP_SignalPend() Pends on OS signal used to synchronize synchronous transfers.
USBD_OS_EP_SignalAbort() Aborts OS signal used to synchronize synchronous transfers.
USBD_OS_EP_SignalPost() Posts OS signal used to synchronize synchronous transfers.
USBD_OS_EP_LockCreate() Creates OS lock used to lock endpoint.
USBD_OS_EP_LockDel() Deletes OS lock used to lock endpoint.
USBD_OS_EP_LockAcquire() Acquires OS lock used to lock endpoint.
USBD_OS_EP_LockRelease() Releases OS lock used to lock endpoint.
USBD_OS_DbgEventRdy() Posts signal used to resume debug task.
USBD_OS_DbgEventWait() Pends on signal used to resume debug task.
USBD_OS_CoreEventGet() Retrieves the next core event to process.
USBD_OS_CoreEventPut() Adds a core event to be processed by the core.
USBD_OS_DlyMs() Delays a task for a number of milliseconds.


Note that you must declare at least one task for the core events management within your RTOS port. This task should simply call the core function USBD_CoreTaskHandler in an infinite loop. Furthermore, if you plan using the debugging feature, you must also create a task for this purpose. This task should simply call the core function USBD_DbgTaskHandler in an infinite loop. Listing - Core task and debug task typical implementation shows how these two task functions body should be implemented.

Listing - Core task and debug task typical implementation
static  void  USBD_OS_CoreTask (void  *p_arg)
{
    (void)&p_arg;
 
    while (DEF_ON) {
        USBD_CoreTaskHandler();
    }
}
 
static  void  USBD_OS_TraceTask (void  *p_arg)
{
    (void)&p_arg;
 
    while (DEF_ON) {
        USBD_DbgTaskHandler();
    }
}