forked from PAWPAW-Mirror/lib_xua
Merge feat/new_spdif_rx -> develop
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
// Copyright 2011-2023 XMOS LIMITED.
|
// Copyright 2011-2023 XMOS LIMITED.
|
||||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||||
|
|
||||||
#include <xs1.h>
|
#include <xs1.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <print.h>
|
#include <print.h>
|
||||||
@@ -141,9 +140,6 @@ static inline void setClockValidity(chanend c_interruptControl, int clkIndex, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns 1 for valid clock found else 0 */
|
/* Returns 1 for valid clock found else 0 */
|
||||||
static inline int validSamples(Counter &counter, int clockIndex)
|
static inline int validSamples(Counter &counter, int clockIndex)
|
||||||
{
|
{
|
||||||
@@ -219,18 +215,6 @@ static inline int validSamples(Counter &counter, int clockIndex)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (XUA_SPDIF_RX_EN)
|
|
||||||
//:badParity
|
|
||||||
/* Returns 1 for bad parity, else 0 */
|
|
||||||
static inline int badParity(unsigned x)
|
|
||||||
{
|
|
||||||
unsigned X = (x>>4);
|
|
||||||
crc32(X, 0, 1);
|
|
||||||
return X & 1;
|
|
||||||
}
|
|
||||||
//:
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LEVEL_METER_LEDS
|
#ifdef LEVEL_METER_LEDS
|
||||||
void VendorLedRefresh(unsigned levelData[]);
|
void VendorLedRefresh(unsigned levelData[]);
|
||||||
unsigned g_inputLevelData[NUM_USB_CHAN_IN];
|
unsigned g_inputLevelData[NUM_USB_CHAN_IN];
|
||||||
@@ -269,9 +253,10 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
int spdifUnderflow = 1;
|
int spdifUnderflow = 1;
|
||||||
int spdifSamps = 0; /* Number of samples in buffer */
|
int spdifSamps = 0; /* Number of samples in buffer */
|
||||||
Counter spdifCounters;
|
Counter spdifCounters;
|
||||||
int spdifReceivedTime;
|
int spdifRxTime;
|
||||||
unsigned tmp2;
|
unsigned tmp2;
|
||||||
unsigned spdifLeft = 0;
|
unsigned spdifLeft = 0;
|
||||||
|
unsigned spdifRxData;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (XUA_ADAT_RX_EN)
|
#if (XUA_ADAT_RX_EN)
|
||||||
@@ -330,7 +315,6 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
adatCounters.samplesPerTick = 0;
|
adatCounters.samplesPerTick = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
t_local :> timeNextEdge;
|
t_local :> timeNextEdge;
|
||||||
timeLastEdge = timeNextEdge;
|
timeLastEdge = timeNextEdge;
|
||||||
timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT / 2);
|
timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT / 2);
|
||||||
@@ -521,25 +505,25 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (XUA_SPDIF_RX_EN)
|
#if (XUA_SPDIF_RX_EN)
|
||||||
/* Receive sample from S/PDIF RX thread (steaming chan) */
|
/* Receive sample from S/PDIF RX thread (streaming chan) */
|
||||||
case c_spdif_rx :> tmp:
|
case c_spdif_rx :> spdifRxData:
|
||||||
|
|
||||||
/* Record time of sample */
|
/* Record time of sample */
|
||||||
t_local :> spdifReceivedTime;
|
t_local :> spdifRxTime;
|
||||||
|
|
||||||
/* Check parity and ignore if bad */
|
/* Check parity and ignore if bad */
|
||||||
if(badParity(tmp))
|
if(spdif_rx_check_parity(spdifRxData))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Get pre-amble */
|
/* Get preamble */
|
||||||
tmp2 = tmp & 0xF;
|
unsigned preamble = spdifRxData & SPDIF_RX_PREAMBLE_MASK;
|
||||||
switch(tmp2)
|
|
||||||
|
switch(preamble)
|
||||||
{
|
{
|
||||||
/* LEFT */
|
/* LEFT */
|
||||||
case SPDIF_FRAME_X:
|
case SPDIF_FRAME_X:
|
||||||
case SPDIF_FRAME_Z:
|
case SPDIF_FRAME_Z:
|
||||||
|
spdifLeft = SPDIF_RX_EXTRACT_SAMPLE(spdifRxData);
|
||||||
spdifLeft = tmp << 4;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* RIGHT */
|
/* RIGHT */
|
||||||
@@ -550,7 +534,7 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
{
|
{
|
||||||
/* Store left and right sample pair to buffer */
|
/* Store left and right sample pair to buffer */
|
||||||
spdifSamples[spdifWr] = spdifLeft;
|
spdifSamples[spdifWr] = spdifLeft;
|
||||||
spdifSamples[spdifWr+1] = tmp << 4;
|
spdifSamples[spdifWr+1] = SPDIF_RX_EXTRACT_SAMPLE(spdifRxData);
|
||||||
|
|
||||||
spdifWr = (spdifWr + 2) & (MAX_SPDIF_SAMPLES - 1);
|
spdifWr = (spdifWr + 2) & (MAX_SPDIF_SAMPLES - 1);
|
||||||
|
|
||||||
@@ -586,13 +570,13 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
if((spdifCounters.receivedSamples >= spdifCounters.samplesPerTick))
|
if((spdifCounters.receivedSamples >= spdifCounters.samplesPerTick))
|
||||||
{
|
{
|
||||||
/* Check edge is about right... S/PDIF may have changed freq... */
|
/* Check edge is about right... S/PDIF may have changed freq... */
|
||||||
if(timeafter(spdifReceivedTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN)))
|
if(timeafter(spdifRxTime, (timeLastEdge + LOCAL_CLOCK_INCREMENT - LOCAL_CLOCK_MARGIN)))
|
||||||
{
|
{
|
||||||
/* Record edge time */
|
/* Record edge time */
|
||||||
timeLastEdge = spdifReceivedTime;
|
timeLastEdge = spdifRxTime;
|
||||||
|
|
||||||
/* Setup for next edge */
|
/* Setup for next edge */
|
||||||
timeNextEdge = spdifReceivedTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
|
timeNextEdge = spdifRxTime + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
|
||||||
|
|
||||||
/* Toggle edge */
|
/* Toggle edge */
|
||||||
i_pll_ref.toggle_timed(1);
|
i_pll_ref.toggle_timed(1);
|
||||||
@@ -705,7 +689,6 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
|
|
||||||
/* Reset counters */
|
/* Reset counters */
|
||||||
adatCounters.receivedSamples = 0;
|
adatCounters.receivedSamples = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -716,7 +699,6 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
#if (XUA_SPDIF_RX_EN || XUA_ADAT_RX_EN)
|
||||||
/* AudioHub requests data */
|
/* AudioHub requests data */
|
||||||
case inuint_byref(c_dig_rx, tmp):
|
case inuint_byref(c_dig_rx, tmp):
|
||||||
@@ -842,8 +824,6 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@
|
|||||||
#include "iap.h"
|
#include "iap.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (XUA_SPDIF_RX_EN)
|
#if (XUA_SPDIF_RX_EN || XUA_SPDIF_TX_EN)
|
||||||
#include "spdif.h"
|
#include "spdif.h" /* From lib_spdif */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (XUA_ADAT_RX_EN)
|
#if (XUA_ADAT_RX_EN)
|
||||||
@@ -42,10 +42,6 @@
|
|||||||
#include "xua_pdm_mic.h"
|
#include "xua_pdm_mic.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (XUA_SPDIF_TX_EN)
|
|
||||||
#include "spdif.h" /* From lib_spdif */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (XUA_DFU_EN == 1)
|
#if (XUA_DFU_EN == 1)
|
||||||
[[distributable]]
|
[[distributable]]
|
||||||
void DFUHandler(server interface i_dfu i, chanend ?c_user_cmd);
|
void DFUHandler(server interface i_dfu i, chanend ?c_user_cmd);
|
||||||
|
|||||||
Reference in New Issue
Block a user