SW Usb Audio - SW Usb Audio - (Design-Guide) 6.16.1alpha1
SW Usb Audio - SW Usb Audio - (Design-Guide) 6.16.1alpha1
SYNOPSIS
The XMOS USB Audio solution provides USB Audio Class compliant devices over USB 2.0 (high-
speed or full-speed). Based on the XMOS XS1 architecture, it supports USB Audio Class 2.0 and
USB Audio Class 1.0, asynchronous mode and sample rates up to 384kHz.
The complete source code, together with the free XMOS xTIMEcomposer development tools
and XCORE multi-core micro-controller devices allow the implementer to select the exact mix of
interfaces and processing required.
The XMOS USB Audio solution is deployed as a framework with reference design applications
extending and customising this framework. These reference designs have particular qualified
feature sets and an accompanying reference hardware platform.
This software design guide assumes the reader is familiar with the XC language and xCORE devices.
For more information see XMOS Programming Guide1 .
The reader should also familiarise themselves with the XMOS USB Device Library2 and the XMOS
USB Device Design Guide3
The reader should always refer to the supplied CHANGELOG and README files for known issues
etc in a specific release
1 https://www.xmos.com/published/xmos-programming-guide
2 http://www.xmos.com/published/xuddg
3 https://www.xmos.com/zh/node/17007?page=9
XM0088546.1
USB Audio Design Guide 3/110
Table of Contents
1 Overview 5
2 Hardware Platforms 6
2.1 xCORE-200 Multi-Channel Audio Board . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1.1 Analogue Input & Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.2 Digital Input & Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.3 MIDI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.4 Audio Clocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.5 LEDs, Buttons and Other IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 xCORE-200 Microphone Array Board . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Microphones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.2 Analogue Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.3 Audio Clocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2.4 Buttons, LEDs and Other IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3 USB Multi-function Audio (MFA) Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4 U16 Multi-Channel USB Audio Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.5 USB Audio 2.0 DJ Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.6 USB Audio 2.0 Reference Design Board . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.7 USB Audio 2.0 Multichannel Reference Design Board . . . . . . . . . . . . . . . . . 15
3 Software Architecture 17
3.1 The USB Audio System Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2 XMOS USB Device (XUD) Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.3 Endpoint 0: Management and Control . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.3.1 Enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.3.2 Over-riding Standard Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3.3 Class Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.4 Audio Endpoints (Endpoint Buffer and Decoupler) . . . . . . . . . . . . . . . . . . . 22
3.4.1 Endpoint Buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4.2 Decoupler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.3 Audio Buffering Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.4 Decoupler/Audio Core interaction . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.5 Audio Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5.1 Port Configuration (xCORE Master) . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5.2 Changing Audio Sample Frequency . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.6 Digital Mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.6.1 Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.6.2 Host Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.7 S/PDIF Transmit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.7.1 Clocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.7.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.7.3 Output stream structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.8 S/PDIF Receive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.8.1 Usage and Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.9 ADAT Receive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.9.1 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.10 External Clock Recovery (ClockGen) . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.11 MIDI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.12 PDM Microphones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
XM0088546.1
USB Audio Design Guide 4/110
5 Programming Guide 48
5.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.1.1 Building and Running . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.1.2 Installing the application onto flash . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2 Project Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.2.1 Applications and Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.3 Build Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.4 Validated Build Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.5 Configuration Naming Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.6 A USB Audio Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.6.1 Custom Defines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.6.2 Configuration Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.6.3 The main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
5.7 Adding Custom Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.7.1 Example: Changing output format . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.7.2 Example: Adding DSP to output stream . . . . . . . . . . . . . . . . . . . . . . 59
XM0088546.1
USB Audio Design Guide 5/110
7 API 86
7.1 Configuration Defines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.1.1 Code location (tile) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.1.2 Channel Counts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.1.3 Frequencies and Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.1.4 Audio Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
7.1.5 System Feature Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.1.6 USB Device Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7.1.7 Stream Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.1.8 Volume Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
7.1.9 Mixing Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1.10 Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7.2 Required User Function Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7.2.1 External Audio Hardware Configuration Functions . . . . . . . . . . . . . . . . 98
7.2.2 Audio Streaming Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.2.3 Host Active . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.2.4 HID Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
7.3 Component API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
XM0088546.1
1 Overview
XM0088546.1
USB Audio Design Guide 7/110
Functionality
Provides USB interface to audio I/O.
Supported Standards
USB USB 2.0 (Full-speed and High-speed)
USB Audio Class 1.04
USB Audio Class 2.05
USB Firmware Upgrade (DFU) 1.16
USB Midi Device Class 1.07
Audio I2S/TDM
S/PDIF
ADAT
Direct Stream Digital (DSD)
PDM Microphones
MIDI
Supported Sample Frequencies
44.1kHz, 48kHz, 88.2kHz, 96kHz, 176.4kHz, 192kHz, 352.8kHz, 384kHz
Supported Devices
XMOS Devices xCORE-200 Series
XS1 L-Series
XS1 U-Series
XS1 G-Series (Not recommended for
new designs)
Requirements
Development Tools xTIMEcomposer Development Tools
v14 or later
USB External ULPI USB Phy (If using XS1
G/L-Series)
Audio External audio DAC/ADC/CODECs
(and required supporting
componentry) supporting I2S/TDM
Boot/Storage Compatible SPI Flash device
Licensing and Support
Reference code provided without charge under license from XMOS.
Please visit http://www.xmos.com/support/contact for support.
Reference code is maintained by XMOS Limited.
4 http://www.usb.org/developers/devclass_docs/audio10.pdf
5 http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
6 http://www.usb.org/developers/devclass_docs/DFU_1.1.pdf
7 http://www.usb.org/developers/devclass_docs/midi10.pdf
XM0088546.1
2 Hardware Platforms
IN THIS CHAPTER
· xCORE-200 Multi-Channel Audio Board
· xCORE-200 Microphone Array Board
· USB Multi-function Audio (MFA) Kit
· U16 Multi-Channel USB Audio Kit
· USB Audio 2.0 DJ Kit
· USB Audio 2.0 Reference Design Board
· USB Audio 2.0 Multichannel Reference Design Board
The following sections describe the hardware platforms that support development
with the XMOS USB Audio software framework.
For full details regarding the hardware please refer to xCORE-200 Multichannel
Audio Platform Hardware Manual9 .
The reference board has an associated firmware application that uses the USB
Audio 2.0 software reference platform. Details of this application can be found in
section §6.6.
8 https://www.xmos.com/support/boards?product=18334
9 https://www.xmos.com/support/boards?product=18334&component=18687
XM0088546.1
USB Audio Design Guide 9/110
A total of eight single-ended analog input channels are provided via 3.5mm stereo
jacks. Each is fed into a CirrusLogic CS5368 ADC. Similarly a total of eight single-
ended analog output channels are provided. Each is fed into a CirrusLogic CS4384
DAC.
The four digital I2S/TDM input and output channels are mapped to the xCORE
input/outputs through a header array. The jumper allows channel selection when
the ADC/DAC is used in TDM mode
Optical and coaxial digital audio transmitters are used to provide digital audio
input output in formats such as IEC60958 consumer mode (S/PDIF) and ADAT. The
output data streams from the xCORE-200 are re-clocked using the external master
clock to synchronise the data into the audio clock domain. This is achieved using
simple external D-type flip-flops.
2.1.3 MIDI
MIDI I/O is provided on the board via a standard Gameport connector. The signals
are buffered using 5V line drivers and are then connected to 1-bit ports on the
xCORE-200, via a 5V to 3.3V buffer.
A flexible clocking scheme is provided for both audio and other system services.
In order to accommodate a multitude of clocking options, the low-jitter master
clock is generated locally using a frequency multiplier PLL chip. The chip used is a
Phaselink PL611-01, which is pre-programmed to provide a 24MHz clock from its
CLK0 output, and either 24.576 MHz or 22.5792MHz from its CLK1 output.
The 24MHz fixed output is provided to the xCORE-200 device, as the main pro-
cessor clock. It also provides the reference clock to a Cirrus Logic CS2100, which
provides a very low jitter audio clock from a synchronisation signal provided from
the xCORE-200.
Either the locally generated clock (from the PL611) or the recovered low jitter clock
(from the CS2100) may be selected to clock the audio stages; the xCORE-200, the
ADC/DAC and Digital output stages.
An array of 4*4 green LEDs, 3 buttons and a switch are provided for general
purpose user interfacing. The LED array is driven by eight signals each controlling
one of 4 rows and 4 columns.
A standard XMOS xSYS interface is provided to allow host debug of the board via
JTAG.
XM0088546.1
USB Audio Design Guide 10/110
Figure 1 shows the block layout of the xCORE-200 Microhone Array board.
JTAG BUFFER
MIC0
MIC1
MII MIC-DATA[6:0]
Ethernet MIC2
MDI
PHY MIC3
LAN8710A SMI
RJ45 MIC-CLK
D-FF
Buffer MIC CLK[6:0] MIC4
MIC5
xCORE MIC6
25MHz
XUF216 I2S
MEMS mic
AKU441
DAC HP
CS43L21 3.5mm Jack
USB USB diff pair I2C
Type-B
Figure 1:
xCORE-200
Microphone
24MHz
Array Board
DAC-MCLK
Block 3v3 1v 2v5
PLL CLK
24.576
MCLK BUFFER Device MHz
Diagram TILE CLK to xCore
CS2100
For full details regarding the hardware please refer to xCORE Microphone Array
Hardware Manual11 .
The reference board has an associated firmware application that uses the USB
Audio 2.0 software reference platform. Details of this application can be found in
section §6.7.
10 https://www.xmos.com/support/boards?product=20258
11 https://www.xmos.com/download/private/xCORE-Microphone-Array-Hardware-Manual%281v1%29.pdf
XM0088546.1
USB Audio Design Guide 11/110
2.2.1 Microphones
The xCORE Microphone Array board features 7 MEMS microphones with PDM (Pulse
Density Modulation) output.
MIC6 MIC1
xCORE-200
XUF216
A B C D
Figure 2:
xCORE-200
MIC4 MIC3
Microphone
Array Board
Microphone
Arrangement
As well at 7 PDM microphones the board also provides a stereo DAC (CS43L21)
with integrated headphone amplifier. The CS43L21 is connected to the xCORE-200
through an I2S interface and is configured using an I2C interface.
XM0088546.1
USB Audio Design Guide 12/110
The CS2100 generates a low-jitter output signal that is distributed to the xCORE-
200 device and DAC. The CS2100 device is configured using the I2C interface.
The board has 13 LEDs that are controlled by the xCORE-200 GPIO. The layout of
the LEDs is shown in Figure 3.
D13 D2
MIC6 MIC1
D12 D3
xCORE-200
XUF216
D11 D4
D14
MIC5 MIC2
D10 A B C D D5
D6
Figure 3: D9
xCORE-200 MIC3
Microphone MIC4
Array Board D8 D7
LED
Arrangement
LED 0 to LED 11 (D2-D13) are positioned around the edge of the board, one
each side of every microphone. LED 12 (D14) is positioned next to the middle
microphone.
XM0088546.1
USB Audio Design Guide 13/110
A green LED (PGOOD) by the USB connector indicates a 3V3 power good signal.
Four general purpose push-button switches are provided. When pressed, each
button creates a connection from the I/O to GND.
A standard XMOS xSYS interface (J2) is provided to allow host debug of the board
via JTAG.
The board also includes Ethernet conextivity, however, this is outside the scope of
this documentation.
XM0088546.1
USB Audio Design Guide 14/110
· A main board which includes the XMOS U-series device and all audio
hardware
· A “USB Slice” board which contains USB connectivity
The separate USB slice board allows flexibility in the connection method to the USB
audio source/sink as well as other functionality such as 3rd party authentication
ICs and any required USB switching. This also means the XMOS device can be used
as a USB device or host using the same main board.
This document addresses the combination of the main board with the USB AB slice
(part numbers XK-USB-AUDIO-U8-2C and XA-SK-USB-AB respectively). This provides
a standard USB Audio device hardware configuration using the B socket on the USB
AB slice.
RCA
Gate SPDIF
MIDI Socket
5V
5V Analogue Audio
Charge Pump
4Mbit
Flash
Isolator &
Buffer
Buffer
System 5V
CS 24 bit 192kHz
MUX MIDI + DSD Stereo
VBUS IN 3.5mm
Stereo Audio Differential to
SPI Stereo
DAC Single Ended
USB USB TRS Jack
Active LPF
Slice High Speed I2S
EN CS4392
Connector
Preferential VBUS PCIE 36
I2C
5V OR
IN
Socket
GPIO XMOS
XS1-U8A-64
I2S 24 bit 192kHz
Stereo Audio Stereo 3.5mm
ADC Single Ended Stereo
VBUS
OUT
24MHz
MCLK
12V to 5V
DCDC FSEL Audio Master
Figure 4: Clock PLL
Multi- XSYS
Debug
2 x User
LEDs
Switch
&
Or
22.5792 MHz
Connector 2 x Push
function 12V DC
3A
Buttons & 24MHz
Cent +ve
Audio Kit Connector
Block
Diagram
The core board includes a U-Series device with integrated USB PHY, a stereo DAC
(with support for Direct Stream Digital) and a stereo ADC. Both ADC and DAC
12 http://www.xmos.com/products/reference-designs/mfa
XM0088546.1
USB Audio Design Guide 15/110
In addition the main board also includes two LEDs, two buttons and one two-
position switch for use by the user application.
The XMOS U16 Multi-Channel USB Audio kit13 is a hardware development platform
available from XMOS based on a dual tile XMOS U-series device.
· A sliceKIT core board which includes the XMOS U-series device (XP-SKC-U16)
· A “USB Slice” board which contains USB connectivity (XA-SK-USB-AB)
· A double-slot slice card including audio hardware and connectors (XA-SK-
AUDIO8)
The separate USB slice board allows flexibility in the connection method to the USB
audio source/sink as well as other functionality such as 3rd party authentication
ICs and any required USB switching. This also means the XMOS device can be used
as a USB device or host using the same main board.
This document addresses the combination of the main board with the USB AB
slice (part numbers XP-SKC-U16 and XA-SK-USB-AB respectively). This provides a
standard USB Audio device hardware configuration using the B socket on the USB
AB slice.
The core board includes a U-Series device with integrated USB PHY and required
supporting componentry.
Please note, for correct operation the following core-board jumper settings are
required:
As well as analogue channels the audio-slice also has MIDI input and output
connectors and both COAX and optical connectors for digital output.
Additionally the slice also includes an LED matrix and three push-buttons for use
by the user application.
13 http://www.xmos.com/usbaudio16mc
XM0088546.1
USB Audio Design Guide 16/110
The DJ naming simply comes from the fact the board has 4 input and 4 output
audio channels - a common configuration for a DJ controller.
The kit is made up of two boards a “core” board and an “audio slice” board. Part
numbers XP-SKC-SU1 and XA-SK-AUDIO respectively.
The core board includes a U-Series device with integrated USB PHY. The audio slice
board is equipped with two stereo audio CODECs giving 4 channels of input and 4
channels of output at sample frequencies up to 192kHz.
In addition to analogue channels the audio slice board also has MIDI input and
output connectors and a COAX connector for S/PDIF output.
The USB Audio 2.0 Reference Design15 is a stereo hardware reference design
available from XMOS based on an XMOS L8 device (previously named L1). The
diagram in Figure 5 shows the block layout of the USB Audio 2.0 Reference Design
board. The main purpose of the XS1 L-Series device is to provide a USB Audio
interface to the USB PHY and route the audio to the audio CODEC and S/PDIF output.
Note, although the software supports MIDI, there are no MIDI connectors on the
board.
For full hardware details please refer to the USB Audio 2.0 Ref Design XS1-L1
Hardware Manual16 .
The reference board has an associated firmware application that uses the USB
Audio 2.0 software reference platform. Details of this application can be found in
section §6.1.
14 https://www.xmos.com/support/boards?product=15404
15 https://www.xmos.com/support/boards?product=14772
16 https://www.xmos.com/published/usb-audio-20-ref-design-xs1-l1-hardware-manual
XM0088546.1
USB Audio Design Guide 17/110
JTAG SPI
MCLK Analog Out
1Vrms at
Full Scale
‘-244
USB Passive
Stereo
High Speed 24 bit 192kHz LPF
480Mb/s ULPI I2S TRS Jack
USB USB Stereo Audio
Series B Transceiver CODEC
Receptacle USB3318
‘-244
CS4270 Passive Stereo
LPF TRS Jack
+5V VBus
Analog In
2Vrms at
1.8V LDO Full Scale
Diagram
Figure 6 shows the block layout of the USB Audio 2.0 Multichannel Reference
Design board.
The board supports six analogue inputs and eight analogue outputs (via a CS4244
CODEC), digital input and output (via coax and optical connectors) and MIDI input
and output. For full details please refer to USB Audio 2.0 Reference Design, XS1-L2
Edition Hardware Manual18 .
The reference board has an associated firmware application that uses the USB
Audio 2.0 software reference platform. Details of this application can be found in
section §6.3.
17 https://www.xmos.com/support/boards?product=14771
18 https://www.xmos.com/download/public/USB-Audio-2.0-MC-Hardware-Manual%281.6%29.pdf
XM0088546.1
USB Audio Design Guide 18/110
<=
012..
012..
012..
012..
012..
Figure 6:
012..
USB Audio
2.0
012..
Multichannel
Reference
Design Block 012..
Diagram
XM0088546.1
3 Software Architecture
IN THIS CHAPTER
· The USB Audio System Architecture
· XMOS USB Device (XUD) Library
· Endpoint 0: Management and Control
· Audio Endpoints (Endpoint Buffer and Decoupler)
· Audio Driver
· Digital Mixer
· S/PDIF Transmit
· S/PDIF Receive
· ADAT Receive
· External Clock Recovery (ClockGen)
· MIDI
· PDM Microphones
· Overview of PDM implemention
· Resource Usage
The following sections describe the software architecture of the XMOS USB Audio
framework.
XMOS USB Audio solutions are provided as a framework with reference design
applications customising and extending this framework to provide the required
functionality. These applications execute on a reference hardware platform.
XM0088546.1
USB Audio Design Guide 20/110
Component Description
XMOS USB Device Driver (XUD) Handles the low level USB I/O.
Endpoint 0 Provides the logic for Endpoint 0 which handles
enumeration and control of the device including DFU
related requests.
Endpoint buffer Buffers endpoint data packets to and from the host.
Decoupler Manages delivery of audio packets between the
endpoint buffer component and the audio components.
Figure 7: It can also handle volume control processing.
Shared Audio Driver Handles audio I/O over I2S and manages audio data
Components to/from other digital audio I/O components.
Component Description
Mixer Allows digital mixing of input and output channels. It can also
handle volume control instead of the decoupler.
S/PDIF Transmitter Outputs samples of an S/PDIF digital audio interface.
S/PDIF Receiver Inputs samples of an S/PDIF digital audio interface (requires the
clockgen component).
ADAT Receiver Inputs samples of an ADAT digital audio interface (requires the
clockgen component).
Clockgen Drives an external frequency generator (PLL) and manages
changes between internal clocks and external clocks arising from
digital input.
Figure 8: MIDI Outputs and inputs MIDI over a serial UART interface.
Optional PDM Microphones Receives PDM data from microphones and performs PDM to PCM
Components conversion
Figure 9 shows how the components interact with each other. The green circles
represent cores with arrows indicating inter-core communications.
The XUD_Manager() function runs in its own core and communicates with endpoint
cores though a mixture of shared memory and channel communications.
XM0088546.1
USB Audio Design Guide 21/110
Figure 9:
USB Audio
Core Diagram
For more details and full XUD API documentation please refer to XMOS USB Device
(XUD) Library19
Figure 9 shows the XUD library communicating with two other cores:
· Endpoint Buffer: This core sends/receives data packets from the XUD library.
The core receives audio data from the decoupler core, MIDI data from the MIDI
core etc.
19 http://www.xmos.com/published/xuddg
XM0088546.1
USB Audio Design Guide 22/110
These tasks can be generally split into enumeration, audio configuration and
firmware upgrade requests.
3.3.1 Enumeration
When the device is first attached to a host, enumeration occurs. This process
involves the host interrogating the device as to its functionality. The device does
this by presenting several interfaces to the host via a set of descriptors.
During the enumeration process the host will issue various commands to the device
including assigning the device a unique address on the bus.
The endpoint 0 code runs in its own core and follows a similar format to that of
the USB Device examples in sc_usb_device (i.e. Example HID Mouse Demo). That
is, a call is made to USB_GetSetupPacket() to receive a command from the host.
This populates a USB_SetupPacket_t structure, which is then parsed.
There are many mandatory requests that a USB Device must support as required by
the USB Specification. Since these are required for all devices in order to function
a USB_StandardRequests() function is provided (see module_usb_device) which
implements all of these requests. This includes the following items:
For more information and full documentation, including full worked examples of
simple devices, please refer the XMOS USB Device Design Guide20
The function returns XUD_RES_ERR if the request was not recognised by the
USB_StandardRequests() function and a STALL has been issued.
20 https://www.xmos.com/zh/node/17007?page=9
XM0088546.1
USB Audio Design Guide 23/110
The function may also return XUD_RES_RST if a bus-reset has been issued onto the
bus by the host and communicated from XUD to Endpoint 0.
Before making the call to USB_StandardRequests() the setup packet is parsed for
Class requests. These are handled in functions such as AudioClasRequests_2(),
AudioClassRequests_2, DFUDeviceRequests() etc depending on the type of re-
quest.
Any device specific requests are handled - in this case Audio Class, MIDI class, DFU
requests etc.
Some of the common Audio Class requests and their associated behaviour will now
be examined.
When the host issues an audio request (e.g. sample rate or volume change),
it sends a command to Endpoint 0. Like all requests this is returned from
USB_GetSetupPacket(). After some parsing (namely as Class Request to an Au-
dio Interface) the request is handled by either the AudioClassRequests_1() or
AudioClassRequests_2() function (based on whether the device is running in Au-
dio Class 1.0 or 2.0 mode).
Note, Audio Class 1.0 Sample rate changes are send to the relevant endpoint,
rather than the interface - this is handled as a special case in he endpoint 0 request
parsing where AudioEndpointRequests_1() is called.
XM0088546.1
USB Audio Design Guide 24/110
The new sample frequency is extracted and passed via channel to the rest of
the design - through the buffering code and eventually to the Audio IO/I2S core.
The AudioClassRequests_2() function waits for a handshake to propagate back
though the system before signalling to the host that the request has completed
successfully. Note, during this time the USB library is NAKing the host essentially
holding off further traffic/requests until the sample-rate change is fully complete.
When the host requests a volume change, it sends an audio interface request to
Endpoint 0. An array is maintained in the Endpoint 0 core that is updated with
such a request.
When changing the volume, Endpoint 0 applies the master volume and channel
volume, producing a single volume value for each channel. These are stored in the
array.
The volume will either be handled by the decoupler core or the mixer component
(if the mixer component is used). Handling the volume in the mixer gives the
decoupler more performance to handle more channels.
If the effect of the volume control array on the audio input and output is imple-
mented by the decoupler, the decoupler core reads the volume values from this
array. Note that this array is shared between Endpoint 0 and the decoupler core.
This is done in a safe manner, since only Endpoint 0 can write to the array, word
update is atomic between cores and the decoupler core only reads from the array
(ordering between writes and reads is unimportant in this case). Inline assembly is
used by the decoupler core to access the array, avoiding the parallel usage checks
of XC.
All endpoints other that Endpoint 0 are handled in one core. This core is imple-
mented in the file usb_buffer.xc. This core is communicates directly with the XUD
library.
The USB buffer core is also responsible for feedback calculation based on USB Start
Of Frame (SOF) notification and reads from the port counter of a port connected to
the master clock.
XM0088546.1
USB Audio Design Guide 25/110
3.4.2 Decoupler
The decoupler supplies the USB buffering core with buffers to transmit/receive
audio data to/from the host. It marshals these buffers into FIFOs. The data from
the FIFOs are then sent over XC channels to other parts of the system as they need
it. This core also determines the size of each packet of audio sent to the host (thus
matching the audio rate to the USB packet rate). The decoupler is implemented in
the file decouple.xc.
This scheme is executed by co-operation between the buffering core, the decouple
core and the XUD library.
For data going from the device to the host the following scheme is used:
1. The decouple core receives samples from the audio core and puts them into a
FIFO. This FIFO is split into packets when data is entered into it. Packets are
stored in a format consisting of their length in bytes followed by the data.
2. When the buffer cores needs a buffer to send to the XUD core (after sending the
previous buffer), the decouple core is signalled (via a shared memory flag).
3. Upon this signal from the buffering core, the decouple core passes the next
packet from the FIFO to the buffer core. It also signals to the XUD library that
the buffer core is able to send a packet.
4. When the buffer core has sent this buffer, it signals to the decouple that the
buffer has been sent and the decouple core moves the read pointer of the FIFO.
For data going from the host to the device the following scheme is used:
1. The decouple core passes a pointer to the buffering core pointing into a FIFO of
data and signals to the XUD library that the buffering core is ready to receive.
2. The buffering core then reads a USB packet into the FIFO and signals to the
decoupler that the packet has been read.
3. Upon receiving this signal the decoupler core updates the write pointer of the
FIFO and provides a new pointer to the buffering core to fill.
4. Upon request from the audio core, the decoupler core sends samples to the
audio core by reading samples out of the FIFO.
To meet timing requirements of the audio system, the decoupler core must respond
to requests from the audio system to send/receive samples immediately. An
interrupt handler is set up in the decoupler core to do this. The interrupt handler
is implemented in the function handle_audio_request.
XM0088546.1
USB Audio Design Guide 26/110
The audio system sends a word over a channel to the decouple core to request
sample transfer (using the build in outuint function). The receipt of this word in
the channel causes the handle_audio_request interrupt to fire.
The first operation the interrupt handler does is to send back a word acknowledging
the request (if there was a change of sample frequency a control token would
instead be sent—the audio system uses a testct() to inspect for this case).
Sample transfer may now take place. First the audio subsystem transfers samples
destined for the host, then the decouple core sends samples from the host to
device. These transfers always take place in channel count sized chunks (i.e.
NUM_USB_CHAN_OUT and NUM_USB_CHAN_IN). That is, if the device has 10 output
channels and 8 input channels, 10 samples are sent from the decouple core and 8
received every interrupt.
The complete communication scheme is shown in the table below (for non sample
frequency change case):
The request and acknowledgement sent to/from Decouple to the Audio System is
an “output underflow” sample value. If in PCM mode it will be 0, in DSD mode it will
be DSD silence. This allows the buffering system to output a suitable underflow
value without knowing the format of the stream (this is especially advantageous in
the DSD over PCM (DoP) case)
The device uses a feedback endpoint to report the rate at which audio is output/in-
put to/from external audio interfaces/devices. This feedback is in accordance with
the USB 2.0 Specification.
XM0088546.1
USB Audio Design Guide 27/110
This asynchronous clocking scheme means that the device is the clocking master
than therefore means a high-quality local master clock source can be used.
After each received USB SOF token, the buffering core takes a time-stamp from
a port clocked off the master clock. By subtracting the time-stamp taken at the
previous SOF, the number of master clock ticks since the last SOF is calculated.
From this the number of samples (as a fixed point number) between SOFs can be
calculated. This count is aggregated over 128 SOFs and used as a basis for the
feedback value.
The sending of feedback to the host is also handled in the USB buffering core via
an explicit feedback IN endpoint. If both input and output is enabled then the
feedback is implicit based on the audio stream sent to the host.
The Audio core must consume data from USB and provide data to USB at the correct
rate for the selected sample frequency. The USB 2.0 Specification states that the
maximum variation on USB packets can be +/- 1 sample per USB frame. USB frames
are sent at 8kHz, so on average for 48kHz each packet contains six samples per
channel. The device uses Asynchronous mode, so the audio clock may drift and run
faster or slower than the host. Hence, if the audio clock is slightly fast, the device
may occasionally input/output seven samples rather than six. Alternatively, it may
be slightly slow and input/output five samples rather than six. Figure 11 shows
the allowed number of samples per packet for each example audio frequency.
See USB Device Class Definition for Audio Data Formats v2.0 section 2.3.1.1 for
full details.
44.1 5 6
48 5 7
Figure 11: 88.2 10 11
Allowed 96 11 13
samples per 176.4 20 21
packet 192 23 25
To implement this control, the decoupler core uses the feedback value calculated
in the buffering core. This value is used to work out the size of the next packet it
will insert into the audio FIFO.
XM0088546.1
USB Audio Design Guide 28/110
from the incoming master clock (typically the output of the external oscillator or
PLL). The audio driver is implemented in the file audio.xc.
The audio driver captures and plays audio data over I2S. It also forwards on relevant
audio data to the S/PDIF transmit core.
The audio core must be connected to a CODEC that supports I2S (other modes
such as “left justified” can be supported with firmware changes). In slave mode, the
XMOS device acts as the master generating the Bit Clock (BCLK) and Left-Right Clock
(LRCLK, also called Word Clock) signals. Any CODEC or DAC/ADC combination that
supports I2S and can be used.
Figure 12 shows the signals used to communicate audio between the XMOS device
and the CODEC.
Signal Description
The bit clock controls the rate at which data is transmitted to and from the CODEC.
In the case where the XMOS device is the master, it divides the MCLK to generate
the required signals for both BCLK and LRCLK, with BCLK then being used to clock
data in (SDIN) and data out (SDOUT) of the CODEC.
Figure 13 shows some example clock frequencies and divides for different sample
rates (note that this reflects the single tile L-Series reference board configuration):
The master clock must be supplied by an external source e.g. clock generator,
fixed oscillators, PLL etc to generate the two frequencies to support 44.1kHz and
48kHz audio frequencies (e.g. 11.2896/22.5792MHz and 12.288/24.576MHz
respectively). This master clock input is then provided to the CODEC and the XMOS
device.
XM0088546.1
USB Audio Design Guide 29/110
The default software configuration is CODEC Slave (xCORE master). That is, the
XMOS device provides the BCLK and LRCLK signals to the CODEC.
XS1 ports and XMOS clocks provide many valuable features for implementing I2S.
This section describes how these are configured and used to drive the I2S interface.
L8A-64-TQ128
p_mclk Audio master clock
clk_audio_mclk
p_bclk
clk_audio_bclk p_lrclk
CODEC
p_sdin
Figure 14:
Ports and
Clocks p_sdout
(CODEC slave)
The code to configure the ports and clocks is in the ConfigAudioPorts() function.
Developers should not need to modify this.
The XMOS device inputs MCLK and divides it down to generate BCLK and LRCLK.
To achieve this MCLK is input into the device using the 1-bit port p_mclk. This
is attached to the clock block clk_audio_mclk, which is in turn used to clock the
BCLK port, p_bclk. BCLK is used to clock the LRCLK (p_lrclk) and data signals
SDIN (p_sdin) and SDOUT (p_sdout). Again, a clock block is used (clk_audio_bclk)
which has p_bclk as its input and is used to clock the ports p_lrclk, p_sdin and
p_sdout. The preceding diagram shows the connectivity of ports and clock blocks.
p_sdin and p_sdout are configured as buffered ports with a transfer width of 32,
so all 32 bits are input in one input statement. This allows the software to input,
process and output 32-bit words, whilst the ports serialize and deserialize to the
single I/O pin connected to each port.
xCORE-200 series devices have the ability to divide an extenal clock in a clock-block.
However, XS1 based devices do not have this functionality. In order achieve the
reqired master-clock to bit-clock/LR-clock divicd on XS1 devices, buffered ports
with a transfer width of 32 are also used for p_bclk and p_lrclk. The bit clock
is generated by performing outputs of a particular pattern to p_bclk to toggle
the output at the desired rate. The pattern depends on the divide between the
XM0088546.1
USB Audio Design Guide 30/110
master-clock and bit-clock. The following table shows the required pattern for
different values of this divide:
In any case, the bit clock outputs 32 clock cycles per sample. In the special
case where the divide is 1 (i.e. the bit clock frequency equals the master clock
frequency), the p_bclk port is set to a special mode where it simply outputs its
clock input (i.e. p_mclk). See configure_port_clock_output() in xs1.h for details.
p_lrclk is clocked by p_bclk. In I2S mode the port outputs the pattern 0x7fffffff
followed by 0x80000000 repeatedly. This gives a signal that has a transition one
bit-clock before the data (as required by the I2S standard) and alternates between
high and low for the left and right channels of audio.
When the host changes sample frequency, a new frequency is sent to the audio
driver core by Endpoint 0 (via the buffering cores and mixer).
Upon receiving the change of sample frequency request, the audio core stops the
I2S/TDM interface and calls the CODEC/port configuration functions.
Once this is complete, the I2S/TDM interface is restarted at the new frequency.
The mixer takes two cores and can perform eight mixes with up to 18 inputs at
sample rates up to 96kHz and two mixes with up to 18 inputs at higher sample
rates. The component automatically moves down to two mixes when switching to
a higher rate.
· The USB outputs from the host—these samples come from the decoupler core.
XM0088546.1
USB Audio Design Guide 31/110
· The inputs from the audio interface on the device—these samples come from
the audio driver.
Since the sum of these inputs may be more then the 18 possible mix inputs to
each mixer, there is a mapping from all the possible inputs to the mixer inputs.
After the mix occurs, the final outputs are created. There are two output destina-
tions:
· The USB inputs to the host—these samples are sent to the decoupler core.
· The outputs to the audio interface on the device—these samples are sent to the
audio driver.
For each possible output, a mapping exists to tell the mixer what its source is.
The possible sources are the USB outputs from the host, the inputs for the audio
interface or the outputs from the mixer units.
As mentioned in §3.3.3.3, the mixer can also handle volume setting. If the mixer
is configured to handle volume but the number of mixes is set to zero (so the
component is solely doing volume setting) then the component will use only one
core.
3.6.1 Control
The mixers can receive the following control commands from the Endpoint 0 core
via a channel:
Command Description
SET_SAMPLES_TO_HOST_MAP Sets the source of one of the audio streams going to the
host.
SET_SAMPLES_TO_DEVICE_MAP Sets the source of one of the audio streams going to the
audio driver.
SET_MIX_MULT Sets the multiplier for one of the inputs to a mixer.
SET_MIX_MAP Sets the source of one of the inputs to a mixer.
SET_MIX_IN_VOL If volume adjustment is being done in the mixer, this
command sets the volume multiplier of one of the USB
Figure 16: audio inputs.
Mixer SET_MIX_OUT_VOL If volume adjustment is being done in the mixer, this
Component command sets the volume multiplier of one of the USB
Commands audio outputs.
XM0088546.1
USB Audio Design Guide 32/110
· Set the mapping for physical outputs which can either come directly from the
inputs or via the mixer.
There is enough flexibility within this configuration that there will often be multiple
ways of creating the required solution.
Whilst using the XMOS Host control example application, consider setting the mixer
to perform a loop-back from analogue inputs 1 and 2 to analogue outputs 1 and 2.
displays which channels could possibly be mapped to mixer inputs. Notice that
analogue inputs 1 and 2 are on mixer inputs 10 and 11.
displays which channels are mapped to which outputs. By default all of these
bypass the mixer. We can also see what all the possible mappings are:
So now map the first two mixer outputs to physical outputs 1 and 2:
This now makes analogue outputs 1 and 2 come from the mixer, rather than
directly from USB. However the mixer is still mapped to pass the USB channels
through to the outputs, so there will still be no functional change yet.
The mixer nodes need to be individually set. They can be displayed with:
XM0088546.1
USB Audio Design Guide 33/110
To get the audio from the analogue inputs to outputs 1 and 2, nodes 80 and 89
need to be set:
As mentioned above, the flexibility of the mixer is such that there will be multiple
ways to create a particular mix. Another option to create the same routing would be
to change the mixer sources such that mixer 1/2 outputs come from the analogue
inputs.
The mixer should now have the default values. The sources for mixer 1/2 can now
be changed:
If you rerun:
the first column now has AUD - Analogue 1 and 2 rather than DAW (Digital Audio
Workstation i.e. the host) - Analogue 1 and 2 confirming the new mapping. Again,
by playing audio into analogue inputs 1/2 this can be heard looped through to
analogue outputs 1/2.
XM0088546.1
USB Audio Design Guide 34/110
The S/PDIF transmitter core takes PCM audio samples via a channel and outputs
them in S/PDIF format to a port. A lookup table is used to encode the audio data
into the required format.
It receives samples from the Audio I/O core two at a time (for left and right). For
each sample, it performs a lookup on each byte, generating 16 bits of encoded
data which it outputs to a port.
S/PDIF sends data in frames, each containing 192 samples of the left and right
channels.
Audio samples are encapsulated into S/PDIF words (adding preamble, parity,
channel status and validity bits) and transmitted in biphase-mark encoding (BMC)
with respect to an external master clock.
Figure 17: Sample frequencies 44.1, 48, 88.2, 96, 176.4, 192 kHz
S/PDIF Master clock ratios 128x, 256x, 512x
Capabilities Module module_spdif_tx
3.7.1 Clocking
PORT
Figure 18:
PORT D-type
D-Type Jitter S/PDIF S/PDIF
Reduction DATA TX
The S/PDIF signal is output at a rate dictated by the external master clock. The
master clock must be 1x 2x or 4x the BMC bit rate (that is 128x 256x or 512x audio
sample rate, respectively). For example, the minimum master clock frequency for
192kHz is therefore 24.576MHz.
This resamples the master clock to its clock domain (oscillator), which introduces
jitter of 2.5-5 ns on the S/PDIF signal. A typical jitter-reduction scheme is an
external D-type flip-flop clocked from the master clock (as shown in the preceding
diagram).
XM0088546.1
USB Audio Design Guide 35/110
3.7.2 Usage
The interface to the S/PDIF transmitter core is via a normal channel with streaming
built-ins (outuint, inuint). Data format should be 24-bit left-aligned in a 32-bit
word: 0x12345600
The stream is composed of words with the following structure shown in Figure 20.
The channel status bits are 0x0nc07A4, where c=1 for left channel, c=2 for right
channel and n indicates sampling frequency as shown in Figure 21.
Bits
Frequency (kHz) n
44.1 0
48 2
88.2 8
Figure 21: 96 A
Channel 176.4 C
Status Bits 192 E
XM0088546.1
USB Audio Design Guide 36/110
The S/PDIF receiver module uses a clockblock and a buffered one-bit port. The
clock-block is divided of a 100 MHz reference clock. The one bit port is buffered
to 4-bits. The receiver code uses this clock to over sample the input data.
The receiver outputs audio samples over a streaming channel end where data can
be input using the built-in input operator.
The S/PDIF receive function never returns. The 32-bit value from the channel input
comprises:
Bits
Figure 22:
S/PDIF RX 0:3 A tag (see below)
Word 4:28 PCM encoded sample value
Structure 29:31 User bits (parity, etc)
Tag Meaning
See S/PDIF specification for further details on format, user bits etc.
Since S/PDIF is a digital steam the devices master clock must be syncronised to it.
This is typically done with an external fractional-n multipier. See Clock Recovery
(§3.10)
The S/PDIF receive function communicates with the clockGen component with
passes audio data to the audio driver and handles locking to the S/PDIF clock
source if required (see External Clock Recovery).
Ideally the parity of each word/sample received should be checked. This is done
using the built in crc32 function (see xs1.h):
If bad parity is detected the word/sample is ignored, otherwise the tag is inspected
for channel (i.e. left or right) and the sample stored.
XM0088546.1
USB Audio Design Guide 37/110
The following code snippet illustrates how the output of the S/PDIF receive compo-
nent could be used:
while (1)
{
c_spdif_rx : > data ;
if ( badParity ( data )
continue ;
switch ( tag )
{
case FRAME_X :
case FRAME_X :
// Store left
break ;
case FRAME_Z :
// Store right
break ;
}
}
The component outputs 32 bits words split into nine word frames. The frames are
laid out in the following manner:
· Control byte
· Channel 0 sample
· Channel 1 sample
· Channel 2 sample
· Channel 3 sample
· Channel 4 sample
· Channel 5 sample
· Channel 6 sample
XM0088546.1
USB Audio Design Guide 38/110
· Channel 7 sample
Example of code show how to read the output of the ADAT component is shown
below:
Samples are 24-bit values contained in the lower 24 bits of the word.
The control word comprises four control bits in bits [11..8] and the value
0b00000001 in bits [7..0]. This control word enables synchronization at a higher
level, in that on the channel a single odd word is always read followed by eight
words of data.
3.9.1 Integration
Since the ADAT is a digital stream the devices master clock must synchronised to
it. This is typically achieved with an external fractional-n clock multiplier.
The ADAT receive function communicates with the clockGen component which
passes audio data onto the audio driver and handles locking to the ADAT clock
source if required.
The clock recovery core (clockGen) is responsible for generating the reference
frequency to the Fractional-N Clock Generator. This, in turn, generates the master
clock used over the whole design.
When running in Internal Clock mode this core simply generates this clock using a
local timer, based on the XMOS reference clock.
When running in an external clock mode (i.e. S/PDIF Clock” or “ADAT Clock” mode)
digital samples are received from the S/PDIF and/or ADAT receive core.
XM0088546.1
USB Audio Design Guide 39/110
ensure that valid master clock generation continues regardless of cable unplugs
etc.
This core gets clock selection Get/Set commands from Endpoint 0 via the c_clk_ctl
channel. This core also records the validity of external clocks, which is also queried
through the same channel from Endpoint 0.
This core also can cause the decouple core to request an interrupt packet on change
of clock validity. This functionality is based on the Audio Class 2.0 status/interrupt
endpoint feature.
3.11 MIDI
The MIDI driver implements a 31250 baud UART input and output. On receiving
32-bit USB MIDI events from the buffer core, it parses these and translates them
to 8-bit MIDI messages which are sent over UART. Similarly, incoming 8-bit MIDI
messages are aggregated into 32-bit USB-MIDI events an passed on to the buffer
core. The MIDI core is implemented in the file usb_midi.xc.
Interfacing to the PDM microphones is done using the XMOS microphone array
library (lib_mic_array). lib_mic_array is designed to allow interfacing to PDM
microphones coupled with efficient decimation to user selectable output sample
rates.
· PDM interface
XM0088546.1
USB Audio Design Guide 40/110
3.072 MHz
8..48 kHz
8..48 kHz
8..48 kHz
384 kHz
96 kHz
1x4 ch
1x4 ch
1x4 ch
1x4 ch
1x4 ch
4 ch
Figure 24:
One to four Div N Select Overlapping
Div 8 Div 4 Decimator DC offset frames Voice
channel Decimator Decimator N=2,4,6,8 FIR comp WIndowing app
or 12 Gain comp Bit reverse
count PDM
mic_array_pdm_rx() mic_array_decimate_to_pcm_4ch()
interface
for 5-8 channels three logical cores are required, as shown below:
3.072 MHz
8..48 kHz
8..48 kHz
8..48 kHz
384 kHz
96 kHz
2x4 ch
2x4 ch
2x4 ch
2x4 ch
2x4 ch
8 ch
After the decimation to the output sample-rate various other steps take place
e.g. DC offset elimination, gain correction and compensation etc. Please refer
to lib_mic_array documention for further implementation detail and complete
feature set.
The PDM microphones need a clock input and provide the PDM signal on a data
output. All PDM microphones share the same clock signal (buffered on the PCB as
appropriate), and output onto eight data wires that are connected to a single 8-bit
port:
XM0088546.1
USB Audio Design Guide 41/110
Figure 26:
PDM
microphone
data and CLOCK Clock line, the PDM clock the used by the microphones to drive the data out.
signal wires
DQ_PDM The data from the PDM microphones on an 8 bit port.
The only port that is passed into lib_mic_array is the 8-bit data port. The library
assumes that the input port is clocked using the PDM clock and requires no
knowlege of the PDM clock source.
The input clock for the microphones can be generated in a multitude of ways. For
example, a 3.072MHz clock can be generated on the board, or the xCORE can
divide down 12.288 MHz master clock. Or, if clock accuracy is not important, the
internal 100 MHz reference can be divided down to provide an approximate clock.
A PDM microphone wrapper is called from main() and takes one channel argument
connecting it to the rest of the system:
pcm_pdm_mic(c_pdm_pcm);
The first job of this function is to configure the ports/clocking for the microphones,
this divides the external audio master clock input (on port p_mclk) and outputs the
divided clock to the microphones via the p_pdm_clk port:
c o n f i g u r e _ c l o c k _ s r c _ d i v i d e ( pdmclk , p_mclk , M C L K _ T O _ P D M _ C L K _ D I V ) ;
c o n f i g u r e _ p o r t _ c l o c k _ o u t p u t ( p_pdm_clk , pdmclk ) ;
c o n f i g u r e _ i n _ p o r t ( p_pdm_mics , pdmclk ) ;
start_clock ( pdmclk ) ;
It then runs the various cores required for the PDM interface and PDM to PCM
conversion as discussed previously:
par
{
m i c _ a r r a y _ p d m _ r x ( p_pdm_mics , c_4x_pdm_mic_0 , c_4x_ pdm_mi c_1 ) ;
m i c _ a r r a y _ d e c i m a t e _ t o _ p c m _ 4 c h ( c_4x_pdm_mic_0 , c_ds_output [0]) ;
m i c _ a r r a y _ d e c i m a t e _ t o _ p c m _ 4 c h ( c_4x_pdm_mic_1 , c_ds_output [1]) ;
pdm_process ( c_ds_output , c_pcm_out ) ;
}
The pdm_process() task includes the main integration code, it takes audio from the
lib_mic_array cores, buffers it, performs optional local processing and outputs it
to the audio driver (TDM/I2S core).
XM0088546.1
USB Audio Design Guide 42/110
These resource estimates are based on the multichannel reference design with all
options of that design enabled. For fewer channels, the resource usage is likely to
decrease.
The XUD library requires an 80MIPS core to function correctly (i.e. on a 500MHz
part only six cores can run).
The ULPI ports are a fixed set of ports on the L-Series device. When using these
ports, other ports are unavailable when ULPI is active. See the XS1-L Hardware
Design Checklist21 for further details.
21 http://www.xmos.com/published/xs1lcheck
XM0088546.1
4 Features & Options
IN THIS CHAPTER
· Device Firmware Upgrade (DFU)
· USB Audio Class Version Support
· Audio Controls via Human Interface Device (HID)
· Apple MFi compatibility
· Audio Stream Formats
· DSD over PCM (DoP)
This section looks at some of the available features of the USB Audio design.
The interface links USB to the XMOS flash user library (see XM-000953-PC). In
Application mode the DFU can accept commands to reset the device into DFU mode.
There are two ways to do this:
· The host can send a DETACH request and then reset the device. If the device is
reset by the host within a specified timeout, it will start in DFU mode (this is
initially set to one second and is configurable from the host).
· The host can send a custom user request XMOS_DFU_RESETDEVICE to the DFU
interface that resets the device immediately into DFU mode.
Once the device is in DFU mode. The DFU interface can accept commands defined
by the DFU 1.1 class specification22 . In addition the interface accepts the custom
command XMOS_DFU_REVERTFACTORY which reverts the active boot image to the
factory image. Note that the XMOS specific command request identifiers are
defined in dfu_types.h within module_dfu.
USB Audio Class 2.0 offers many improvements over USB Audio Class 1.0, most
notable is the complete support for high-speed operation. This means that Audio
22 http://www.usb.org/developers/devclass_docs/DFU_1.1.pdf*USB
XM0088546.1
USB Audio Design Guide 44/110
Class devices are no longer limited to full-speed operation allowing greater channel
counts, sample frequencies and sample bit-depths. Additional improvement,
amoungst others, include:
· Added support for multiple clock domains, clock description and clock control
· Extensive support for interrupts to inform the host about dynamic changes that
occur to different entities such as Clocks etc
Audio Class 1.0 is fully supported in Apple OSX. Audio Class 1.0 is fully supported
in all modern Microsoft Windows operating systems (i.e. Windows XP and later).
Audio Class 2.0 is fully supported in Apple OSX since version 10.6.4. Audio Class
2.0 is not supported natively by Windows operating systems. It is therefore required
that a driver is installed. Documentation of Windows drivers is beyond the scope
of this document, please contact XMOS for further details.
The normal default for XMOS USB Audio applications is to run as a high-speed
Audio Class 2.0 device. However, some products may prefer to run in Audio Class
1.0 mode, this is normally to allow “driver-less” operation with Windows operating
systems.
The device will operate in full-speed Audio Class 1.0 mode if one of the following
is true:
· The code is compiled for USB Audio Class 2.0 and it is connected to the host
over a full speed link (and the Audio Class fall back is enabled).
When running in Audio Class 1.0 mode the following restrictions are applied:
· MIDI is disabled.
· DFU is disabled (Since Windows operating systems would prompt for a DFU
driver to be installed)
XM0088546.1
USB Audio Design Guide 45/110
· Sample rate is limited to a maximum of 48kHz if both input and output are
enabled.
1. HID descriptors are enabled in the Configuration Descriptor informing the host
that the device has HID interface
The Get Descriptor Request enabled in endpoint 0 returns the report descriptor for
the HID device. This details the format of the HID reports returned from the device
to the host. It maps a bit in the report to a function such as play/pause.
The USB Audio Framework implements a report descriptor that should fit most basic
audio device controls. If further controls are necessary the HID Report Descriptor
in descriptors.h should be modified. The default report size is 1 byte with the
format as follows:
Bit Function
0 Play/Pause
1 Scan Next Track
2 Scan Prev Track
Figure 28: 3 Volume Up
Default HID 4 Volume Down
Report 5 Mute
Format 6-7 Unused
On each HID report request from the host the function Vendor_ReadHidButtons(unsigned char h
is called from buffer(). This function is passed an array hidData[] by reference.
The programmer should report the state of his buttons into this array. For
example, if a volume up command is desired, bit 3 should be set to 1, else 0.
XM0088546.1
USB Audio Design Guide 46/110
Since the Vendor_ReadHidButtons() function is called from the buffer logical core,
care should be taken not to add to much execution time to this function since this
could cause issues with servicing other endpoints.
An AudioStreaming interface can have Alternate Settings that can be used to change
certain characteristics of the interface and underlying endpoint. A typical use of
Alternate Settings is to provide a way to change the subframe size and/or number
of channels on an active AudioStreaming interface. Whenever an AudioStreaming
interface requires an isochronous data endpoint, it must at least provide the
default Alternate Setting (Alternate Setting 0) with zero bandwidth requirements
(no isochronous data endpoint defined) and an additional Alternate Setting that
contains the actual isochronous data endpoint.
For further information refer to 3.16.2 of USB Audio Device Class Definition for
Audio Devices23
23 http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
XM0088546.1
USB Audio Design Guide 47/110
An audio subslot holds a single audio sample. See USB Device Class Definition for
Audio Data Formats24 for full details. This is represented by bSubslotSize in the
devices descriptors
Typically, since it is run on a 32-bit machine, the value 4 is used for subslot -
this means that packing/unpacking samples is trivial. Other values can be used
(currently 4, 3 and 2 are supported by the design).
· To support restrictions with certain hosts. For example many Android based
hosts support only 16bit samples in a 2-byte subslot.
24 http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
XM0088546.1
USB Audio Design Guide 48/110
The design supports two audio formats, PCM and Direct Stream Digital (DSD). A
DSD capable DAC is required for the latter.
The USB Audio Raw Data format is used to indicate DSD data (2.3.1.7.5 of USB
Device Class Definition for Audio Data Formats25 ). This use of a RAW/DSD format
in an alternative setting is termed Native DSD
· STREAM_FORMAT_OUTPUT_1_DATAFORMAT
· STREAM_FORMAT_OUTPUT_2_DATAFORMAT
· STREAM_FORMAT_OUTPUT_3_DATAFORMAT
· UAC_FORMAT_TYPEI_RAW_DATA
· UAC_FORMAT_TYPEI_PCM
4 byte slot size with a 32 bit resolution is required for RAW/DSD format
Native DSD requires driver support and is available in the Thesycon Windows driver
via ASIO.
Since the Apple OS only allows a PCM path a method of transporting DSD audio
data over PCM frames has been developed. This data can then be sent via the
native USB Audio support.
The XMOS USB Audio design(s) implement the method described in DoP Open
Standard 1.126
25 http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
26 http://dsd-guide.com/sites/default/files/white-papers/DoP_openStandard_1v1.pdf
XM0088546.1
USB Audio Design Guide 49/110
Standard DSD has a sample size of 1 bit and a sample rate of 2.8224MHz - this is
64x the speed of CD. This equates to the same data-rate as a 16 bit PCM stream at
176.4kHz.
In order to clearly identify when this PCM stream contains DSD and when it contains
PCM some header bits are added to the sample. A 24-bit PCM stream is therefore
used, with the most significant byte being used for a DSD marker (alternating 0x05
and 0xFA values).
When enabled, if USB audio design detects a un-interrupted run of these samples
(above a defined threshold) it switches to DSD mode, using the lower 16-bits as
DSD sample data. When this check for DSD headers fails the design falls back to
PCM mode. DoP detection and switching is done completely in the Audio/I2S core
(audio.xc). All other code handles the audio samples as PCM.
The design supports higher DSD/DoP rates (i.e. DSD128) by simply raising the
underlying PCM sample rate e.g. from 176.4kHz to 352.8kHz. The marker byte
scheme remains exactly the same regardless of rate.
XM0088546.1
5 Programming Guide
IN THIS CHAPTER
· Getting Started
· Project Structure
· Build Configurations
· Validated Build Configurations
· Configuration Naming Scheme
· A USB Audio Application
· Adding Custom Code
The following sections provide a guide on how to program the USB audio software
platform including instructions for building and running programs and creating
your own custom USB audio applications.
To build, select the relavant project (e.g. app_usb_aud_l1) in the Project Explorer
and click the Build icon.
To install the software, open the xTIMEcomposer Studio and follow these steps:
3. Click Browse next to Select archive file and select the file firmware ZIP file.
4. Make sure the projects you want to import are ticked in the Projects list. Import
all the components and whichever applications you are interested in.
5. Click Finish.
To build, select the relevant project (e.g. app_usb_aud_l1) in the Project Explorer
and click the Build icon.
XM0088546.1
USB Audio Design Guide 51/110
xmake all
The main Makefile for the project is in the app directory (e.g. app_usb_aud_l1).
This file specifies build options and used modules. The Makefile uses the common
build infrastructure in module_xmos_common. This system includes the source files
from the relevant modules and is documented within module_xmos_common.
2. Connect the xTAG-2 to the USB Audio board and plug the xTAG-2 into your PC
or Mac.
8. Browse for the XE file in the Project and C/XC Application boxes.
1. Open the XMOS command line tools (Desktop Tools Prompt) and execute the
following command:
xflash < binary >. xe
XM0088546.1
USB Audio Design Guide 52/110
The code is split into several module directories. The code for these modules
can be included by adding the module name to the USED_MODULES define in an
application Makefile:
There are multiple application directories that contain Makefiles that build into
executables:
Build configurations are listed in the application makefile with their associated
options, they can be built within the xTIMEComposer GUI or via the command like
as follows:
When a reference design application is compiled using “build all” (xmake all on
command line) all configurations are automatically built.
XM0088546.1
USB Audio Design Guide 53/110
Each relevant build option is assigned a position in the configuration name, with
a character denoting the options value (normally ‘x’ is used to denote “off” or
“disabled”)
For example, Figure 31 lists the build options for the single tile L-Series Reference
Design.
For example a binary named 2ioxs would indicate Audio Class 2.0 with input and
output enabled, MIDI disabled, SPDIF output enabled.
In each application directory the src directory is arranged into two folders:
#. An core directory containing source items that must be made available to the
USB Audio framework
1. A .xn file to describe the hardware platform the app will run on
XM0088546.1
USB Audio Design Guide 54/110
The customdefines.h file contains all the #defines required to tailor the USB audio
framework to the particular application at hand. Typically these over-ride default
values in devicedefines.h in module_usb_audio.
First there are defines to determine overall capability. For this appliction S/PDIF
output and DFU are enabled. Note that ifndef is used to check that the option is
not already defined in the makefile.
Next, the file defines the audio properties of the application. This application has
stereo in and stereo out with an S/PDIF output that duplicates analogue channels 1
and 2 (note channels are indexed from 0):
The file then sets some defines for the master clocks on the hardware and the
maximum sample-rate for the device.
XM0088546.1
USB Audio Design Guide 55/110
Finally, there are some general USB identification defines to be set. These are set
for the XMOS reference design but vary per manufacturer:
For a full description of all the defines that can be set in customdefines.h see §7.1
In addition to the custom defines file, the application needs to provide implemen-
tations of user functions that are specific to the application.
Firstly, code is required to initialise the external audio hardware. In the case of the
CODEC on the L1 Refence Design board there is no required action so the funciton
is left empty:
Both the CODEC reset line and clock selection line are attached to the 32 bit port
32A. This is accessed through the port32A_peek and port32A_out functions:
# define PORT32A_PEEK ( X ) { asm ( " peek %0 , res [%1] " : " = r " ( X ) : " r " ( XS1_PORT_32A ) )
> ;}
# define PORT32A_OUT ( X ) { asm ( " out res [%0] , %1 " :: " r " ( XS1_PORT_32A ) ," r " ( X ) ) ;}
XM0088546.1
USB Audio Design Guide 56/110
if (( samFreq % 22050) == 0)
{
/* Frequency select low for 441000 etc */
tmp &= (~ P32A_CLK_SEL ) ;
}
else // if (( samFreq % 24000) == 0)
{
/* Frequency select high for 48000 etc */
tmp |= P32A_CLK_SEL ;
}
PORT32A_OUT ( tmp ) ;
Finally, the application has functions for audio streaming start/stop that enable/dis-
able an LED on the board (also on port 32A):
XM0088546.1
USB Audio Design Guide 57/110
/* Any actions required for stream start e . g . DAC un - mute - run every
* stream start .
*
* For L1 USB Audio Reference Design we illuminate LED B ( connected
* to port 32 A )
*
* Since this port is shared with other functionality inline assembly
* is used to access the port resource .
*/
void U s e r A u d i o S t r e a m S t a r t ( void )
{
int x ;
x |= P32A_LED_B ;
/* Output to port */
asm ( " out res [%0] , %1 " :: " r " ( XS1_PORT_32A ) ," r " ( x ) ) ;
}
asm ( " peek %0 , res [%1] " : " = r " ( x ) : " r " ( XS1_PORT_32A ) ) ;
x &= (~ P32A_LED_B ) ;
asm ( " out res [%0] , %1 " :: " r " ( XS1_PORT_32A ) ," r " ( x ) ) ;
}
The main() function is shared across all applications is therefore part of the
framework. It is located in sc_usb_audio and contains:
· A declaration of all the ports used in the framework. These vary depending on
the PCB an application is running on.
· A main function which declares some channels and then has a par statement
which runs the required cores in parallel.
XM0088546.1
USB Audio Design Guide 58/110
The framework supports devices with multiple tiles so it uses the on tile[n]:
syntax.
# if ( AUDIO_CLASS ==2)
XUD_Manager ( c_xud_out , ENDPOINT_COUNT_OUT , c_xud_in , ENDPOINT_COUNT_IN ,
c_sof , epTypeTableOut , epTypeTableIn , p_usb_rst ,
clk , 1 , XUD_SPEED_HS , XUD_PWR_CFG ) ;
# else
XUD_Manager ( c_xud_out , ENDPOINT_COUNT_OUT , c_xud_in , ENDPOINT_COUNT_IN ,
c_sof , epTypeTableOut , epTypeTableIn , p_usb_rst ,
clk , 1 , XUD_SPEED_FS , XUD_PWR_CFG ) ;
# endif
The make up of the channel arrays connecting to this driver are described in §7.3.
The channels connected to the XUD driver are fed into the buffer and decouple
cores:
XM0088546.1
USB Audio Design Guide 59/110
{
thread_speed () ;
decouple ( c_mix_out
# ifdef CHAN _BUFF_ CTRL
, c_buff_ctrl
# endif
);
}
These then connect to the audio driver which controls the I2S output and S/PDIF
output (if enabled). If S/PDIF output is enabled, this component spawns into two
cores as opposed to one.
XM0088546.1
USB Audio Design Guide 60/110
{
thread_speed () ;
# ifdef MIXER
# define AUDIO_CHANNEL c_mix_out
# else
# define AUDIO_CHANNEL c_aud_in
# endif
audio ( AUDIO_CHANNEL ,
# if defined ( SPDIF_TX ) && ( SPDIF_TX_TILE != AUDIO_IO_TILE )
c_spdif_tx ,
# endif
# if defined ( SPDIF_RX ) || defined ( ADAT_RX )
c_dig_rx ,
# endif
c_aud_cfg , c_adc
# if XUD_TILE != 0
, dfuInterface
# endif
# if ( NUM_PDM_MICS > 0)
, c_pdm_pcm
# endif
# ifdef RUN_DSP_TASK
, i_dsp
# endif
);
}
Finally, if MIDI is enabled you need a core to drive the MIDI input and output.
The MIDI core also optionally handles authentication with Apple devices. Due to
licensing issues this code is only available to Apple MFI licensees. Please contact
XMOS for details.
on tile [ MIDI_TILE ]:
{
thread_speed () ;
usb_midi ( p_midi_rx , p_midi_tx , clk_midi , c_midi , 0 , null , null , null ,
> null ) ;
}
XM0088546.1
USB Audio Design Guide 61/110
The reference designs have been verified against a variety of host OS types, across
different samples rates. However, modifications to the code may invalidate the
results of this verification and you are strongly encouraged to fully re- test the
resulting software.
2. Make a copy of any modules you wish to alter (most of the time you probably
do not want to do this). Update the Makefile of your new application to use
these new custom modules.
3. Make appropriate changes to the code, rebuild and reflash the device for testing.
1. Provide a .xn file for your board (updating the TARGET variable in the Makefile
appropriately).
3. Update main.xc.
The following sections show some example changes with a high level overview of
how to change the code.
You may wish to customize the digital output format e.g. for a CODEC that expects
sample data left justified with respect to the word clock.
To do this you need to alter the main audio driver loop in audio.xc. After the
alteration you need to re-test the functionality. The XMOS Timing Analyzer can
help guarantee that your changes do not break the timing requirement of this core.
To add some DSP requires an extra core of computation, so some existing func-
tionality needs to be removed (e.g. S/PDIF). Follow these steps to update the
code:
2. Add another core to do the DSP. This core will probably have three XC channels:
one channel to receive samples from decoupler core and another to output to
the audio driver—this way the core ‘intercepts’ audio data on its way to the
audio driver; the third channel can receive control commands from Endpoint 0.
XM0088546.1
USB Audio Design Guide 62/110
3. Implement the DSP on this core. This needs to be synchronous (i.e. for every
sample received from the decoupler, a sample needs to be outputted to the
audio driver).
XM0088546.1
6 USB Audio Applications
IN THIS CHAPTER
· USB Audio 2.0 Reference Design (L-Series) Application
· The USB Audio 2.0 DJ Kit (U-Series)
· The USB Audio 2.0 Multichannel Reference Design (L-Series) Software
· The Multi-function Audio Kit (U-Series)
· The U-Series Multi-Channel USB Audio Kit
· The xCORE-200 Multi-Channel Audio Board
· The xCORE-200 Array Microphone Board
· Endpoint 0
· Endpoint buffer
· Decoupler
· Audio Driver
The diagrams Figure 32 and Figure 33 show the software layout of the code running
on the XS1-L chip. Each unit runs in a single core concurrently with the others units.
The lines show the communication between each functional unit. Due to the MIPS
requirement of the USB driver (see §3.14), only six cores can be run on the single
tile L-Series device so only one of S/PDIF transmit or MIDI can be supported.
XM0088546.1
USB Audio Design Guide 64/110
Figure 32:
Single Tile
L-Series
Software
Core Diagram
(with S/PDIF
TX)
Figure 33:
Single Tile
L-Series
Software
Core Diagram
(with MIDI
I/O)
Port 32A on the XS1-L device is a 32-bit wide port that has several separate signal
bit signal connected to it, accessed by multiple cores. To this end, any output
to this port must be read-modify-write i.e. to change a single bit of the port, the
software reads the current value being driven across 32 bits, flips a bit and then
outputs the modified value.
XM0088546.1
USB Audio Design Guide 65/110
This method of port usage (i.e. sharing a port between cores) is outside the
standard XC usage model so is implemented using inline assembly as required.
The peek instruction is used to get the current output value on the port:
The required output value is then assembled using the relevant bit-wise operation(s)
before the out instruction is used directly to output data to the port:
/* Output to port */
asm ( " out res [%0] , %1 " :: " r " ( XS1_PORT_32A ) ," r " ( x ) ) ;
The table Figure 34 shows the signals connected to port 32A on the USB Audio
Class 2.0 reference design board. Note, they are all outputs from the XS1-L device.
6.1.2 Clocking
The board has two on-board oscillators for master clock generation. These produce
11.2896MHz for sample rates 44.1, 88.2, 176.4KHz etc and 24.567MHz for sample
rates 48, 96, 192kHz etc.
The required master clock is selected from one of these using an external mux cir-
cuit via port P32A[2] (pin 2 of port 32A). Setting P32A[2] high selects 11.2896MHz,
low selects 24.576MHz.
The reference design board uses a 24 bit, 192kHz stereo audio CODEC (Cirrus
Logic CS4270).
The CODEC has three internal modes depending on the sampling rate used. These
change the oversampling ratio used internally in the CODEC. The three modes are
shown below:
XM0088546.1
USB Audio Design Guide 66/110
BCLK
LR CLK Codec
L8A-64-TQ128 SDOUT
SDIN
CS427
0
MCLK
MCLK_SEL
The internal master clock dividers are set using the MDIV pins. MDIV is tied low
and MDIV2 is connected to bit 2 of port 32A (as well as to the master clock select).
With MDIV2 low, the master clock must be 256Fs in single-speed mode, 128Fs in
double-speed mode and 64Fs in quad-speed mode. This allows an 11.2896MHz
master clock to be used for sample rates of 44.1, 88.2 and 176.4kHz.
With MDIV2 high, the master clock must be 512Fs in single-speed mode, 256Fs
in double-speed mode and 128Fs in quad-speed mode. This allows a 24.576MHz
master clock to be used for sample rates of 48, 96 and 192kHz.
When changing sample frequency, the CodecConfig() function first puts the CODEC
into reset by setting P32A[1] low. It selects the required master clock/CODEC
dividers and keeps the CODEC in reset for 1ms to allow the clocks to stabilize. The
CODEC is brought out of reset by setting P32A[1] back high.
6.1.3 HID
XM0088546.1
USB Audio Design Guide 67/110
p_but_a : > a ;
p_but_b : > b ;
a = (~ a ) & 1;
b = (~ b ) & 1;
The reference design can be built in several ways by changing the build options.
These are described in usb_audio_sec_custom_defines_api.
The design has only been fully validated against the build options as set in the
application as distributed. See §5.3 for details and binary naming.
In practise, due to the similarities between the U-Series and L-Series feature set, it
is fully expected that all listed U-Series configurations will operate as expected on
the L-Series and vice versa.
This configuration runs in high-speed Audio Class 2.0 mode, has the mixer disabled,
supports 2 channels in, 2 channels out and supports sample rates up to 192kHz
and S/PDIF transmit.
XM0088546.1
USB Audio Design Guide 68/110
- DSPDIF_TX =0
and MIDI as 1:
- DMIDI =1
This configuration is similar to the first configuration apart from it runs in Audio
1.0 over full-speed USB.
- DAUDIO_CLASS =1
· Endpoint 0
· Endpoint buffer
· Decoupler
· Audio Driver
The software layout is the identical to the single tile L-Series Reference Design and
therefore the diagrams Figure 32 and Figure 33 show the software layout of the
code running on the XS1-U chip.
As with the L-Series, each unit runs in a single core concurrently with the others
units.
Due to the MIPS requirement of the USB driver (see §3.14), only six cores can be
run on the single tile L-Series device so only one of S/PDIF transmit or MIDI can be
supported.
XM0088546.1
USB Audio Design Guide 69/110
The actual hardware involved in the clock generation is somewhat different to the
single tile L-Series board. Instead of two separate oscillators and switching logic
a single oscillator with a Phaselink PLL is used to generate fixed 24.576MHz and
22.5792MHz master-clocks.
The advantages of this system are fewer components and a smaller board area.
When changing sample frequency, the CodecConfig() function first puts the CODEC
into reset by setting P4C[2] low. It selects the required master clock and keeps the
CODEC in reset for 1ms to allow the clocks to stabilize. The CODEC is brought out
of reset by setting P4C[2] back high.
The board is equipped with two stereo audio CODECs (Cirrus Logic CS4270) giving
4 channels of input and 4 channels of output. Configuration of these CODECs
takes place using I2C, with both sharing the same I2C bus. The design uses the
open source I2C component sc_i2c27
The codebase includes code exampling how the ADC built into the U-Series device
can be used. Once setup a pin is used to cause the ADC to sample, this sample is
then sent via a channel to the xCORE device.
On the DJ kit the ADC is clocked via the same pin as the I2S LR clock. Since this
means that a ADC sample is received every audio sample the ADC is setup and it’s
data received in the audio driver core (audio.xc).
The code simply writes the ADC value to the global variable g_adcVal for use
elsewhere in the program as required. The ADC code is enabled by defining
SU1_ADC_ENABLE as 1.
27 http://www.github.com/xcore/sc_i2c
XM0088546.1
USB Audio Design Guide 70/110
The Vendor_ReadHIDButtons() function simply looks at the value from the ADC,
if is near the maximum value it reports a volume up, near the minimum value a
volume down is reported. If the ADC value is mid-range no event is reported. The
code is shown below:
hidData [0] = 0;
# if defined ( AD C_ V OL _C O NT RO L ) && ( A DC _V O L_ CO N TR O L == 1)
adcVal = g_adcVal >> 20;
The reference design can be built in several ways by changing the build options.
These are described in usb_audio_sec_custom_defines_api.
The design has only been fully validated against the build options as set in the
application as distributed. See §5.3 for details and binary naming scheme.
These fully validated build configurations are listed below. In practise, due to the
similarities between the U-Series and L-Series feature set, it is fully expected that
all listed U-Series configurations will operate as expected on the L-Series and vice
versa.
This configuration runs in high-speed Audio Class 2.0 mode, has the mixer disabled,
supports 2 channels in, 2 channels out, supports sample rates up to 192kHz and
S/PDIF transmit.
XM0088546.1
USB Audio Design Guide 71/110
- DSPDIF_TX =0
and MIDI as 1:
- DMIDI =1
This configuration is similar to the first configuration apart from it runs in Audio
1.0 over full-speed USB.
- DAUDIO_CLASS =1
This configuration is similar to the configuration above in that it runs in Audio 1.0
over full-speed USB. However, the it is output only (i.e. the input path is disabled
with -DNUM_USB_CHAN_IN=0
· Endpoint 0
· Endpoint buffer
· Decoupler
XM0088546.1
USB Audio Design Guide 72/110
· Audio Driver
· Mixer
· S/PDIF Transmitter
· S/PDIF Receiver
· ADAT Receiver
· Clockgen
· MIDI
Figure 37 shows the software layout of the USB Audio 2.0 Multichannel Reference
Design.
tile[0]
tile[1]
Figure 37:
Dual Tile
L-Series
Reference
Design Core
Layout
XM0088546.1
USB Audio Design Guide 73/110
6.3.1 Clocking
For complete clocking flexibility the dual tile L-Series reference design drives a
reference clock to an external fractional-n clock multiplier IC (Cirrus Logic CS2300).
This in turn generates the master clock used over the design. This is described in
§3.10.
The reference design can be built in several ways by changing the option described
in usb_audio_sec_custom_defines_api. However, the design has only been validated
against the build options as set in the application as distributed with the following
four variations.
6.3.2.1 Configuration 1
All the #defines are set as per the distributed application. It has the mixer enabled,
supports 16 channels in, 10 channels out and supports sample rates up to 96kHz.
6.3.2.2 Configuration 2
The same as Configuration 1 but with the CODEC set as I2S master (and the XCORE
Tile as slave).
6.3.2.3 Configuration 3
# define NU M_ U SB _C H AN _I N (10)
# define I2S_CHANS_ADC (6)
# define SPD IF_RX_ INDEX (8)
XM0088546.1
USB Audio Design Guide 74/110
6.3.2.4 Configuration 4
The same as Configuration 3 but with the CODEC set as I2S master. This configura-
tion can be made by making the changes for Configuration 3 and commenting out
the following line in customdefines.h:
· Endpoint 0
· Endpoint buffer
· Decoupler
· Audio Driver
The software layout is the identical to the single tile L-Series Reference Design and
therefore the diagrams Figure 32 and Figure 33 show the software layout of the
code running on the XS1-U chip.
As with the L-Series, each unit runs in a single core concurrently with the others
units. The lines show the communication between each functional unit.
Due to the MIPS requirement of the USB driver (see §3.14), only six cores can be
run on the single tile L-Series device so only one of S/PDIF transmit or MIDI can be
supported.
A single oscillator with a Phaselink PLL is used to generate fixed 24.576MHz and
22.5792MHz master-clocks.
XM0088546.1
USB Audio Design Guide 75/110
When changing sample frequency, the AudioHwConfig() function first puts the
both the DAC and ADC into reset by setting P4C[0] and P4C[1] low. It selects the
required master clock and keeps both the DAC and ADC in reset for 1ms to allow
the clocks to stabilize. The DAC and ADC are brought out of reset by setting P4C[0]
and P4C[1] back high.
The board is equipped with a single stereo audio DAC (Cirrus Logic CS4392) and a
single stereo ADC (Cirrus Logic 5340) giving 2 channels of input and 2 channels of
output.
Configuration of the DAC takes place using I2C. The design uses the open source
I2C component sc_i2c28 No configuration of the ADC is required in software, it is
set into slave mode via its configuration pins on the board.
The codebase includes code exampling how the ADC built into the U-Series device
can be used. Once setup a pin is used to cause the ADC to sample, this sample is
then sent via a channel to the xCORE device.
On the multi-function audio board the ADC is clocked via the same pin as the I2S
LR clock. Since this means that a ADC sample is received every audio sample the
ADC is setup and it’s data received in the audio driver core (audio.xc).
The ADC inputs for the U8 device are simply pinned out to test point headers. As
such there is no example functionality attached to the ADC data.
The codebase includes an example of a HID controls implementation using the two
buttons and switch on the multi-function audio board.
This example code is enabled if HID_CONTROLS are all defined as 1. When this define
is enabled a call to the function Vendor_ReadHIDButtons() is enabled and must be
implemented. Failing to do so will result in a build error.
The example Vendor_ReadHIDButtons() firstly reads the state of the buttons and
switch. These inputs are all connected to the same 4-bit port. Since the buttons
are active low and the HID report is active high the value read is inverted. Some
bitwise operations are then used to exact the individual states of the buttons and
switch.
If the switch input is low (i.e. high when inverted) then the button states are shifted
up into the position required perform volume up and down and written into the
hidData[] array:
28 http://www.github.com/xcore/sc_i2c
XM0088546.1
USB Audio Design Guide 76/110
If the switch input is high (i.e. low when inverted) then the buttons states are
used to either indicate play/pause or next/previous. Based on counter and a small
state-machine a single click on either button provides a play/pause command. A
double tap on button A or B provides a previous or next command respectively.
XM0088546.1
USB Audio Design Guide 77/110
if ( sw )
{
/* Assign buttons A and B to Vol Up / Down */
hidData [0] = ( a << H I D _ C O N T R O L _ V O L U P _ S H I F T ) | ( b <<
> HID_CONTROL_VOLDN_SHIFT );
}
else
{
/* Assign buttons A and B to play for single tap , next / prev for
> double tap */
if ( b )
{
m u l t i c o n t r o l _ c o u n t ++;
wait_counter = 0;
lastA = 0;
}
else if ( a )
{
m u l t i c o n t r o l _ c o u n t ++;
wait_counter = 0;
lastA = 1;
}
else
{
if ( m u l t i c o n t r o l _ c o u n t > THRESH )
{
state ++;
}
wait_counter ++;
if ( wait_counter > M U LT I PR ES S _W AI T )
{
if ( state == STATE_PLAY )
{
hidData [0] = (1 << H I D _ C O N T R O L _ P L A Y P A U S E _ S H I F T )
> ;
}
else if ( state == STATE _NEXTP REV )
{
if ( lastA )
hidData [0] = (1 << H I D _ C O N T R O L _ P R E V _ S H I F T ) ;
else
hidData [0] = (1 << H I D _ C O N T R O L _ N E X T _ S H I F T ) ;
}
state = STATE_IDLE ;
}
m u l t i c o n t r o l _ c o u n t = 0;
XM0088546.1 }
}
}
USB Audio Design Guide 78/110
The reference design can be built in several ways by changing the build options.
These are described in §7.1.
The design has only been fully validated against the build options as set in the
application as distributed. See §5.3 for details and binary naming scheme.
These fully validated build configurations are listed below. In practise, due to the
similarities between the U-Series and L-Series feature set, it is fully expected that
all listed U-Series configurations will operate as expected on the L-Series and vice
versa.
This configuration runs in high-speed Audio Class 2.0 mode, has the mixer disabled,
supports 2 channels in, 2 channels out, supports sample rates up to 192kHz and
S/PDIF transmit.
- DSPDIF_TX =0
and MIDI as 1:
- DMIDI =1
This configuration is similar to the first configuration apart from it runs in Audio
1.0 over full-speed USB.
- DAUDIO_CLASS =1
XM0088546.1
USB Audio Design Guide 79/110
This configuration is similar to the configuration above in that it runs in Audio 1.0
over full-speed USB. However, the it is output only (i.e. the input path is disabled
with -DNUM_USB_CHAN_IN=0
The design supports 10 channels channels of audio input and output at sample
frequencies up to 192kHz and uses the following components:
· Endpoint 0
· Endpoint buffer
· Decoupler
· Audio Driver
· S/PDIF Transmitter
· MIDI
The software layout is the identical to the single tile L-Series Multi-channel Reference
Design and therefore the diagram Figure 37 shows the software arrangement of
the code running on the XS1-U chip.
As with the L-Series, each unit runs in a single core concurrently with the others
units. The lines show the communication between each functional unit.
The XA-SK-AUDIO8 double-slot slice includes two options for master clock genera-
tion:
· A Cirrus Logic CS2100 clock multiplier allowing the master clock to be generated
from a XCore derived reference.
XM0088546.1
USB Audio Design Guide 80/110
The master clock source is controlled by a mux which, in turn, is controlled by bit
1 of PORT 4D:
Figure 38:
Value Source
Master Clock
Source 0 Master clock is sourced from PhaseLink PLL
Selection 1 Master clock is source from Cirrus Clock Multiplier
The current version of the supplied application only supports the use of the fixed
master-clocks from the PhaseLink part.
The clock-select from the phaselink part is controlled via bit 2 of PORT 4E:
Figure 39:
Value Frequency
Master Clock
Frequency 0 24.576MHz
Select 1 22.579MHz
The board is equipped with a single multi-channel audio DAC (Cirrus Logic CS4384)
and a single multi-channel ADC (Cirrus Logic CS5368) giving 8 channels of analogue
output and 8 channels of analogue input.
Configuration of both the DAC and ADC takes place using I2C. The design uses
the I2C component sc_i2c29 .
The reset lines of the DAC and ADC are connected to bits 0 and 1 of PORT 4E
respectively.
6.5.3 AudioHwInit()
6.5.4 AudioHwConfig()
29 http://www.github.com/xcore/sc_i2c
XM0088546.1
USB Audio Design Guide 81/110
The AudioHwConfig() function first puts the both the DAC and ADC into reset by
setting P4E[0] and P4E[1] low. It then selects the required master clock and keeps
both the DAC and ADC in reset for a period in order allow the clocks to stabilize.
The DAC and ADC are brought out of reset by setting P4E[0] and P4E[1] back high.
Various registers are then written to the ADC and DAC as required.
The reference design can be built in several ways by changing the build options.
These are described in §7.1.
The design has only been fully validated against the build options as set in the
application as distributed. See §5.3 for details and binary naming scheme.
These fully validated build configurations are listed below. In practise, due to the
similarities between the U-Series and L-Series feature set, it is fully expected that
all listed U-Series configurations will operate as expected on the L-Series and vice
versa.
This configuration runs in high-speed Audio Class 2.0 mode, has the mixer core is
enabled (for volume processing only, supports 10 channels in, 10 channels out,
supports sample rates up to 192kHz and S/PDIF transmit.
· Endpoint 0
· Endpoint buffer
· Decoupler
· Audio Driver
XM0088546.1
USB Audio Design Guide 82/110
· S/PDIF Transmitter
· MIDI
The software layout is the identical to the dual tile L-Series Multi-channel Reference
Design and therefore the diagram Figure 37 shows the software arrangement of
the code running on the xCORE-200 device.
As with the L/U-Series, each unit runs in a single core concurrently with the others
units. The lines show the communication between each functional unit.
· A Cirrus Logic CS2100 clock multiplier allowing the master clock to be generated
from a XCore derived reference.
The master clock source is controlled by a mux which, in turn, is controlled by bit
5 of PORT 8C:
Figure 40:
Value Source
Master Clock
Source 0 Master clock is sourced from PhaseLink PLL
Selection 1 Master clock is source from Cirrus Clock Multiplier
The clock-select from the phaselink part is controlled via bit 7 of PORT 8C:
Figure 41:
Value Frequency
Master Clock
Frequency 0 24.576MHz
Select 1 22.579MHz
The board is equipped with a single multi-channel audio DAC (Cirrus Logic CS4384)
and a single multi-channel ADC (Cirrus Logic CS5368) giving 8 channels of analogue
output and 8 channels of analogue input.
Configuration of both the DAC and ADC takes place using I2C. The design uses
the I2C component sc_i2c30 .
The reset lines of the DAC and ADC are connected to bits 1 and 6 of PORT 8C
respectively.
30 http://www.github.com/xcore/sc_i2c
XM0088546.1
USB Audio Design Guide 83/110
6.6.3 AudioHwInit()
6.6.4 AudioHwConfig()
The AudioHwConfig() function first puts the both the DAC and ADC into reset by
setting P8C[1] and P8C[6] low. It then selects the required master clock and keeps
both the DAC and ADC in reset for a period in order allow the clocks to stabilize.
The DAC and ADC are brought out of reset by setting P8C[1] and P8C[6] back high.
Various registers are then written to the ADC and DAC as required.
XM0088546.1
USB Audio Design Guide 84/110
The reference design can be built in several ways by changing the build options.
These are described in §7.1.
The design has only been fully validated against the build options as set in the
application as distributed in the Makefile. See §5.3 for details and binary naming
scheme.
These fully validated build configurations are enumerated in the supplied Makefile
In practise, due to the similarities between the U/L/xCORE-200 Series feature set,
it is fully expected that all listed U-Series configurations will operate as expected
on the L-Series and vice versa.
Audio Class 1 2
Input enabled: i (channel count) disabled: x
Output enabled: i (channel count) disabled: x
MIDI enabled: m disabled: x
SPDIF output enabled: s disabled: x
Figure 42: SPDIF input enabled: s disabled: x
Build config ADAT output enabled: a disabled: x
naming ADAT input enabled: a disabled: x
scheme DSD output enabled: d disabled: x
e.g. A build config named 2i10o10xsxxx would signify: Audio class 2.0, input and
output enabled (10 channels each), no MIDI SPDIF output, no SPDIF input, no ADAT
or DSD
In addition to this the terms tdm or slave may be appended to the build configura-
tion name to indicate the I2S mode employed.
The design supports upto 2 channels of analogue audio output at sample-rates from
the on-board DAC. The design also supports input from the 7 PDM microphones.
· Endpoint 0
XM0088546.1
USB Audio Design Guide 85/110
· Endpoint buffer
· Decoupler
· Audio Driver
The software layout is the identical to the dual tile L-Series Multi-channel Reference
Design and therefore the diagram Figure 37 shows the software arrangement of
the code running on the xCORE-200 device.
As with the L/U-Series, each unit runs in a single core concurrently with the others
units. The lines show the communication between each functional unit.
The board includes an external fractional-N clock multiplier (Cirrus Logic CS2100)
for audio clock generation.
This allows the audio master clock to be generated from an reference clock provided
by the xCORE, optionally derived from some external source e.g. an incoming
digital steam.
This functionality is primarily included on the board to allow for Ethernet AVB,
where syncing to an external clock is required. In the USB audio design the IC is
simply used for static master clock generation.
The system wide audio master-clock is connected to the AUX output of the CS2100
part. By default, without configuration, the CS2100 part outputs the 24.576MHz
REF input to this output.
The clock multiply ratio is programmed into the CS2100 via the I2C bus.
By default a core is used to drive a fixed reference to the CS2100 part using a timer
and port I/O. Since this I/O is located on a 4-bit port it cannot be directly output
from a clock-block (which would save a core).
· Move the I/O to a 1-bit port and drive the clock directly from a clock-block
· Use a clocking methodology that does not require this REF signal as previously
explained, it is unlikely the clocking methodology would be employed in a
production environment if locking to an external clock is not required.
XM0088546.1
USB Audio Design Guide 86/110
The board is equipped with a single stereo audio DAC with integrated headphone
amplifier (Cirrus Logic CS43L21)
Configuration of both the DAC takes place using I2C. The design uses the I2C
component sc_i2c31 .
6.7.3 AudioHwInit()
· Configures the CS2100 part to output a ratio for a suitable initial master clock
frequency (DEFAULT_MCLK_FREQ)
6.7.4 AudioHwConfig()
The AudioHwConfig() function first puts the both the DAC/headphone-amp and
into reset by writing to PORT 4F.
It then sets the required ratio in the CS2100 via I2C based on the mClk parameter.
After a delay, in order to allow the master clock from the CS2100 to settle the DAC
is take out of reset. The DAC is then configured via I2C, this primarily involves
switching the DAC into I2S slave mode
The processing involves applying a simple gain globally to all of the microphones.
Normal operation sees this gain applied to the data from the 7 microphones and
then written to output[0-6]. The gain is increased and decreased by pressing
buttons B and C respectively.
31 http://www.github.com/xcore/sc_i2c
XM0088546.1
USB Audio Design Guide 87/110
The example also provides a simple summing example, where all 7 microphones
are summed into output[0] with the original microphone signals output to
output[1..7]. This functionality is enabled and disabled using Button A.
The reference design can be built in several ways by changing the build options.
These are described in §7.1.
The design has only been fully validated against the build options as set in the
application as distributed in the Makefile. See §5.3 for details and binary naming
schemes.
These fully validated build configurations are enumerated in the supplied Makefile
In practise, due to the similarities between the U/L/xCORE-200 Series feature set,
it is fully expected that all listed U-Series configurations will operate as expected
on the L-Series and vice versa.
e.g. A build config named 2i8o2 would signify: Audio class 2.0, input and output
enabled (8 in, 2 out).
XM0088546.1
7 API
IN THIS CHAPTER
· Configuration Defines
· Required User Function Definitions
· Component API
These defines should be over-ridden in the mandatory customdefines.h file or in Makefile for a
relevant build configuration.
This section fully documents all of the setable defines and their default values (where appropriate).
Macro AUDIO_IO_TILE
Description Location (tile) of audio I/O.
Default: 0
Macro XUD_TILE
Description Location (tile) of audio I/O.
Default: 0
Macro IAP_TILE
Description Location (tile) of IAP.
Default: AUDIO_IO_TILE
XM0088546.1
USB Audio Design Guide 89/110
Macro MIDI_TILE
Description Location (tile) of MIDI I/O.
Default: AUDIO_IO_TILE
Macro NUM_USB_CHAN_OUT
Description Number of output channels (host to device).
Default: NONE (Must be defined by app)
Macro NUM_USB_CHAN_IN
Description Number of input channels (device to host).
Default: NONE (Must be defined by app)
Macro DSD_CHANS_DAC
Description Number of DSD output channels.
Default: 0 (disabled)
Macro I2S_CHANS_DAC
Description Number of IS2 channesl to DAC/CODEC.
Must be a multiple of 2.
Default: NONE (Must be defined by app)
Macro I2S_CHANS_ADC
Description Number of I2S channels from ADC/CODEC.
Must be a multiple of 2.
Default: NONE (Must be defined by app)
XM0088546.1
USB Audio Design Guide 90/110
Macro MAX_FREQ
Description Max supported sample frequency for device (Hz).
Default: 192000
Macro MIN_FREQ
Description Min supported sample frequency for device (Hz).
Default 44100
Macro DEFAULT_FREQ
Description Default device sample frequency.
A safe default should be used. Default: MIN_FREQ
Macro MCLK_441
Description Master clock defines for 44100 rates (in Hz).
Default: NONE (Must be defined by app)
Macro MCLK_48
Description Master clock defines for 48000 rates (in Hz).
Default: NONE (Must be defined by app)
Macro AUDIO_CLASS
Description USB Audio Class Version.
Default: 2 (Audio Class version 2.0)
Macro AUDIO_CLASS_FALLBACK
Description Whether or not to fall back to Audio Class 1.0 in USB Full-speed.
Default: 0 (Disabled)
XM0088546.1
USB Audio Design Guide 91/110
Macro FULL_SPEED_AUDIO_2
Description Whether or not to run UAC2 in full-speed.
When disabled device can either operate in UAC1 mode in full-speed (if AU-
DIO_CLASS_FALLBACK enabled) or return “null” descriptors.
Default: 1 (Enabled) when AUDIO_CLASS_FALLBACK disabled.
7.1.5.1 MIDI
Macro MIDI
Description Enable MIDI functionality including buffering, descriptors etc.
Default: DISABLED
Macro MIDI_RX_PORT_WIDTH
Description MIDI Rx port width (1 or 4bit).
Default: 1
7.1.5.2 S/PDIF
Macro SPDIF_TX
Description Enables SPDIF Tx.
Default: 0 (Disabled)
Macro SPDIF_TX_INDEX
Description Defines which output channels (stereo) should be output on S/PDIF.
Note, Output channels indexed from 0.
Default: 0 (i.e. channels 0 & 1)
Macro SPDIF_RX
Description Enables SPDIF Rx.
Default: 0 (Disabled)
XM0088546.1
USB Audio Design Guide 92/110
Macro SPDIF_RX_INDEX
Description S/PDIF Rx first channel index, defines which channels S/PDIF will be input on.
Note, indexed from 0.
Default: NONE (Must be defined by app when SPDIF_RX enabled)
7.1.5.3 ADAT
Macro ADAT_RX
Description Enables ADAT Rx.
Default: 0 (Disabled)
Macro ADAT_RX_INDEX
Description ADAT Rx first channel index.
defines which channels ADAT will be input on. Note, indexed from 0.
Default: NONE (Must be defined by app when ADAT_RX enabled)
Macro NUM_PDM_MICS
Description Number of PDM microphones in the design.
Default: None
7.1.5.5 DFU
Macro DFU
Description Enable DFU functionality.
A driver required for Windows operation.
Default: 1 (Enabled)
7.1.5.6 HID
XM0088546.1
USB Audio Design Guide 93/110
Macro HID_CONTROLS
Description Enable HID playback controls functionality.
1 for enabled, 0 for disabled.
Default 0 (Disabled)
Macro CODEC_MASTER
Description
Macro VENDOR_STR
Description Vendor String used by the device.
This is also pre-pended to various strings used by the design.
Default: “XMOS”
Macro VENDOR_ID
Description USB Vendor ID (or VID) as assigned by the USB-IF.
Default: 0x20B1 (XMOS)
Macro PRODUCT_STR
Description USB Product String for the device.
If defined will be used for both PRODUCT_STR_A2 and PRODUCT_STR_A1
Default: Undefined
Macro PRODUCT_STR_A2
Description Product string for Audio Class 2.0 mode.
Default: “xCore USB Audio 2.0”
XM0088546.1
USB Audio Design Guide 94/110
Macro PRODUCT_STR_A1
Description Product string for Audio Class 1.0 mode.
Default: “xCore USB Audio 1.0”
Macro PID_AUDIO_1
Description USB Product ID (PID) for Audio Class 1.0 mode.
Only required if AUDIO_CLASS == 1 or AUDIO_CLASS_FALLBACK is enabled.
Default: 0x0003
Macro PID_AUDIO_2
Description USB Product ID (PID) for Audio Class 2.0 mode.
Default: 0x0002
Macro BCD_DEVICE
Description Device firmware version number in Binary Coded Decimal format: 0xJJMN where
JJ: major, M: minor, N: sub-minor version number.
NOTE: User code should not modify this but should modify BCD_DEVICE_J,
BCD_DEVICE_M, BCD_DEVICE_N instead
Default: XMOS USB Audio Release version (e.g. 0x0651 for 6.5.1).
7.1.7.1 Output/Playback
Macro OUTPUT_FORMAT_COUNT
Description Number of supported output stream formats.
Values 1,2,3 supported
Default: 2
Macro STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS
Continued on next page
XM0088546.1
USB Audio Design Guide 95/110
Macro STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS
Description Sample resolution (bits) of output stream Alternate 2.
Default: 16 if Alternate 2 is PCM, else 32 if DSD/RAW
Macro STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS
Description Sample resolution (bits) of output stream Alternate 3.
Default: 32 if Alternate 2 is PCM, else 32 if DSD/RAW
Macro HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES
Description Sample sub-slot size (bytes) of output stream Alternate 1 when running in
high-speed.
Default: 4 if resolution for Alternate 1 is 24bits, else resolution / 8
Note, the default catchs the 24bit special case where 4-byte subslot is nicer
for our 32-bit machine. Typically do not care about this extra bus overhead at
High-speed
Macro HS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES
Description Sample sub-slot size (bytes) of output stream Alternate 2 when running in
high-speed.
Default: 4 if resolution for Alternate 2 is 24bits, else resolution / 8
Note, the default catchs the 24bit special case where 4-byte subslot is nicer
for our 32-bit machine. Typically do not care about this extra bus overhead at
High-speed
Macro HS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES
Continued on next page
XM0088546.1
USB Audio Design Guide 96/110
Description Sample sub-slot size (bytes) of output stream Alternate 3 when running in
high-speed.
Default: 4 if resolution for Alternate 3 is 24bits, else resolution / 8
Note, the default catchs the 24bit special case where 4-byte subslot is nicer
for our 32-bit machine. Typically do not care about this extra bus overhead at
High-speed
Macro FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES
Description Sample sub-slot size (bytes) of output stream Alternate 1 when running in
full-speed.
Note, in full-speed mode bus bandwidth is at a premium, therefore pack samples
into smallest possible sub-slot.
Default: STREAM_FORMAT_OUTPUT_1_RESOLUTION_BITS / 8
Macro FS_STREAM_FORMAT_OUTPUT_2_SUBSLOT_BYTES
Description Sample sub-slot size (bytes) of output stream Alternate 2 when running in
full-speed.
Note, in full-speed mode bus bandwidth is at a premium, therefore pack samples
into smallest possible sub-slot.
Default: STREAM_FORMAT_OUTPUT_2_RESOLUTION_BITS / 8
Macro FS_STREAM_FORMAT_OUTPUT_3_SUBSLOT_BYTES
Description Sample sub-slot size (bytes) of output stream Alternate 3 when running in
full-speed.
Note, in full-speed mode bus bandwidth is at a premium, therefore pack samples
into smallest possible sub-slot.
Default: STREAM_FORMAT_OUTPUT_3_RESOLUTION_BITS / 8
Macro STREAM_FORMAT_OUTPUT_1_DATAFORMAT
Description Sample audio data-format if output stream Alternate 1.
Default: UAC_FORMAT_TYPEI_RAW_DATA when Alternate 1 is RAW/DSD else
UAC_FORMAT_TYPEI_PCM
XM0088546.1
USB Audio Design Guide 97/110
Macro STREAM_FORMAT_OUTPUT_2_DATAFORMAT
Description Sample audio data-format if output stream Alternate 2.
Default: UAC_FORMAT_TYPEI_RAW_DATA when Alternate 2 is RAW/DSD else
UAC_FORMAT_TYPEI_PCM
Macro STREAM_FORMAT_OUTPUT_3_DATAFORMAT
Description Sample audio data-format if output stream Alternate 3.
Default: UAC_FORMAT_TYPEI_RAW_DATA when Alternate 3 is RAW/DSD else
UAC_FORMAT_TYPEI_PCM
7.1.7.2 Input/Recording
Macro INPUT_FORMAT_COUNT
Description Number of supported input stream formats.
Default: 1
Macro STREAM_FORMAT_INPUT_1_RESOLUTION_BITS
Description Sample resolution (bits) of input stream Alternate 1.
Default: 24
Macro HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES
Description Sample sub-slot size (bytes) of input stream Alternate 1 when running in high-
speed.
Default: 4 if resolution for Alternate 1 is 24bits, else resolution / 8
Note, the default catchs the 24bit special case where 4-byte subslot is nicer
for our 32-bit machine. Typically do not care about this extra bus overhead at
High-speed
Macro FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES
Continued on next page
XM0088546.1
USB Audio Design Guide 98/110
Description Sample sub-slot size (bytes) of input stream Alternate 1 when running in full-
speed.
Note, in full-speed mode bus bandwidth is at a premium, therefore pack samples
into smallest possible sub-slot.
Default: STREAM_FORMAT_INPUT_1_RESOLUTION_BITS / 8
Macro STREAM_FORMAT_INPUT_1_DATAFORMAT
Description Sample audio data-format for input stream Alternate 1.
Default: UAC_FORMAT_TYPEI_PCM
Macro OUTPUT_VOLUME_CONTROL
Description Enable/disable output volume control including all processing and descriptor
support.
Default: 1 (Enabled)
Macro INPUT_VOLUME_CONTROL
Description Enable/disable input volume control including all processing and descriptor
support.
Default: 1 (Enabled)
Macro MIN_VOLUME
Description The minimum volume setting above -inf.
This is a signed 8.8 fixed point number that must be strictly greater than -128
(0x8000)
Default: 0x8100 (-127db)
Macro MAX_VOLUME
Description The maximum volume setting.
This is a signed 8.8 fixed point number.
Default: 0x0000 (0db)
XM0088546.1
USB Audio Design Guide 99/110
Macro VOLUME_RES
Description The resolution of the volume control in db as a 8.8 fixed point number.
Default: 0x100 (1db)
Macro MIXER
Description Enable “mixer” core.
Default: 0 (Disabled)
Macro MAX_MIX_COUNT
Description Number of seperate mixes to perform.
Default: 8 if MIXER enabled, else 0
Macro MIX_INPUTS
Description Number of channels input into the mixer.
Note, total number of mixer nodes is MIX_INPUTS * MAX_MIX_COUNT
Default: 18
Macro MIN_MIXER_VOLUME
Description The minimum volume setting for the mixer unit above -inf.
This is a signed 8.8 fixed point number that must be strictly greater than -128
(0x8000)
Default: 0x8100 (-127db)
Macro MAX_MIXER_VOLUME
Description The maximum volume setting for the mixer.
This is a signed 8.8 fixed point number.
Default: 0x0000 (0db)
XM0088546.1
USB Audio Design Guide 100/110
Macro VOLUME_RES_MIXER
Description The resolution of the volume control in db as a 8.8 fixed point number.
Default: 0x100 (1db)
7.1.10 Power
Macro SELF_POWERED
Description Report as self to the host when enabled, else reports as bus-powered.
This affects descriptors and XUD usage.
Default: 0 (Disabled)
Macro BMAX_POWER
Description Power drawn from the host (in mA x 2).
Default: 0 when SELF_POWERED enabled else 250 (500mA)
Function AudioHwInit
Description This function is called when the audio core starts after the device boots up and
should initialize the external audio harware e.g. clocking, DAC, ADC etc
Parameters c_codec An optional chanend that was original passed into audio() that
can be used to communicate with other cores.
Function AudioHwConfig
Description This function is called when the audio core starts or changes sample rate. It
should configure the extenal audio hardware to run at the specified sample rate
given the supplied master clock frequency.
XM0088546.1
USB Audio Design Guide 101/110
Parameters samFreq The sample frequency in Hz that the hardware should be config-
ured to (in Hz).
c_codec An optional chanend that was original passed into audio() that
can be used to communicate with other cores.
The following functions can be optionally used by the design. They can be useful for mute lines
etc.
Function AudioStreamStart
Description This function is called when the audio stream from device to host starts.
Function AudioStreamStop
Description This function is called when the audio stream from device to host stops.
The following function can be used to signal that the device is connected to a valid host.
XM0088546.1
USB Audio Design Guide 102/110
Function AudioStreamStart
Description
Type void AudioStreamStart(int active)
Parameters active Indicates if the host is active or not. 1 for active else 0.
The following function is called when the device wishes to read physical user input (buttons etc).
Function UserReadHIDButtons
Description
Type void
UserReadHIDButtons(unsigned char hidData[])
Parameters hidData The function should write relevant HID bits into this array. The
bit ordering and functionality is defined by the HID report de-
scriptor used.
Function XUD_Manager
Description This performs the low-level USB I/O operations.
Note that this needs to run in a thread with at least 80 MIPS worst case execution
speed.
XM0088546.1
USB Audio Design Guide 103/110
XM0088546.1
USB Audio Design Guide 104/110
Parameters c_epOut An array of channel ends, one channel end per output endpoint
(USB OUT transaction); this includes a channel to obtain requests
on Endpoint 0.
c_epIn An array of channel ends, one channel end per input endpoint
(USB IN transaction); this includes a channel to respond to re-
quests on Endpoint 0.
epTypeTableOut
See epTypeTableIn.
epTypeTableIn
This and epTypeTableOut are two arrays indicating the type of
the endpoint. Legal types include: XUD_EPTYPE_CTL (Endpoint 0),
XUD_EPTYPE_BUL (Bulk endpoint), XUD_EPTYPE_ISO (Isochronous
endpoint), XUD_EPTYPE_INT (Interrupt endpoint), XUD_EPTYPE_DIS
(Endpoint not used). The first array contains the endpoint types
for each of the OUT endpoints, the second array contains the
endpoint types for each of the IN endpoints.
p_usb_rst The port to used to connect to an external phy reset line. Should
be null for U-Series.
clk The clock block to use for the p_usb_rst port - this should not
be clock block 0. Should be null for U-Series.
rstMask The mask to use when taking an external phy into/out of reset.
The mask is ORed into the port to disable reset, and unset when
deasserting reset. Use ‘-1’ as a default mask if this port is not
shared.
desiredSpeed
This parameter specifies what speed the device will attempt
to run at i.e. full-speed (ie 12Mbps) or high-speed (480Mbps)
if supported by the host. Pass XUD_SPEED_HS if high-speed is
desired or XUD_SPEED_FS if not. Low speed USB is not supported
by XUD.
When using the USB audio framework the c_ep_in array is always composed in the following order:
· Endpoint 0 (in)
· Endpoint 0 (out)
Function Endpoint0
Description Function implementing Endpoint 0 for enumeration, control and configuration
of USB audio devices.
It uses the descriptors defined in descriptors_2.h.
XM0088546.1
USB Audio Design Guide 106/110
c_EANativeTransport_ctrl
Optional chanend to be connected to EA Native endpoint man-
ager if present
Function buffer
Description USB Audio Buffering Thread.
This function buffers USB audio data between the XUD layer and the decouple
thread. Most of the chanend parameters to the function should be connected
to XUD_Manager()
XM0088546.1
USB Audio Design Guide 107/110
c_midi_from_host
MIDI OUT endpoint channel connected to the XUD
c_midi_to_host
MIDI IN endpoint channel connected to the XUD
p_off_mclk A port that is clocked of the MCLK input (not the MCLK input
itself)
Function decouple
Description Manage the data transfer between the USB audio buffer and the Audio I/O
driver.
Function mixer
Description Digital sample mixer.
This thread mixes audio streams between the decouple() thread and the audio()
thread.
XM0088546.1
USB Audio Design Guide 108/110
Function audio
Description The audio driver thread.
This function drives I2S ports and handles samples to/from other digital I/O
threads.
Parameters c_in Audio sample channel connected to the mixer() thread or the
decouple() thread
Function clockGen
Description Clock generation and digital audio I/O handling.
Type void
clockGen(streaming chanend ?c_spdif_rx,
chanend ?c_adat_rx,
out port p,
chanend c_audio,
chanend c_clk_ctl,
chanend c_clk_int)
XM0088546.1
USB Audio Design Guide 109/110
Function SpdifReceive
Description S/PDIF receive function.
This function needs 1 thread and no memory other than ~2800 bytes of program
code. It can do 11025, 12000, 22050, 24000, 44100, 48000, 88200, 96000,
and 192000 Hz. When the decoder encounters a long series of zeros it will
lower the divider; when it encounters a short series of 0-1 transitions it will
increase the divider.
Output: the received 24-bit sample values are output as a word on the streaming
channel end. Each value is shifted up by 4-bits with the bottom four bits
being one of FRAME_X, FRAME_Y, or FRAME_Z. The bottom four bits should be
removed whereupon the sample value should be sign extended.
The function does not return unless compiled with TEST defined in which case
it returns any time that it loses synchronisation.
Parameters p S/PDIF input port. This port must be 4-bit buffered, declared as
in buffered port:4
initial_divider
initial divide for initial estimate of sample rate For a 100Mhz
reference clock, use an initial divider of 1 for 192000, 2 for
96000/88200, and 4 for 48000/44100.
clk clock block sourced from the 100 MHz reference clock.
XM0088546.1
USB Audio Design Guide 110/110
Function adatReceiver48000
Description ADAT Receive Thread (48kHz sample rate).
When a data rame is received, samples will be output onto the streaming
channel At first a word 0x000000Z1 will be output, where Z are the user data;
after that eight words 0x0ZZZZZZ0 will be output where ZZZZZZ is a 24-bit
sample value. The eight words may refer to sample values on eight channels,
or on fewer channels if muxing is used.
The function will return if it cannot lock onto a 48,000 Hz signal. Normally the
48000 function is called in a while(1) loop. If both 44,100 and 48,000 need to
be supported, they should be called in sequence in a while(1) loop. Note that
the functions are large, and that 44,100 should not be called if 44.1 KHz does
not need to be supported.
Type void
adatReceiver48000(buffered in port:32 p, chanend oChan)
Function adatReceiver44100
Description ADAT Receive Thread (44.1kHz sample rate).
When a data rame is received, samples will be output onto the streaming
channel At first a word 0x000000Z1 will be output, where Z are the user data;
after that eight words 0x0ZZZZZZ0 will be output where ZZZZZZ is a 24-bit
sample value. The eight words may refer to sample values on eight channels,
or on fewer channels if muxing is used.
The function will return if it cannot lock onto a 44,100 Hz signal. Normally the
44,100 function is called in a while(1) loop. If both 44,100 and 48,000 need to
be supported, they should be called in sequence in a while(1) loop. Note that
the functions are large, and that 48,000 should not be called if 48 Khz does
not need to be supported.
Type void
adatReceiver44100(buffered in port:32 p, chanend oChan)
XM0088546.1
USB Audio Design Guide 111/110
Function usb_midi
Description USB MIDI I/O thread.
This function passes MIDI data from USB to UART I/O.
Type void
usb_midi(buffered in port:1 ?p_midi_in,
port ?p_midi_out,
clock ?clk_midi,
chanend ?c_midi,
unsigned cable_number,
chanend ?c_iap,
chanend ?c_i2c,
port ?p_scl,
port ?p_sda)
clk_midi clock block used for clockin the UART; should have a rate of
100MHz
cable_number
the cable number of the MIDI implementation. This should be
set to 0.
XM0088546.1
USB Audio Design Guide 112/110
Why does the USBView tool from Microsoft show errors in the devices descrip-
tors?
Xmos Ltd. is the owner or licensee of this design, code, or Information (collectively, the “Information”) and
is providing it to you “AS IS” with no warranty of any kind, express or implied and shall have no liability in
relation to its use. Xmos Ltd. makes no representation that the Information, or any particular implementation
thereof, is or will be free from any claims of infringement and again, shall have no liability in relation to any
such claims.
XMOS and the XMOS logo are registered trademarks of Xmos Ltd. in the United Kingdom and other countries,
and may not be used without written permission. All other trademarks are property of their respective owners.
Where those designations appear in this book, and XMOS was aware of a trademark claim, the designations
have been printed with initial capital letters or in all capitals.
XM0088546.1