Skip to content

Commit

Permalink
Merge pull request #274 from xross/feature/sync_tests
Browse files Browse the repository at this point in the history
Feature/sync tests
  • Loading branch information
xross authored Aug 8, 2022
2 parents 8157a76 + 80e6f04 commit ce41732
Show file tree
Hide file tree
Showing 41 changed files with 712 additions and 189 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ build/
.build*
*.pyc
xscope.xmt

# Traces
*.gtkw
*.vcd
14 changes: 10 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ pipeline {
xcoreLibraryChecks("${REPO}")
}
}
stage('XS2 Tests') {
stage('Testing') {
failFast true
parallel {
stage('Legacy tests') {
stage('Tests') {
steps {
runXmostest("${REPO}", 'legacy_tests')
dir("${REPO}/tests"){
viewEnv(){
withVenv{
runPytest('--numprocesses=4')
}
}
}
}
}
stage('Unit tests') {
stage('Unity tests') {
steps {
dir("${REPO}") {
dir('tests') {
Expand Down
23 changes: 0 additions & 23 deletions legacy_tests/runtests.py

This file was deleted.

51 changes: 0 additions & 51 deletions legacy_tests/test_i2s_loopback.py

This file was deleted.

5 changes: 2 additions & 3 deletions lib_xua/src/core/audiohub/xua_audiohub.xc
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,11 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
null,
p_dsd_clk,
#endif
divide, curSamFreq, dsdMode);
p_mclk_in, clk_audio_bclk, divide, curSamFreq, dsdMode);
}
else
#endif
{

ConfigAudioPortsWrapper(
#if (I2S_CHANS_DAC != 0)
p_i2s_dac,
Expand All @@ -813,7 +812,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk,
p_bclk,
#endif
#endif
divide, curSamFreq, dsdMode);
p_mclk_in, clk_audio_bclk, divide, curSamFreq, dsdMode);
}


Expand Down
34 changes: 28 additions & 6 deletions lib_xua/src/core/buffer/ep/ep_buffer.xc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "xua.h"
#if XUA_USB_EN
#include <xs1.h>
#include <print.h>

#include <stdint.h>

#ifdef MIDI
#include "usb_midi.h"
Expand Down Expand Up @@ -357,7 +356,21 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
#endif
#endif

timer tmr;
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
#ifndef LOCAL_CLOCK_INCREMENT
#define LOCAL_CLOCK_INCREMENT (100000) /* 500Hz */
#endif
#ifndef LOCAL_CLOCK_MARGIN
#define LOCAL_CLOCK_MARGIN (1000)
#endif
int sofClockValid = 0;
timer t_sofCheck;
unsigned timeLastEdge;
unsigned timeNextEdge;
t_sofCheck :> timeLastEdge;
timeNextEdge + LOCAL_CLOCK_INCREMENT;
i_pll_ref.toggle();
#endif

while(1)
{
Expand Down Expand Up @@ -502,6 +515,13 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
}
break;
}
#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC)
case t_sofCheck when timerafter(timeNextEdge) :> void:
i_pll_ref.toggle();
timeLastEdge = timeNextEdge;
timeNextEdge += LOCAL_CLOCK_INCREMENT;
break;
#endif

#define MASK_16_13 (7) /* Bits that should not be transmitted as part of feedback */
#define MASK_16_10 (127) /* For Audio 1.0 we use a mask 1 bit longer than expected to avoid Windows LSB issues */
Expand All @@ -517,20 +537,21 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
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));
clocks = ((int64_t) sampleFreq << 16) / framesPerSec;

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_pll_ref.toggle();
t_sofCheck :> timeLastEdge;
sofCount = 0;
timeNextEdge = timeLastEdge + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN;
}
#else

Expand Down Expand Up @@ -889,6 +910,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
case XUD_SetData_Select(c_hid, ep_hid, result):
hid_ready_flag = 0U;
unsigned reportTime;
timer tmr;
tmr :> reportTime;
hidCaptureReportTime(hid_ready_id, reportTime);
hidCalcNextReportTime(hid_ready_id);
Expand Down
16 changes: 5 additions & 11 deletions lib_xua/src/core/clocking/clockgen.xc
Original file line number Diff line number Diff line change
Expand Up @@ -490,20 +490,14 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa
timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT/2);
timeNextEdge += LOCAL_CLOCK_INCREMENT;

/* If we are in an external clock mode and this fire, then clock invalid */

/* If we are in an external clock mode and this fire, then clock invalid
* reset counters in case we are moved to digital clock - we want a well timed
* first edge */
#if (XUA_SPDIF_RX_EN)
// if(clkMode == CLOCK_SPDIF)
{
/* We must have lost valid S/PDIF stream, reset counters, so we dont produce a double edge */
spdifCounters.receivedSamples = 0;
}
spdifCounters.receivedSamples = 0;
#endif
#if ADAT_RX
//if(clkMode == CLOCK_ADAT)
{
adatCounters.receivedSamples = 0;
}
adatCounters.receivedSamples = 0;
#endif

#ifdef CLOCK_VALIDITY_CALL
Expand Down
7 changes: 3 additions & 4 deletions lib_xua/src/core/ports/audioports.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright 2013-2021 XMOS LIMITED.
// Copyright 2013-2022 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#include <xs1.h>
#define __ASSEMBLER__ // Work around for bug #14118
#include <platform.h>
#undef __ASSEMBLER__
#include "audioports.h"
#include <xccompat.h>
#include "xua.h"

/* Note since DSD ports could be reused for I2S ports we do all the setup manually in C */
Expand Down Expand Up @@ -46,7 +45,7 @@ void ConfigAudioPortsWrapper(
port p_lrclk,
port p_bclk,
#endif
unsigned int divide, unsigned curSamFreq, unsigned int dsdMode)
port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq, unsigned int dsdMode)
{
ConfigAudioPorts(
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0)
Expand All @@ -61,6 +60,6 @@ unsigned int divide, unsigned curSamFreq, unsigned int dsdMode)
p_lrclk,
p_bclk,
#endif
divide, curSamFreq);
p_mclk_in, clk_audio_bclk, divide, curSamFreq);
}

13 changes: 8 additions & 5 deletions lib_xua/src/core/ports/audioports.h
Original file line number Diff line number Diff line change
@@ -1,9 +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 _AUDIOPORTS_H_
#define _AUDIOPORTS_H_

#include <xccompat.h>
#ifdef __STDC__
typedef unsigned clock;
#endif
#include "xua.h"

#ifdef __XC__
Expand All @@ -28,7 +31,7 @@ void ConfigAudioPorts(
in port p_bclk,
#endif
#endif
unsigned int divide, unsigned int curSamFreq);
in port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned int curSamFreq);
#else

void ConfigAudioPorts(
Expand All @@ -51,7 +54,7 @@ void ConfigAudioPorts(
port p_bclk,
#endif
#endif
unsigned int divide, unsigned int curSamFreq);
port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned int curSamFreq);


#endif /* __XC__*/
Expand All @@ -76,7 +79,7 @@ void ConfigAudioPortsWrapper(
buffered in port:32 p_bclk,
#endif
#endif
unsigned int divide, unsigned curSamFreq, unsigned int dsdMode);
in port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq, unsigned int dsdMode);
#else

void ConfigAudioPortsWrapper(
Expand All @@ -92,7 +95,7 @@ void ConfigAudioPortsWrapper(
port p_lrclk,
port p_bclk,
#endif
unsigned int divide, unsigned curSamFreq, unsigned int dsdMode);
port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq, unsigned int dsdMode);


#endif /* __XC__*/
Expand Down
10 changes: 4 additions & 6 deletions lib_xua/src/core/ports/audioports.xc
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Copyright 2011-2021 XMOS LIMITED.
// Copyright 2011-2022 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#include <xs1.h>
#include <platform.h>
#include <print.h>
#include "xua.h"
#include "audioports.h"



extern in port p_mclk_in;
//extern in port p_mclk_in;
extern clock clk_audio_mclk;
extern clock clk_audio_bclk;
//extern clock clk_audio_bclk;

void ConfigAudioPorts(
#if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0)
Expand All @@ -32,7 +30,7 @@ void ConfigAudioPorts(
in port p_bclk,
#endif
#endif
unsigned int divide, unsigned curSamFreq)
in port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq)
{
#if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ pytest-xdist==1.34.0
# of its own setup.py file, then this list must include an entry for that
# setup.py file, e.g., '-e .' or '-e ./python' (without the quotes).
-e ./python
-e ./../test_support
24 changes: 24 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
import pytest


def pytest_addoption(parser):
parser.addoption(
"--enabletracing",
action="store_true",
default=False,
help="Run tests with instruction tracing",
)

parser.addoption(
"--enablevcdtracing",
action="store_true",
default=False,
help="Run tests with vcd tracing",
)


@pytest.fixture
def options(request):
yield request.config.option
File renamed without changes.
Loading

0 comments on commit ce41732

Please sign in to comment.