forked from PAWPAW-Mirror/lib_xua
Add simple test app for I2S loopback (no USB)
This commit is contained in:
20
examples/app_i2s_loopback_xvf3510/Makefile
Normal file
20
examples/app_i2s_loopback_xvf3510/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
APP_NAME = app_xua_i2s_loopback
|
||||
|
||||
TARGET = XK_XVF3510_L71.xn
|
||||
|
||||
# The flags passed to xcc when building the application
|
||||
XCC_FLAGS = -Os -report -save-temps -g -Wno-unused-function -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[1]
|
||||
|
||||
# The USED_MODULES variable lists other module used by the application. These
|
||||
# modules will extend the SOURCE_DIRS, INCLUDE_DIRS and LIB_DIRS variables.
|
||||
# Modules are expected to be in the directory above the BASE_DIR directory.
|
||||
USED_MODULES = lib_xua lib_xud lib_i2c
|
||||
|
||||
|
||||
#=============================================================================
|
||||
# The following part of the Makefile includes the common build infrastructure
|
||||
# for compiling XMOS applications. You should not need to edit below here.
|
||||
|
||||
XMOS_MAKE_PATH ?= ../..
|
||||
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
|
||||
|
||||
111
examples/app_i2s_loopback_xvf3510/XK_XVF3510_L71.xn
Normal file
111
examples/app_i2s_loopback_xvf3510/XK_XVF3510_L71.xn
Normal file
@@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Network xmlns="http://www.xmos.com"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.xmos.com http://www.xmos.com">
|
||||
<Type>Device</Type>
|
||||
<Name>XVF3510 Device</Name>
|
||||
|
||||
<Declarations>
|
||||
<Declaration>tileref tile[2]</Declaration>
|
||||
<Declaration>tileref usb_tile</Declaration>
|
||||
</Declarations>
|
||||
|
||||
<Packages>
|
||||
<Package id="0" Type="XS2-UFnA-512-FB236">
|
||||
<Nodes>
|
||||
<Node Id="0" InPackageId="0" Type="XS2-L16A-512" SystemFrequency="500MHz" OscillatorSrc="1">
|
||||
<Boot>
|
||||
<Source Location="bootFlash0"/>
|
||||
</Boot>
|
||||
<Tile Number="0" Reference="tile[0]">
|
||||
<Port Location="XS1_PORT_1B" Name="PORT_SQI_CS_0"/>
|
||||
<Port Location="XS1_PORT_1C" Name="PORT_SQI_SCLK_0"/>
|
||||
<Port Location="XS1_PORT_4B" Name="PORT_SQI_SIO_0"/>
|
||||
|
||||
<!-- Mic related ports -->
|
||||
<Port Location="XS1_PORT_1L" Name="PORT_PDM_CLK"/>
|
||||
<Port Location="XS1_PORT_4D" Name="PORT_MUTE"/>
|
||||
<Port Location="XS1_PORT_4E" Name="PORT_PDM_DATA"/>
|
||||
<Port Location="XS1_PORT_1K" Name="PORT_PDM_MCLK"/>
|
||||
|
||||
<!-- Audio Ports -->
|
||||
<Port Location="XS1_PORT_1O" Name="PORT_I2S_LRCLK"/>
|
||||
<Port Location="XS1_PORT_1P" Name="PORT_I2S_BCLK"/>
|
||||
<Port Location="XS1_PORT_1N" Name="I2S_DATA_IN"/>
|
||||
|
||||
<!-- connected to DAC -->
|
||||
<Port Location="XS1_PORT_4F" Name="PORT_I2C"/>
|
||||
<Port Location="XS1_PORT_1M" Name="I2S_MIC_DATA"/>
|
||||
|
||||
|
||||
</Tile>
|
||||
<Tile Number="1" Reference="tile[1]">
|
||||
|
||||
<!-- I2C slave -->
|
||||
<Port Location="XS1_PORT_1D" Name="PORT_I2C_SDA"/>
|
||||
<Port Location="XS1_PORT_1C" Name="PORT_I2C_SCL"/>
|
||||
|
||||
|
||||
<Port Location="XS1_PORT_1A" Name="PORT_MCLK_TILE1"/>
|
||||
<Port Location="XS1_PORT_16B" Name="PORT_MCLK_COUNT"/>
|
||||
|
||||
|
||||
</Tile>
|
||||
|
||||
</Node>
|
||||
<Node Id="1" InPackageId="1" Type="periph:XS1-SU" Reference="usb_tile" Oscillator="24MHz">
|
||||
</Node>
|
||||
</Nodes>
|
||||
<Links>
|
||||
<Link Encoding="5wire">
|
||||
<LinkEndpoint NodeId="0" Link="8" Delays="52clk,52clk"/>
|
||||
<LinkEndpoint NodeId="1" Link="XL0" Delays="1clk,1clk"/>
|
||||
</Link>
|
||||
</Links>
|
||||
</Package>
|
||||
</Packages>
|
||||
|
||||
<Nodes>
|
||||
<Node Id="3" Type="device:" RoutingId="0x8000">
|
||||
<Service Id="0" Proto="xscope_host_data(chanend c);">
|
||||
<Chanend Identifier="c" end="3"/>
|
||||
</Service>
|
||||
</Node>
|
||||
</Nodes>
|
||||
|
||||
<Links>
|
||||
<Link Encoding="2wire" Delays="4,4" Flags="XSCOPE">
|
||||
<LinkEndpoint NodeId="0" Link="XL0"/>
|
||||
<LinkEndpoint NodeId="3" Chanend="1"/>
|
||||
</Link>
|
||||
</Links>
|
||||
|
||||
<ExternalDevices>
|
||||
<Device NodeId="0" Tile="0" Class="SQIFlash" Name="bootFlash0">
|
||||
<Attribute Name="PORT_SQI_CS" Value="PORT_SQI_CS_0"/>
|
||||
<Attribute Name="PORT_SQI_SCLK" Value="PORT_SQI_SCLK_0"/>
|
||||
<Attribute Name="PORT_SQI_SIO" Value="PORT_SQI_SIO_0"/>
|
||||
</Device>
|
||||
</ExternalDevices>
|
||||
|
||||
<JTAGChain>
|
||||
<JTAGDevice NodeId="0"/>
|
||||
</JTAGChain>
|
||||
|
||||
</Network>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
103
examples/app_i2s_loopback_xvf3510/app_i2s_loopback.xc
Normal file
103
examples/app_i2s_loopback_xvf3510/app_i2s_loopback.xc
Normal file
@@ -0,0 +1,103 @@
|
||||
|
||||
/* A very simple *example* of I2S loopback (analog in to analog out)
|
||||
* using the I2S module built into lib_xua (usb audio library)
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
#include <xscope.h>
|
||||
|
||||
#include "xua_commands.h"
|
||||
#include "xua.h"
|
||||
|
||||
/* Port declarations. Note, the defines come from the xn file */
|
||||
buffered out port:32 p_i2s_dac[] = {I2S_MIC_DATA}; /* I2S Data-line(s) */
|
||||
buffered in port:32 p_i2s_adc[] = {I2S_DATA_IN}; /* I2S Data-line(s) */
|
||||
|
||||
#if defined(CODEC_MASTER) && (CODEC_MASTER != 0)
|
||||
on tile[AUDIO_IO_TILE] : buffered in port:32 p_lrclk = PORT_I2S_LRCLK;
|
||||
on tile[AUDIO_IO_TILE] : buffered in port:32 p_bclk = PORT_I2S_BCLK;
|
||||
#else
|
||||
on tile[AUDIO_IO_TILE] : buffered out port:32 p_lrclk = PORT_I2S_LRCLK;
|
||||
on tile[AUDIO_IO_TILE] : buffered out port:32 p_bclk = PORT_I2S_BCLK;
|
||||
#endif
|
||||
|
||||
|
||||
/* Port declarations. Note, the defines come from the xn file */
|
||||
/* Master clock for the audio IO tile */
|
||||
//on tile[1]: in port p_mclk_in_tile1 = PORT_MCLK_TILE1;
|
||||
on tile[0]: in port p_mclk_in = PORT_PDM_MCLK;
|
||||
|
||||
|
||||
/* Resources for USB feedback */
|
||||
in port p_for_mclk_count = PORT_MCLK_COUNT; /* Extra port for counting master clock ticks */
|
||||
|
||||
/* Clock-block declarations */
|
||||
clock clk_audio_bclk = on tile[0]: XS1_CLKBLK_3; /* Bit clock */
|
||||
clock clk_audio_mclk = on tile[0]: XS1_CLKBLK_2; /* Master clock */
|
||||
//clock clk_audio_mclk_usb = on tile[1]: XS1_CLKBLK_1; /* Master clock for USB tile */
|
||||
|
||||
|
||||
|
||||
on tile[0] : clock mclk_internal = XS1_CLKBLK_5;
|
||||
|
||||
void set_node_pll_reg(tileref tile_ref, unsigned reg_val){
|
||||
write_sswitch_reg(get_tile_id(tile_ref), XS1_SSWITCH_PLL_CTL_NUM, reg_val);
|
||||
}
|
||||
|
||||
void run_clock(void) {
|
||||
configure_clock_xcore(mclk_internal, 10); // 24.576 MHz
|
||||
configure_port_clock_output(p_mclk_in, mclk_internal);
|
||||
start_clock(mclk_internal);
|
||||
}
|
||||
|
||||
// Nominal setting is ref div = 25, fb_div = 1024, op_div = 2
|
||||
// PCF Freq 0.96MHz
|
||||
|
||||
#define PLL_NOM 0xC003FF18 // This is 3.072MHz
|
||||
|
||||
void set_pll(void) {
|
||||
set_node_pll_reg(tile[0], PLL_NOM);
|
||||
run_clock();
|
||||
}
|
||||
|
||||
void loopback(chanend c_i2s)
|
||||
{
|
||||
int samps[NUM_USB_CHAN_OUT] = {0};
|
||||
int sampFreq = FREQ;
|
||||
|
||||
/* This block is the protocol for sample rate change */
|
||||
inuint(c_i2s);
|
||||
outct(c_i2s, SET_SAMPLE_FREQ);
|
||||
outuint(c_i2s, sampFreq);
|
||||
chkct(c_i2s, XS1_CT_END);
|
||||
|
||||
while(1)
|
||||
{
|
||||
inuint(c_i2s);
|
||||
for (int i=0; i<NUM_USB_CHAN_OUT; i++) outuint(c_i2s, samps[i]);
|
||||
for (int i=0; i<NUM_USB_CHAN_IN; i++) samps[i] = inuint(c_i2s);
|
||||
|
||||
xscope_int(0, samps[0]);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
chan c_i2s;
|
||||
|
||||
par {
|
||||
on tile[0]: {
|
||||
if (CODEC_MASTER == 0) set_pll();
|
||||
par {
|
||||
XUA_AudioHub(c_i2s, clk_audio_mclk, clk_audio_bclk, p_mclk_in, p_lrclk, p_bclk, p_i2s_dac, p_i2s_adc); //I2S
|
||||
loopback(c_i2s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
22
examples/app_i2s_loopback_xvf3510/config.xscope
Normal file
22
examples/app_i2s_loopback_xvf3510/config.xscope
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- ======================================================= -->
|
||||
<!-- The 'ioMode' attribute on the xSCOPEconfig -->
|
||||
<!-- element can take the following values: -->
|
||||
<!-- "none", "basic", "timed" -->
|
||||
<!-- -->
|
||||
<!-- The 'type' attribute on Probe -->
|
||||
<!-- elements can take the following values: -->
|
||||
<!-- "STARTSTOP", "CONTINUOUS", "DISCRETE", "STATEMACHINE" -->
|
||||
<!-- -->
|
||||
<!-- The 'datatype' attribute on Probe -->
|
||||
<!-- elements can take the following values: -->
|
||||
<!-- "NONE", "UINT", "INT", "FLOAT" -->
|
||||
<!-- ======================================================= -->
|
||||
|
||||
<xSCOPEconfig ioMode="basic" enabled="true">
|
||||
<!-- For example: -->
|
||||
<!-- <Probe name="Probe Name" type="CONTINUOUS" datatype="UINT" units="Value" enabled="true"/> -->
|
||||
<Probe name="ch0" type="CONTINUOUS" datatype="INT" units="Value" enabled="true"/>
|
||||
<!-- From the target code, call: xscope_int(PROBE_NAME, value); -->
|
||||
</xSCOPEconfig>
|
||||
19
examples/app_i2s_loopback_xvf3510/hwsupport.xc
Normal file
19
examples/app_i2s_loopback_xvf3510/hwsupport.xc
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <xs1.h>
|
||||
#include <platform.h>
|
||||
#include <xs1_su.h>
|
||||
#include "i2c.h"
|
||||
#include "dsd_support.h"
|
||||
#include "debug_print.h"
|
||||
#include "xassert.h"
|
||||
|
||||
|
||||
void AudioHwInit()
|
||||
{
|
||||
}
|
||||
//:
|
||||
|
||||
void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode,
|
||||
unsigned samRes_DAC, unsigned samRes_ADC)
|
||||
{
|
||||
}
|
||||
//:
|
||||
37
examples/app_i2s_loopback_xvf3510/xua_conf.h
Normal file
37
examples/app_i2s_loopback_xvf3510/xua_conf.h
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#define NUM_USB_CHAN_OUT 2
|
||||
#define NUM_USB_CHAN_IN 2
|
||||
#define I2S_CHANS_DAC 2
|
||||
#define I2S_CHANS_ADC 2
|
||||
#define MCLK_441 (512 * 44100)
|
||||
#define MCLK_48 (512 * 48000)
|
||||
#define FREQ 48000
|
||||
#define MIN_FREQ FREQ
|
||||
#define MAX_FREQ FREQ
|
||||
|
||||
#define EXCLUDE_USB_AUDIO_MAIN
|
||||
#define NUM_PDM_MICS 0
|
||||
#define XUD_TILE 1
|
||||
#define AUDIO_IO_TILE 0
|
||||
#define MIXER 0
|
||||
#define XUA_USB_EN 0
|
||||
|
||||
#define SPDIF_TX_INDEX 0
|
||||
#define VENDOR_STR "XMOS"
|
||||
#define VENDOR_ID 0x20B1
|
||||
#define PRODUCT_STR_A2 "XUA Example"
|
||||
#define PRODUCT_STR_A1 "XUA Example"
|
||||
#define PID_AUDIO_1 1
|
||||
#define PID_AUDIO_2 2
|
||||
#define AUDIO_CLASS 2
|
||||
#define AUDIO_CLASS_FALLBACK 0
|
||||
#define BCD_DEVICE 0x1234
|
||||
#define XUA_DFU_EN 0
|
||||
|
||||
#define N_BITS_I2S 32
|
||||
#define AUD_TO_USB_RATIO 1
|
||||
#define CODEC_MASTER 0
|
||||
|
||||
|
||||
/* TODO */
|
||||
#define XUA_DFU XUA_DFU_EN
|
||||
Reference in New Issue
Block a user