WIP + get DAC config running

This commit is contained in:
Ed Clarke
2018-10-26 11:25:39 +01:00
parent 770c11b3f0
commit 161b934b8f
8 changed files with 198 additions and 165 deletions

1
.gitignore vendored
View File

@@ -26,3 +26,4 @@ _build*
build/ build/
.build* .build*
*.pyc *.pyc
xscope.xmt

View File

@@ -4,7 +4,9 @@ TARGET = RPI_HAT_60QFN.xn
# The flags passed to xcc when building the application # The flags passed to xcc when building the application
XCC_FLAGS = -fcomment-asm -Xmapper --map -Xmapper MAPFILE -O3 -report \ XCC_FLAGS = -fcomment-asm -Xmapper --map -Xmapper MAPFILE -O3 -report \
-g -Wno-unused-function -Wno-timing -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[0] -g -Wno-unused-function -Wno-timing -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSB_TILE=tile[0] \
-D XUA_LITE=1
#-DSDA_HIGH=2 -DSCL_HIGH=1 -fxscope #-DSDA_HIGH=2 -DSCL_HIGH=1 -fxscope

View File

@@ -0,0 +1,3 @@
<xSCOPEconfig ioMode="basic" enabled="true">
<Probe name="Value" type="CONTINUOUS" datatype="INT" units="Value" enabled="true"/>
</xSCOPEconfig>

View File

@@ -3,6 +3,7 @@
#include <platform.h> #include <platform.h>
#include <print.h> #include <print.h>
#include <stdio.h> #include <stdio.h>
#include "i2c.h"
@@ -51,20 +52,12 @@
// TLV320DAC3101 easy register access defines // TLV320DAC3101 easy register access defines
//#define DAC3101_REGWRITE(reg, val) {data[0] = val; i2c_master_write_reg(DAC3101_I2C_DEVICE_ADDR, reg, data, 1, i2c);} //#define DAC3101_REGWRITE(reg, val) {data[0] = val; i2c_master_write_reg(DAC3101_I2C_DEVICE_ADDR, reg, data, 1, i2c);}
#define DAC3101_REGWRITE(reg, val) #define DAC3101_REGWRITE(reg, val) {i_i2c.write_reg(DAC3101_I2C_DEVICE_ADDR, reg, val);}
void AudioHwConfigure(unsigned samFreq) void AudioHwConfigure(unsigned samFreq, client i2c_master_if i_i2c)
{ {
// Take DAC out of reset.
//p_gpio <: 1;
par
{
{
unsigned char data[1] = {0};
// Wait for 1ms // Wait for 1ms
delay_milliseconds(1); delay_milliseconds(1);
@@ -209,10 +202,6 @@ void AudioHwConfigure(unsigned samFreq)
// Unmute DAC left and right channels // Unmute DAC left and right channels
DAC3101_REGWRITE(DAC3101_DAC_VOL, 0x00); DAC3101_REGWRITE(DAC3101_DAC_VOL, 0x00);
// Shutdown
//i_i2c[0].shutdown();
}
} /* par */
} }
//These are here just to silence compiler warnings //These are here just to silence compiler warnings

View File

@@ -10,6 +10,10 @@
#include "i2c.h" #include "i2c.h"
#include "gpio.h" #include "gpio.h"
#define DEBUG_UNIT XUA_APP
#define DEBUG_PRINT_ENABLE_XUA_APP 1
#include "debug_print.h"
// Port declarations. Note, the defines come from the xn file // Port declarations. Note, the defines come from the xn file
on tile[0]: buffered out port:32 p_i2s_dac[] = {XS1_PORT_1M}; //DAC on tile[0]: buffered out port:32 p_i2s_dac[] = {XS1_PORT_1M}; //DAC
on tile[0]: buffered in port:32 p_i2s_adc[] = {XS1_PORT_1N}; //Unused currently on tile[0]: buffered in port:32 p_i2s_adc[] = {XS1_PORT_1N}; //Unused currently
@@ -17,7 +21,7 @@ on tile[0]: buffered out port:32 p_lrclk = XS1_PORT_1O; //I2S Bit-clo
on tile[0]: out port p_bclk = XS1_PORT_1P; //I2S L/R-clock on tile[0]: out port p_bclk = XS1_PORT_1P; //I2S L/R-clock
// Master clock for the audio IO tile // Master clock for the audio IO tile
on tile[0]: in port p_mclk_in = XS1_PORT_1A; on tile[0]: in port p_mclk_in = XS1_PORT_1K;
// Resources for USB feedback // Resources for USB feedback
on tile[0]: in port p_for_mclk_count= XS1_PORT_16A; // Extra port for counting master clock ticks on tile[0]: in port p_for_mclk_count= XS1_PORT_16A; // Extra port for counting master clock ticks
@@ -35,6 +39,7 @@ on tile[1]: port p_sda = XS1_PORT_1D;
// Clock-block declarations // Clock-block declarations
clock clk_audio_bclk = on tile[0]: XS1_CLKBLK_2; // Bit clock clock clk_audio_bclk = on tile[0]: XS1_CLKBLK_2; // Bit clock
clock clk_audio_mclk = on tile[0]: XS1_CLKBLK_3; // Master clock clock clk_audio_mclk = on tile[0]: XS1_CLKBLK_3; // Master clock
//XUD uses XS1_CLKBLK_4, XS1_CLKBLK_5
// Endpoint type tables - informs XUD what the transfer types for each Endpoint in use and also // Endpoint type tables - informs XUD what the transfer types for each Endpoint in use and also
// if the endpoint wishes to be informed of USB bus resets // if the endpoint wishes to be informed of USB bus resets
@@ -79,7 +84,7 @@ int main()
XUD_Main(c_ep_out, 2, c_ep_in, 3, XUD_Main(c_ep_out, 2, c_ep_in, 3,
c_sof, epTypeTableOut, epTypeTableIn, c_sof, epTypeTableOut, epTypeTableIn,
null, null, -1 , null, null, -1 ,
XUD_SPEED_FS, XUD_PWR_BUS); (AUDIO_CLASS == 1) ? XUD_SPEED_FS : XUD_SPEED_HS, XUD_PWR_BUS);
// Endpoint 0 core from lib_xua // Endpoint 0 core from lib_xua
// Note, since we are not using many features we pass in null for quite a few params.. // Note, since we are not using many features we pass in null for quite a few params..

View File

@@ -2,11 +2,16 @@
#include "i2c.h" #include "i2c.h"
#include "gpio.h" #include "gpio.h"
#include "xua.h" #include "xua.h"
#define DEBUG_UNIT XUA_AUDIO_HUB
#define DEBUG_PRINT_ENABLE_XUA_AUDIO_HUB 1
#include "debug_print.h"
void AudioHwConfigure(unsigned samFreq, client i2c_master_if i_i2c);
[[distributable]] [[distributable]]
void AudioHub(server i2s_frame_callback_if i2s, void AudioHub(server i2s_frame_callback_if i2s,
chanend c_aud, chanend c_aud,
client i2c_master_if i2c, client i2c_master_if i_i2c,
client output_gpio_if dac_reset) client output_gpio_if dac_reset)
{ {
int32_t samples[8] = {0}; // Array used for looping back samples int32_t samples[8] = {0}; // Array used for looping back samples
@@ -25,7 +30,8 @@ void AudioHub(server i2s_frame_callback_if i2s,
// Take CODECs out of reset // Take CODECs out of reset
dac_reset.output(1); dac_reset.output(1);
//reset_codecs(i2c); AudioHwConfigure(DEFAULT_FREQ, i_i2c);
debug_printf("I2S init\n");
break; break;
case i2s.receive(size_t n_chans, int32_t in_samps[n_chans]): case i2s.receive(size_t n_chans, int32_t in_samps[n_chans]):
@@ -38,6 +44,7 @@ void AudioHub(server i2s_frame_callback_if i2s,
case i2s.restart_check() -> i2s_restart_t restart: case i2s.restart_check() -> i2s_restart_t restart:
restart = I2S_NO_RESTART; // Keep on looping restart = I2S_NO_RESTART; // Keep on looping
debug_printf("I2S restart\n");
break; break;
} }
} }

View File

@@ -2,8 +2,10 @@
#include "xua_commands.h" #include "xua_commands.h"
#include "xud.h" #include "xud.h"
#include "testct_byref.h" #include "testct_byref.h"
#define DEBUG_UNIT XUA_LITE_BUFFER
#define DEBUG_PRINT_ENABLE_XUA_LITE_BUFFER 1
#include "debug_print.h" #include "debug_print.h"
#include "xua_conf.h" #include "xua.h"
//#include "fifo_impl.h" //xua_conf.h must be included before hand so that we have FIFO sizes //#include "fifo_impl.h" //xua_conf.h must be included before hand so that we have FIFO sizes
//Currently only single frequency supported //Currently only single frequency supported
@@ -98,6 +100,8 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
unsigned char buffer_aud_out[OUT_AUDIO_BUFFER_SIZE_BYTES]; unsigned char buffer_aud_out[OUT_AUDIO_BUFFER_SIZE_BYTES];
unsigned char buffer_aud_in[IN_AUDIO_BUFFER_SIZE_BYTES]; unsigned char buffer_aud_in[IN_AUDIO_BUFFER_SIZE_BYTES];
unsigned char buffer_feedback[4];
unsigned in_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES; unsigned in_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_INPUT_1_SUBSLOT_BYTES;
unsigned out_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES; unsigned out_subslot_size = (AUDIO_CLASS == 1) ? FS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES : HS_STREAM_FORMAT_OUTPUT_1_SUBSLOT_BYTES;
@@ -107,7 +111,9 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
unsigned tmp; unsigned tmp;
XUD_ep ep_aud_out = XUD_InitEp(c_aud_out); XUD_ep ep_aud_out = XUD_InitEp(c_aud_out);
XUD_ep ep_feedback = XUD_InitEp(c_feedback);
XUD_ep ep_aud_in = XUD_InitEp(c_aud_in); XUD_ep ep_aud_in = XUD_InitEp(c_aud_in);
unsigned num_samples_received_from_host = 0; unsigned num_samples_received_from_host = 0;
@@ -116,6 +122,7 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out); XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out);
XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in, num_samples_to_send_to_host); XUD_SetReady_InPtr(ep_aud_in, (unsigned)buffer_aud_in, num_samples_to_send_to_host);
XUD_SetReady_InPtr(ep_feedback, (unsigned)buffer_feedback, 4);
// printintln(OUT_AUDIO_BUFFER_SIZE_BYTES); // printintln(OUT_AUDIO_BUFFER_SIZE_BYTES);
// printintln(MAX_OUT_SAMPLES_PER_SOF_PERIOD); // printintln(MAX_OUT_SAMPLES_PER_SOF_PERIOD);
@@ -246,18 +253,21 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
int samples[MAX_OUT_SAMPLES_PER_SOF_PERIOD]; int samples[MAX_OUT_SAMPLES_PER_SOF_PERIOD];
unpack_buff_to_samples(buffer_aud_out, num_samples_received_from_host, out_subslot_size, samples); unpack_buff_to_samples(buffer_aud_out, num_samples_received_from_host, out_subslot_size, samples);
//Push into fifo for ASRC
//else debug_printf("Push\n");
//Tell ASRC manager what we have just sent //Tell ASRC manager what we have just sent
outuint(c_aud_host, num_samples_received_from_host); //We assume this will not block and other side always consumes //outuint(c_aud_host, num_samples_received_from_host); //We assume this will not block and other side always consumes
num_samples_to_send_to_host = inuint(c_aud_host); //get number of return samples for sending back to host //num_samples_to_send_to_host = inuint(c_aud_host); //get number of return samples for sending back to host
//Mark EP as ready for next frame from host //Mark EP as ready for next frame from host
XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out); XUD_SetReady_OutPtr(ep_aud_out, (unsigned)buffer_aud_out);
break; break;
//Send feedback
case XUD_SetData_Select(c_feedback, ep_feedback, result):
debug_printf("ep_feedback\n");
XUD_SetReady_InPtr(ep_feedback, (unsigned)buffer_feedback, 4);
break;
//Send samples to host //Send samples to host
case XUD_SetData_Select(c_aud_in, ep_aud_in, result): case XUD_SetData_Select(c_aud_in, ep_aud_in, result):
//debug_printf("sent data\n"); //debug_printf("sent data\n");

View File

@@ -297,9 +297,25 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
while(1) while(1)
{ {
#if XUA_LITE
unsigned char sbuffer[120];
unsigned length;
//XUD_Result_t result = XUD_GetSetupBuffer(ep0_out, sbuffer, &length); //Flattened from xud_device
XUD_Result_t result = XUD_GetSetupData(ep0_out, sbuffer, &length);//Flattened from XUD_EpFunctions.xc
//Next step:
//void XUD_GetSetupData_Select(chan c,XUD_ep e_out, unsigned &length, XUD_Result_t &result);
if (result == XUD_RES_OKAY)
{
/* Parse data buffer end populate SetupPacket struct */
USB_ParseSetupPacket(sbuffer, &sp);
}
#else
/* Returns XUD_RES_OKAY for success, XUD_RES_RST for bus reset */ /* Returns XUD_RES_OKAY for success, XUD_RES_RST for bus reset */
XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, &sp); XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, &sp);
#endif
if (result == XUD_RES_OKAY) if (result == XUD_RES_OKAY)
{ {
result = XUD_RES_ERR; result = XUD_RES_ERR;