From 8f9828ea2cc590e31dd799c0f322bba3ec9d7aa8 Mon Sep 17 00:00:00 2001 From: Ed Clarke Date: Tue, 30 Apr 2019 18:07:15 +0100 Subject: [PATCH] Add simple test app for I2S loopback (no USB) --- examples/app_i2s_loopback_xvf3510/Makefile | 20 ++++ .../XK_XVF3510_L71.xn | 111 ++++++++++++++++++ .../app_i2s_loopback.xc | 103 ++++++++++++++++ .../app_i2s_loopback_xvf3510/config.xscope | 22 ++++ .../app_i2s_loopback_xvf3510/hwsupport.xc | 19 +++ examples/app_i2s_loopback_xvf3510/xua_conf.h | 37 ++++++ 6 files changed, 312 insertions(+) create mode 100644 examples/app_i2s_loopback_xvf3510/Makefile create mode 100644 examples/app_i2s_loopback_xvf3510/XK_XVF3510_L71.xn create mode 100644 examples/app_i2s_loopback_xvf3510/app_i2s_loopback.xc create mode 100644 examples/app_i2s_loopback_xvf3510/config.xscope create mode 100644 examples/app_i2s_loopback_xvf3510/hwsupport.xc create mode 100644 examples/app_i2s_loopback_xvf3510/xua_conf.h diff --git a/examples/app_i2s_loopback_xvf3510/Makefile b/examples/app_i2s_loopback_xvf3510/Makefile new file mode 100644 index 00000000..3ddd7bcb --- /dev/null +++ b/examples/app_i2s_loopback_xvf3510/Makefile @@ -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 + diff --git a/examples/app_i2s_loopback_xvf3510/XK_XVF3510_L71.xn b/examples/app_i2s_loopback_xvf3510/XK_XVF3510_L71.xn new file mode 100644 index 00000000..be6fd040 --- /dev/null +++ b/examples/app_i2s_loopback_xvf3510/XK_XVF3510_L71.xn @@ -0,0 +1,111 @@ + + + Device + XVF3510 Device + + + tileref tile[2] + tileref usb_tile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/app_i2s_loopback_xvf3510/app_i2s_loopback.xc b/examples/app_i2s_loopback_xvf3510/app_i2s_loopback.xc new file mode 100644 index 00000000..742b29db --- /dev/null +++ b/examples/app_i2s_loopback_xvf3510/app_i2s_loopback.xc @@ -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 +#include +#include + +#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 + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/app_i2s_loopback_xvf3510/hwsupport.xc b/examples/app_i2s_loopback_xvf3510/hwsupport.xc new file mode 100644 index 00000000..00a4126e --- /dev/null +++ b/examples/app_i2s_loopback_xvf3510/hwsupport.xc @@ -0,0 +1,19 @@ +#include +#include +#include +#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) +{ +} +//: diff --git a/examples/app_i2s_loopback_xvf3510/xua_conf.h b/examples/app_i2s_loopback_xvf3510/xua_conf.h new file mode 100644 index 00000000..aa0f877c --- /dev/null +++ b/examples/app_i2s_loopback_xvf3510/xua_conf.h @@ -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 \ No newline at end of file