Skip to content

Commit

Permalink
Merge pull request #272 from xross/feature/sync
Browse files Browse the repository at this point in the history
Feature/sync
  • Loading branch information
xross authored Jul 11, 2022
2 parents 638a4f0 + a913cd8 commit d6abd5d
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 216 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ _build*
**/.vscode/**
**.egg-info
*.pdf
*tests/logs/*

# waf build files
.lock-waf_*
Expand Down
43 changes: 10 additions & 33 deletions lib_xua/api/xua_buffer.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2011-2021 XMOS LIMITED.
// Copyright 2011-2022 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef __XUA_BUFFER_H__
#define __XUA_BUFFER_H__

#if __XC__

#include "xua.h"
#include "clocking.h"

/** USB Audio Buffering Core.
*
Expand Down Expand Up @@ -38,31 +39,20 @@ void XUA_Buffer(
chanend c_midi_to_host,
chanend c_midi,
#endif
#ifdef IAP
chanend c_iap_from_host,
chanend c_iap_to_host,
#ifdef IAP_INT_EP
chanend c_iap_to_host_int,
#endif
chanend c_iap,
#ifdef IAP_EA_NATIVE_TRANS
chanend c_iap_ea_native_out,
chanend c_iap_ea_native_in,
chanend c_iap_ea_native_ctrl,
chanend c_iap_ea_native_data,
#endif
#endif
#if (SPDIF_RX) || (ADAT_RX)
chanend ?c_int,
chanend ?c_clk_int,
#endif
chanend c_sof,
chanend c_aud_ctl,
in port p_off_mclk
#if( 0 < HID_CONTROLS )
#if (HID_CONTROLS )
, chanend c_hid
#endif
, chanend c_aud
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, client interface sync_if i_sync
#endif
);

void XUA_Buffer_Ep(chanend c_aud_out,
Expand All @@ -77,32 +67,21 @@ void XUA_Buffer_Ep(chanend c_aud_out,
chanend c_midi_to_host,
chanend c_midi,
#endif
#ifdef IAP
chanend c_iap_from_host,
chanend c_iap_to_host,
#ifdef IAP_INT_EP
chanend c_iap_to_host_int,
#endif
chanend c_iap,
#ifdef IAP_EA_NATIVE_TRANS
chanend c_iap_ea_native_out,
chanend c_iap_ea_native_in,
chanend c_iap_ea_native_ctrl,
chanend c_iap_ea_native_data,
#endif
#endif
#if (SPDIF_RX) || (ADAT_RX)
chanend ?c_int,
chanend ?c_clk_int,
#endif
chanend c_sof,
chanend c_aud_ctl,
in port p_off_mclk
#if( 0 < HID_CONTROLS )
#if (HID_CONTROLS)
, chanend c_hid
#endif
#ifdef CHAN_BUFF_CTRL
, chanend c_buff_ctrl
#endif
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, client interface sync_if i_sync
#endif
);

Expand All @@ -116,7 +95,5 @@ void XUA_Buffer_Decouple(chanend c_audio_out
, chanend c_buff_ctrl
#endif
);

#endif

#endif
23 changes: 21 additions & 2 deletions lib_xua/api/xua_conf_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "xua_conf.h"
#endif



/* Default tile arrangement */

/**
Expand Down Expand Up @@ -57,6 +55,13 @@
#define PDM_TILE AUDIO_IO_TILE
#endif

/**
* @brief Location (tile) of reference signal to CS2100. Default: AUDIO_IO_TILE
*/
#ifndef PLL_REF_TILE
#define PLL_REF_TILE AUDIO_IO_TILE
#endif

/**
* @brief Disable USB functionalty just leaving AudioHub
*/
Expand Down Expand Up @@ -1452,3 +1457,17 @@ enum USBEndpointNumber_Out
#if (CODEC_MASTER == 1) && (DSD_CHANS_DAC != 0)
#error CODEC_MASTER with DSD is currently unsupported
#endif

#define XUA_SYNCMODE_ASYNC (1) // USB_ENDPOINT_SYNCTYPE_ASYNC
#define XUA_SYNCMODE_ADAPT (2) // USB_ENDPOINT_SYNCTYPE_ADAPT
#define XUA_SYNCMODE_SYNC (3) // USB_ENDPOINT_SYNCTYPE_SYNC

#ifndef XUA_SYNCMODE
#define XUA_SYNCMODE XUA_SYNCMODE_ASYNC
#endif

#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
#if (SPDIF_RX || ADAT_RX)
#error "Digital input streams not supported in Sync mode"
#endif
#endif
132 changes: 62 additions & 70 deletions lib_xua/src/core/buffer/ep/ep_buffer.xc
Original file line number Diff line number Diff line change
Expand Up @@ -91,43 +91,32 @@ unsigned int fb_clocks[4];
#define FB_TOLERANCE 0x100

void XUA_Buffer(
register chanend c_aud_out,
register chanend c_aud_out,
#if (NUM_USB_CHAN_IN > 0)
register chanend c_aud_in,
register chanend c_aud_in,
#endif
#if (NUM_USB_CHAN_IN == 0) || defined (UAC_FORCE_FEEDBACK_EP)
chanend c_aud_fb,
chanend c_aud_fb,
#endif
#ifdef MIDI
chanend c_midi_from_host,
chanend c_midi_to_host,
chanend c_midi,
#endif
#ifdef IAP
chanend c_iap_from_host,
chanend c_iap_to_host,
#ifdef IAP_INT_EP
chanend c_iap_to_host_int,
#endif
chanend c_iap,
#ifdef IAP_EA_NATIVE_TRANS
chanend c_iap_ea_native_out,
chanend c_iap_ea_native_in,
chanend c_iap_ea_native_ctrl,
chanend c_iap_ea_native_data,
#endif
chanend c_midi_from_host,
chanend c_midi_to_host,
chanend c_midi,
#endif
#if (SPDIF_RX) || (ADAT_RX)
chanend ?c_ep_int,
chanend ?c_clk_int,
chanend ?c_ep_int,
chanend ?c_clk_int,
#endif
chanend c_sof,
chanend c_aud_ctl,
in port p_off_mclk
#if( 0 < HID_CONTROLS )
, chanend c_hid
chanend c_sof,
chanend c_aud_ctl,
in port p_off_mclk
#if (HID_CONTROLS )
, chanend c_hid
#endif
, chanend c_aud
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, client interface sync_if i_sync
#endif
, chanend c_aud
)
{
#ifdef CHAN_BUFF_CTRL
Expand All @@ -148,20 +137,6 @@ void XUA_Buffer(
c_midi_to_host, /* MIDI In */ // 4
c_midi,
#endif
#ifdef IAP
c_iap_from_host, /* iAP Out */
c_iap_to_host, /* iAP In */
#ifdef IAP_INT_EP
c_iap_to_host_int, /* iAP Interrupt In */
#endif
c_iap,
#ifdef IAP_EA_NATIVE_TRANS
c_iap_ea_native_out,
c_iap_ea_native_in,
c_EANativeTransport_ctrl,
c_ea_data,
#endif
#endif
#if (SPDIF_RX) || (ADAT_RX)
/* Audio Interrupt - only used for interrupts on external clock change */
c_ep_int,
Expand All @@ -173,6 +148,9 @@ void XUA_Buffer(
#endif
#ifdef CHAN_BUFF_CTRL
, c_buff_ctrl
#endif
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
, i_sync
#endif
);

Expand Down Expand Up @@ -204,38 +182,27 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
chanend c_aud_fb,
#endif
#ifdef MIDI
chanend c_midi_from_host,
chanend c_midi_to_host,
chanend c_midi,
#endif
#ifdef IAP
chanend c_iap_from_host,
chanend c_iap_to_host,
#ifdef IAP_INT_EP
chanend c_iap_to_host_int,
#endif
chanend c_iap,
#ifdef IAP_EA_NATIVE_TRANS
chanend c_iap_ea_native_out,
chanend c_iap_ea_native_in,
chanend c_iap_ea_native_ctrl,
chanend c_iap_ea_native_data,
#endif
chanend c_midi_from_host,
chanend c_midi_to_host,
chanend c_midi,
#endif
#if (SPDIF_RX) || (ADAT_RX)
chanend ?c_ep_int,
chanend ?c_clk_int,
chanend ?c_ep_int,
chanend ?c_clk_int,
#endif
chanend c_sof,
chanend c_aud_ctl,
in port p_off_mclk
#if( 0 < HID_CONTROLS )
, chanend c_hid
chanend c_sof,
chanend c_aud_ctl,
in port p_off_mclk
#if(HID_CONTROLS)
, chanend c_hid
#endif
#ifdef CHAN_BUFF_CTRL
, chanend c_buff_ctrl
, chanend c_buff_ctrl
#endif
)
#if XUA_SYNCMODE == XUA_SYNCMODE_SYNC
, client interface sync_if i_sync
#endif
)
{
XUD_ep ep_aud_out = XUD_InitEp(c_aud_out);

Expand Down Expand Up @@ -542,6 +509,30 @@ void XUA_Buffer_Ep(register chanend c_aud_out,

/* SOF notification from XUD_Manager() */
case inuint_byref(c_sof, u_tmp):
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
/* This really could (should) be done in decouple. However, for a quick demo this is okay
* Decouple expects a 16:16 number in fixed point stored in the global g_speed */

unsigned usbSpeed;
int framesPerSec;
GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed);
static int sofCount = 0;
static unsigned syncPinVal = 0;

framesPerSec = (usbSpeed == XUD_SPEED_HS) ? 8000 : 1000;
float float_clocks = (float) sampleFreq/framesPerSec ;

clocks = (unsigned) (float_clocks * (1 << 16));
asm volatile("stw %0, dp[g_speed]"::"r"(clocks));

sofCount += 1000;
if (sofCount == framesPerSec)
{
/* Port is accessed via interface to allow flexibilty with location */
i_sync.toggle();
sofCount = 0;
}
#else

/* NOTE our feedback will be wrong for a couple of SOF's after a SF change due to
* lastClock being incorrect */
Expand Down Expand Up @@ -711,7 +702,8 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
#endif
sofCount++;
}
break;
#endif
break;

#if (NUM_USB_CHAN_IN > 0)
/* Sent audio packet DEVICE -> HOST */
Expand All @@ -724,7 +716,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
#endif

#if (NUM_USB_CHAN_OUT > 0)
#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP)
#if (NUM_USB_CHAN_IN == 0) || defined(UAC_FORCE_FEEDBACK_EP) && (XUA_SYNCMODE == XUA_SYNCMODE_ASYNC)
/* Feedback Pipe */
case XUD_SetData_Select(c_aud_fb, ep_aud_fb, result):
{
Expand Down
19 changes: 19 additions & 0 deletions lib_xua/src/core/clocking/clockgen.xc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "xua.h"
#include "xua_commands.h"
#include "clocking.h"

#if (SPDIF_RX)
#include "spdif.h"
Expand Down Expand Up @@ -38,6 +39,24 @@ static int clockValid[NUM_CLOCKS]; /* Store current val
static int clockInt[NUM_CLOCKS]; /* Interupt flag for clocks */
static int clockId[NUM_CLOCKS];

[[combinable]]
void PllRefPinTask(server interface sync_if i_sync, out port p_sync)
{
static unsigned pinVal= 0;
p_sync <: pinVal;

while(1)
{
select
{
case i_sync.toggle():
pinVal = ~pinVal;
p_sync <: pinVal;
break;
}
}
}


#if (SPDIF_RX) || (ADAT_RX)
static int abs(int x)
Expand Down
10 changes: 9 additions & 1 deletion lib_xua/src/core/clocking/clocking.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2011-2021 XMOS LIMITED.
// Copyright 2011-2022 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#ifndef _CLOCKING_H_
Expand All @@ -16,5 +16,13 @@
interrupts
*/
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);

interface sync_if
{
void toggle();
};

[[combinable]]
void PllRefPinTask(server interface sync_if i_sync, out port p_sync);
#endif

Loading

0 comments on commit d6abd5d

Please sign in to comment.