Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/unit decouple #346

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pipeline {
dir("${REPO}/tests"){
viewEnv(){
withVenv{
runPytest('--numprocesses=4')
runPytest('-s --numprocesses=4')
}
}
}
Expand Down
46 changes: 43 additions & 3 deletions lib_xua/api/xua_buffer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2011-2022 XMOS LIMITED.
// Copyright 2011-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef __XUA_BUFFER_H__
#define __XUA_BUFFER_H__
#ifndef _XUA_BUFFER_H_
#define _XUA_BUFFER_H_

#if __XC__

Expand Down Expand Up @@ -97,4 +97,44 @@ void XUA_Buffer_Decouple(chanend c_audio_out
#endif
);
#endif

#ifndef MAX
#define MAX(x,y) ((x)>(y) ? (x) : (y))
#endif

/* TODO use SLOTSIZE to potentially save memory */
/* Note we could improve on this, for one subslot is set to 4 */
/* The *4 is conversion to bytes, note we're assuming a slotsize of 4 here whic is potentially as waste */
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS ((MAX_FREQ/8000+1)*4)
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS ((MAX_FREQ_FS/1000+1)*4)

/*** IN PACKET SIZES ***/
/* Max packet sizes in bytes. Note the +4 is because we store packet lengths in the buffer */
#define MAX_DEVICE_AUD_PACKET_SIZE_IN_HS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * NUM_USB_CHAN_IN + 4)
#define MAX_DEVICE_AUD_PACKET_SIZE_IN_FS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * NUM_USB_CHAN_IN_FS + 4)

#define MAX_DEVICE_AUD_PACKET_SIZE_IN (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_FS, MAX_DEVICE_AUD_PACKET_SIZE_IN_HS))

/*** OUT PACKET SIZES ***/
#define MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * NUM_USB_CHAN_OUT + 4)
#define MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * NUM_USB_CHAN_OUT_FS + 4)

#define MAX_DEVICE_AUD_PACKET_SIZE_OUT (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS))

/*** BUFFER SIZES ***/

#define BUFFER_PACKET_COUNT (4) /* How many packets too allow for in buffer - minimum is 4 */

#define BUFF_SIZE_OUT_HS MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS * BUFFER_PACKET_COUNT
#define BUFF_SIZE_OUT_FS MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS * BUFFER_PACKET_COUNT

#define BUFF_SIZE_IN_HS MAX_DEVICE_AUD_PACKET_SIZE_IN_HS * BUFFER_PACKET_COUNT
#define BUFF_SIZE_IN_FS MAX_DEVICE_AUD_PACKET_SIZE_IN_FS * BUFFER_PACKET_COUNT

#define BUFF_SIZE_OUT MAX(BUFF_SIZE_OUT_HS, BUFF_SIZE_OUT_FS)
#define BUFF_SIZE_IN MAX(BUFF_SIZE_IN_HS, BUFF_SIZE_IN_FS)

#define OUT_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS))
#define IN_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_HS, MAX_DEVICE_AUD_PACKET_SIZE_IN_FS)*2)

#endif
1 change: 0 additions & 1 deletion lib_xua/module_build_info
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ DEPENDENT_MODULES = lib_locks(>=2.1.0) \

MODULE_XCC_FLAGS = $(XCC_FLAGS) \
-O3 \
-DREF_CLK_FREQ=100 \
-fasm-linenum \
-fcomment-asm \
$(DEBUG_FLAGS)
Expand Down
54 changes: 18 additions & 36 deletions lib_xua/src/core/buffer/decouple/decouple.xc
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,7 @@
#if (HID_CONTROLS)
#include "user_hid.h"
#endif
#define MAX(x,y) ((x)>(y) ? (x) : (y))

/* TODO use SLOTSIZE to potentially save memory */
/* Note we could improve on this, for one subslot is set to 4 */
/* The *4 is conversion to bytes, note we're assuming a slotsize of 4 here whic is potentially as waste */
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS ((MAX_FREQ/8000+1)*4)
#define MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS ((MAX_FREQ_FS/1000+1)*4)

/*** IN PACKET SIZES ***/
/* Max packet sizes in bytes. Note the +4 is because we store packet lengths in the buffer */
#define MAX_DEVICE_AUD_PACKET_SIZE_IN_HS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * NUM_USB_CHAN_IN + 4)
#define MAX_DEVICE_AUD_PACKET_SIZE_IN_FS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * NUM_USB_CHAN_IN_FS + 4)

#define MAX_DEVICE_AUD_PACKET_SIZE_IN (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_FS, MAX_DEVICE_AUD_PACKET_SIZE_IN_HS))

/*** OUT PACKET SIZES ***/
#define MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_HS * NUM_USB_CHAN_OUT + 4)
#define MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS (MAX_DEVICE_AUD_PACKET_SIZE_MULT_FS * NUM_USB_CHAN_OUT_FS + 4)

#define MAX_DEVICE_AUD_PACKET_SIZE_OUT (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS))

/*** BUFFER SIZES ***/

#define BUFFER_PACKET_COUNT (4) /* How many packets too allow for in buffer - minimum is 4 */

#define BUFF_SIZE_OUT_HS MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS * BUFFER_PACKET_COUNT
#define BUFF_SIZE_OUT_FS MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS * BUFFER_PACKET_COUNT

#define BUFF_SIZE_IN_HS MAX_DEVICE_AUD_PACKET_SIZE_IN_HS * BUFFER_PACKET_COUNT
#define BUFF_SIZE_IN_FS MAX_DEVICE_AUD_PACKET_SIZE_IN_FS * BUFFER_PACKET_COUNT

#define BUFF_SIZE_OUT MAX(BUFF_SIZE_OUT_HS, BUFF_SIZE_OUT_FS)
#define BUFF_SIZE_IN MAX(BUFF_SIZE_IN_HS, BUFF_SIZE_IN_FS)

#define OUT_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_OUT_HS, MAX_DEVICE_AUD_PACKET_SIZE_OUT_FS))
#define IN_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_HS, MAX_DEVICE_AUD_PACKET_SIZE_IN_FS)*2)

/* Volume and mute tables */
#if (OUT_VOLUME_IN_MIXER == 0) && (OUTPUT_VOLUME_CONTROL == 1)
Expand Down Expand Up @@ -514,6 +479,7 @@ __builtin_unreachable();
{
/* Finished creating packet - commit it to the FIFO */
/* Total samps to write could start at 0 (i.e. no MCLK) so need to check for < 0) */
//printstr("dec : sampsToWrite: "); printintln(sampsToWrite);
if(sampsToWrite <= 0)
{
int speed, wrPtr;
Expand All @@ -525,6 +491,9 @@ __builtin_unreachable();
GET_SHARED_GLOBAL(wrPtr, g_aud_to_host_wrptr);
write_via_xc_ptr(wrPtr, datasize);

// printstr("dec samples: ");
//printintln(totalSampsToWrite);

/* Round up to nearest word - note, not needed for slotsize == 4! */
datasize = (datasize+3) & (~0x3);
assert(datasize >= 0);
Expand All @@ -537,6 +506,9 @@ __builtin_unreachable();
fillLevel += 4+datasize;
assert(fillLevel <= BUFF_SIZE_IN);

//printstr("dec filllevel: ");
//printintln(fillLevel);

/* Do wrap */
if (wrPtr >= aud_to_host_fifo_end)
{
Expand Down Expand Up @@ -811,7 +783,7 @@ void XUA_Buffer_Decouple(chanend c_mix_out
inUnderflow = 1;
SET_SHARED_GLOBAL(g_aud_to_host_rdptr, aud_to_host_fifo_start);
SET_SHARED_GLOBAL(g_aud_to_host_wrptr, aud_to_host_fifo_start);
SET_SHARED_GLOBAL(g_aud_to_host_dptr,aud_to_host_fifo_start+4);
SET_SHARED_GLOBAL(g_aud_to_host_dptr, aud_to_host_fifo_start + 4);
SET_SHARED_GLOBAL(g_aud_to_host_fill_level, 0);

/* Set buffer to send back to zeros buffer */
Expand Down Expand Up @@ -892,6 +864,7 @@ void XUA_Buffer_Decouple(chanend c_mix_out
}

SET_SHARED_GLOBAL(g_freqChange, 0);

asm volatile("outct res[%0],%1"::"r"(buffer_aud_ctl_chan),"r"(XS1_CT_END));

ENABLE_INTERRUPTS();
Expand Down Expand Up @@ -946,6 +919,14 @@ void XUA_Buffer_Decouple(chanend c_mix_out
SET_SHARED_GLOBAL(g_freqChange, 0);
ENABLE_INTERRUPTS();
}
else if(tmp == XUA_EXIT)
{
DISABLE_INTERRUPTS();
SET_SHARED_GLOBAL(g_freqChange, 0);
inct(c_mix_out);
outct(c_mix_out, XS1_CT_END);
return;
}
#endif
}

Expand Down Expand Up @@ -1059,6 +1040,7 @@ void XUA_Buffer_Decouple(chanend c_mix_out
int aud_to_host_rdptr;
GET_SHARED_GLOBAL(aud_to_host_rdptr, g_aud_to_host_rdptr);
inUnderflow = 0;
//nnprintstr("DEC OUT OF UNDERFLOW\n");
aud_to_host_buffer = aud_to_host_rdptr;
}
else
Expand Down
2 changes: 1 addition & 1 deletion lib_xua/src/core/buffer/ep/ep_buffer.xc
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
case XUD_SetData_Select(c_aud_in, ep_aud_in, result):
{
/* Inform stream that buffer sent */
SET_SHARED_GLOBAL0(g_aud_to_host_flag, bufferIn+1);
SET_SHARED_GLOBAL0(g_aud_to_host_flag, bufferIn+1); // TODO other side only checks for boolean
break;
}
#endif
Expand Down
7 changes: 4 additions & 3 deletions lib_xua/src/core/xua_commands.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2011-2021 XMOS LIMITED.
// Copyright 2011-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.

#ifndef __XUA_INTERNAL_CMDS_H__
#define __XUA_INTERNAL_CMDS_H__
#ifndef _XUA_COMMANDS_H_
#define _XUA_COMMANDS_H_

#include "xua.h"

Expand Down Expand Up @@ -30,6 +30,7 @@
#define SET_SAMPLE_FREQ 4
#define SET_STREAM_FORMAT_OUT 8
#define SET_STREAM_FORMAT_IN 9
#define XUA_EXIT 10

#include "dsd_support.h"

Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def test_file(request):

@pytest.fixture(scope="session") # Use same seed for whole run
def test_seed(request):

seed = str(int(time.time()))
# We dont need the following since pytest will print the values of our fixtures on a failure
# capmanager = request.config.pluginmanager.getplugin("capturemanager")
Expand Down
53 changes: 53 additions & 0 deletions tests/test_decouple_in_underflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2022-2023 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
import pytest
import Pyxsim
from Pyxsim import testers
import os
import sys


@pytest.fixture()
def test_file(request):
return str(request.node.fspath)


def do_test(test_file, options, capfd, test_seed, sample_rate):
testname, _ = os.path.splitext(os.path.basename(test_file))

binary = f"{testname}/bin/{testname}.xe"

tester = testers.ComparisonTester(open("pass.expect"))

max_cycles = 15000000

simargs = [
"--max-cycles",
str(max_cycles),
]

result = Pyxsim.run_on_simulator(
binary,
tester=tester,
simargs=simargs,
capfd=capfd,
instTracing=options.enabletracing,
vcdTracing=options.enablevcdtracing,
clean_before_build=True,
build_options=[
"TEST_BUILD_FLAGS="
+ f" -DTEST_SEED={test_seed}"
+ f" -DDEFAULT_FREQ={sample_rate}"
],
)

return result


# TODO parameterise with:
# - usb bus speed
@pytest.mark.parametrize("sample_rate", [48000, 96000, 192000])
def test_decouple_in_underflow(test_file, options, capfd, test_seed, sample_rate):
result = do_test(test_file, options, capfd, test_seed, sample_rate)

assert result
14 changes: 14 additions & 0 deletions tests/test_decouple_in_underflow/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TARGET = xk-audio-316-mc.xn

USED_MODULES = lib_xua lib_logging lib_random

XCC_FLAGS = $(TEST_BUILD_FLAGS) \
-O3 -g -lflash -DXUD_CORE_CLOCK=600 -fxscope -save-temps -DXUD_WEAK_API=1 \
-DDEBUG_PRINT_ENABLE=1 \
-DXASSERT_ENABLE_ASSERTIONS_MAIN=1 \
-DXASSERT_ENABLE_ASSERTIONS=1 \
-DXASSERT_ENABLE_DEBUG=1 \
-DXASSERT_ENABLE_LINE_NUMBERS=1

XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
Loading