Porting the Audio Class to an RTOS

The audio class uses its own RTOS abstraction layer providing specific services needed by the two internal tasks, playback and record. Both tasks requires a queue to process certain types of messages. The playback task will receive events each time an audio transfer has completed. The record task will receive AudioStreaming requests to retrieve ready buffers from the Audio Peripheral driver and submit them to the USB device driver. A delay used by the playback and the record tasks in certain error conditions is also available from the audio RTOS layer. Two different lock mechanisms are also utilized to protect each AudioStreaming's structure and ring buffer queue. 

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 - OS Layer API Summary. For a complete API description, see the Audio API Reference.


Table - OS Layer API Summary
Function nameOperation
USBD_Audio_OS_Init()Initializes all internal members / tasks.
USBD_Audio_OS_AS_IF_LockCreate()Creates an OS resource to use as an AudioStreaming interface lock.
USBD_Audio_OS_AS_IF_LockAcquire()Waits for an AudioStreaming interface to become available and acquire its lock.
USBD_Audio_OS_AS_IF_LockRelease()Releases an AudioStreaming interface lock.
USBD_Audio_OS_RingBufQLockCreate()Creates an OS resource to use as a stream ring buffer queue lock.
USBD_Audio_OS_RingBufQLockAcquire()Waits for a stream ring buffer queue to become available and acquire its lock.
USBD_Audio_OS_RingBufQLockRelease()Releases a stream ring buffer queue lock.
USBD_Audio_OS_RecordReqPostPosts a request into the record task's queue.
USBD_Audio_OS_RecordReqPendPends on a request from the record task's queue.
USBD_Audio_OS_PlaybackReqPostPosts a request into the playback task's queue.
USBD_Audio_OS_PlaybackReqPendPends on a request from the playback task's queue.
USBD_Audio_OS_DlyMs()Delays calling task for a certain duration expressed in milliseconds.
USBD_Audio_OS_RecordTask()Task processing record streams. Refer to Audio Class Stream Data Flow for more details about this task.
USBD_Audio_OS_PlaybackTask()Task processing playback streams. Refer to Audio Class Stream Data Flow for more details about this task.

OS Tick Rate

Whenever possible, USBD_Audio_OS_DlyMs should provide a delay with a 1 ms granularity. That is the OS tick rate should be set to produce at least 1 tick per millisecond.. It will improve the audio class tasks scheduling as audio class works on a 1 ms frame basis. Moreover, a retry mechanism is implemented in the playback and record tasks in case a transfer cannot be queued on a given endpoint. The playback or record task waits 1 ms between each attempt before re-transmitting the transfer.