diff --git a/.gitignore b/.gitignore
index 86680917..e0379411 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,8 +22,15 @@ test_results.csv
.DS_Store
_README/**
**/pdf/**
+**/.venv/**
*.doctree
sphinx.output
Installs/
.settings
-**/.venv/**
+tests/bin.txt
+tests/log
+tests/test_**/**test_xs2.xn
+tests/test_**/**test_xs3_600.xn
+tests/test_**/**test_xs3_800.xn
+**/venv/**
+*.gtkw
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 02f6a404..e57ab8b5 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,17 @@
lib_xud Change Log
==================
+2.0.0
+-----
+
+ * ADDED: Initial support for XS3A based devices
+ * ADDED: Requirement to define XUD_CORE_CLOCK with xcore core clock speed
+ in MHz
+ * CHANGE: Removed support for XS1-G, and XS1-L (including U series) based
+ devices
+ * RESOLVED: Exception when Endpoint marked as disabled
+ * CHANGE: Use common XN files for tests
+
1.2.0
-----
diff --git a/Jenkinsfile b/Jenkinsfile
index fbcf1b64..f2c0e92c 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -4,11 +4,11 @@ getApproval()
pipeline {
agent {
- label 'x86_64&&brew&&macOS'
+ label 'x86_64 && brew && macOS'
}
environment {
REPO = 'lib_xud'
- VIEW = "${env.JOB_NAME.contains('PR-') ? REPO+'_'+env.CHANGE_TARGET : REPO+'_'+env.BRANCH_NAME}"
+ VIEW = getViewName(REPO)
}
options {
skipDefaultCheckout()
diff --git a/README.rst b/README.rst
index 6dfacdfd..179fc779 100644
--- a/README.rst
+++ b/README.rst
@@ -11,7 +11,7 @@ that allows you to control an USB bus via xCORE ports.
The library provides functionality to act as a USB *device* only.
-This library is aimed primarily for use with xCORE-200 Series or xCORE U-Series devices but it does also support xCORE L-Series devices with the addition of an external USB PHY device.
+This library is for use with xCORE-200 Series or xCORE-AI series devices only, previous generations of xCORE devices are no longer supported.
Features
........
@@ -20,6 +20,12 @@ Features
* Device mode
* Bulk, control, interrupt and isochronous endpoint types supported
+Known Issues
+............
+
+ * Operation on XS3 based devices only supported at 700MHz
+ * SOF tokens are not CRC checked on XS3 based devices (see tests/test_sof_badcrc)
+
Software version and dependencies
.................................
diff --git a/__app_test/.cproject b/__app_test/.cproject
deleted file mode 100644
index ac6478f7..00000000
--- a/__app_test/.cproject
+++ /dev/null
@@ -1,524 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- xmake
-
- all
- true
- true
- true
-
-
- xmake
-
- clean
- true
- true
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/__app_test/.project b/__app_test/.project
deleted file mode 100644
index 64c2ab83..00000000
--- a/__app_test/.project
+++ /dev/null
@@ -1,76 +0,0 @@
-
-
- app_test
-
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
- ?children?
- ?name?=outputEntries\|?children?=?name?=entry\\\\|\\|\||
-
-
- ?name?
-
-
-
- org.eclipse.cdt.make.core.append_environment
- true
-
-
- org.eclipse.cdt.make.core.buildArguments
- CONFIG=Debug
-
-
- org.eclipse.cdt.make.core.buildCommand
- xmake
-
-
- org.eclipse.cdt.make.core.cleanBuildTarget
- clean
-
-
- org.eclipse.cdt.make.core.contents
- org.eclipse.cdt.make.core.activeConfigSettings
-
-
- org.eclipse.cdt.make.core.enableAutoBuild
- false
-
-
- org.eclipse.cdt.make.core.enableCleanBuild
- true
-
-
- org.eclipse.cdt.make.core.enableFullBuild
- true
-
-
- org.eclipse.cdt.make.core.stopOnError
- true
-
-
- org.eclipse.cdt.make.core.useDefaultBuildCmd
- false
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
- com.xmos.cdt.core.XdeProjectNature
-
-
-
diff --git a/__app_test/.xproject b/__app_test/.xproject
deleted file mode 100644
index b564e960..00000000
--- a/__app_test/.xproject
+++ /dev/null
@@ -1 +0,0 @@
-sc_xudXM-002826-SM
\ No newline at end of file
diff --git a/__app_test/Makefile b/__app_test/Makefile
deleted file mode 100644
index 43f28994..00000000
--- a/__app_test/Makefile
+++ /dev/null
@@ -1,66 +0,0 @@
-#The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-
-# This example runs on the XS-L1 usb audio board. It doesn't use any of
-# the audio functionality and just uses the USB functionality of the board
-TARGET = usb_audio_s1
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME = app_test
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-XCC_FLAGS = -Wall -O3 -report -fsubword-select -DUSB_CORE=0 -DGLX -DTEST_MODE_SUPPORT -DXUD_SERIES_SUPPORT=1
-#XCC_FLAGS = -Wall -O2 -report -fsubword-select -DUSB_CORE=1 -DXDK
-
-# The USED_MODULES variable lists other module used by the application.
-
-USED_MODULES = module_usb_shared module_xud
-
-MODULE_LIBRARIES = xud_u_sim
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-
-# Use the main Makefile from module_xmos_common
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
-
-#all: build
-
-#
-# Compile the example
-#
-#build:
-# xcc -O3 -target=XS1-G4B-FB512 -march=xs1b main.xc -o app_test.xe
-
-#
-# Connect the pins together that map to XS1_PORT_1A and XS1_PORT_1B
-# NOTE: Requires the testbench to have been built (src/testbenches/ExampleTestbench)
-#
-run:
- UsbTestbench '--vcd-tracing "-o trace.vcd -ports -pads" ./bin/app_test.xe '
-
-runtrace:
- UsbTestbench '-t --vcd-tracing "-o trace.vcd -ports -pads -cycles -instructions" ./bin/app_test.xe '
- #--vcd-tracing "-o trace.vcd -pads" app_test.xe
-
-#
-# This will give a list of the pins which correspond to the ports
-#
-list:
- xsim --dump-ios app_test.xe
diff --git a/__app_test/README b/__app_test/README
deleted file mode 100755
index 0fd47188..00000000
--- a/__app_test/README
+++ /dev/null
@@ -1,9 +0,0 @@
-This is a xud trest using a xsim testbench.
-
-To build:
- xmake
-
-To run:
- xmake run
-
-Make sure you have built the TB first!
diff --git a/__app_test/README.rst b/__app_test/README.rst
deleted file mode 100644
index 3e0884f9..00000000
--- a/__app_test/README.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-
-================
-
-:scope:
-:description:
-:keywords:
-:boards:
-
-
diff --git a/__app_test/main.xc b/__app_test/main.xc
deleted file mode 100644
index df2a3114..00000000
--- a/__app_test/main.xc
+++ /dev/null
@@ -1,457 +0,0 @@
-// Copyright 2012-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "test.h"
-#include "xc_ptr.h"
-
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
-
-extern xc_ptr char_array_to_xc_ptr(const unsigned char a[]);
-
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-/* USB Port declarations */
-on stdcore[0]: out port p_usb_rst = XS1_PORT_1A;
-on stdcore[0]: clock clk = XS1_CLKBLK_3;
-
-on stdcore[0] : out port p_test = XS1_PORT_1I;
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-char reportBuffer[] = {0, 0, 0, 0};
-
-
-
-/*
- * This function responds to the HID requests - it draws a square using the mouse moving 40 pixels
- * in each direction in sequence every 100 requests.
- */
-void hid(chanend chan_ep1)
-{
- int counter = 0;
- int state = 0;
-
- XUD_ep c_ep1 = XUD_InitEp(chan_ep1);
-
- counter = 0;
- while(1)
- {
- counter++;
- if(counter == 400)
- {
- if(state == 0)
- {
- reportBuffer[1] = 40;
- reportBuffer[2] = 0;
- state+=1;
- }
- else if(state == 1)
- {
- reportBuffer[1] = 0;
- reportBuffer[2] = 40;
- state+=1;
- }
- else if(state == 2)
- {
- reportBuffer[1] = -40;
- reportBuffer[2] = 0;
- state+=1;
- }
- else if(state == 3)
- {
- reportBuffer[1] = 0;
- reportBuffer[2] = -40;
- state = 0;
- }
- counter = 0;
- }
- else
- {
- reportBuffer[1] = 0;
- reportBuffer[2] = 0;
- }
-
- if (XUD_SetBuffer(c_ep1, reportBuffer, 4) < 0)
- {
- XUD_ResetEndpoint(c_ep1, null);
- }
- }
-}
-
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
-
- break;
-
- }
-
- exit(1);
-}
-
-const unsigned char g_rxDataCheck[5] = {1, 1, 1, 1, 1};
-const unsigned char g_txDataCheck[5] = {1, 1, 1, 1, 1};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-xc_ptr p_rxDataCheck;
-xc_ptr p_txDataCheck;
-xc_ptr p_txLength;
-
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- // printstr("##### RX DATA: \n");
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != y)//g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch\n");
- printhexln(b[i]);
- printhexln(g_rxDataCheck[epNum]);
- printhexln(epNum);
- printintln(l);
- return 1;
- }
-
- //g_rxDataCheck[epNum]++;
- read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- x++;
- write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
-
- return 0;
-}
-
-/* Out EP Should receive some data, perform some test process (crc or similar) to check okay */
-/* Answers should be responded to in the IN ep */
-
-#define TYPE_DATA 0
-#define TYPE_CMD 1
-
-#define TYPE_DATA 0
-#define TYPE_CMD_SET_TX_LENGTH 1
-
-
-/* Test packet format:
- * 0: Length
- * 1: type (cmd/data)
- * 2:n-1: Data
- */
-#pragma unsafe arrays
-void TestEp_out(chanend chan_ep, chanend c_sync, int epNum)
-{
- unsigned char buffer[1024];
- int length;
-
- char x;
-
- XUD_ep ep = XUD_InitEp(chan_ep);
-
- int one = 1;
-
- while(1)
- {
-
- length = XUD_GetBuffer(ep, buffer);
-
- /* Update tx length to rx length */
- //asm("stw %0, %1[%2]":: "r" (length), "r"(g_txLength), "r"(epNum));
- //g_txLength[epNum] = length;
- write_via_xc_ptr_indexed(p_txLength, epNum, x);
-
- if(RxDataCheck(buffer, length, epNum))
- {
-
- fail(FAIL_RX_DATAERROR);
- }
-
-
- if(one)
- {
- c_sync <: (int)1;
- one = 0;
- }
- }
-}
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- //buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- buffer[i] = x;
- x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-
-void TestEp_in(chanend chan_ep, chanend c_sync, int epNum)
-{
- unsigned char buffer[1024];
- int y;
- unsigned length;
-
- XUD_ep ep = XUD_InitEp(chan_ep);
-
- c_sync :> y;
- //asm("ldw %0, %1[%2]" : "=r" (length) :"r"(g_txLength), "r" (epNum));
- read_via_xc_ptr_indexed(length, p_txLength, epNum);
-
- //length = g_txLength[epNum];
-
- //printstr("FIRST: ");
- //printintln(length);
-
- SendTxPacket(ep, length, epNum);
-
-
- while(1)
- {
- read_via_xc_ptr_indexed(length, p_txLength, epNum);
-
-
- if((epNum == 2)&&(length!=0))
- {
- }
- SendTxPacket(ep, length, epNum);
- }
-
-}
-
-int TestEp_Control(chanend c_out, chanend c_in, int epNum)
-{
- int slength;
- int length;
-
- XUD_ep c_ep0_out = XUD_InitEp(c_out);
- XUD_ep c_ep0_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
- unsigned char buffer[120];
-
- while(1)
- {
- /* Wait for Setup data */
- slength = XUD_GetSetupBuffer(c_ep0_out, c_ep0_in, buffer);
-
- if(slength != 8)
- {
- printintln(length);
- fail(FAIL_RX_DATAERROR);
- }
-
- if(RxDataCheck(buffer, slength, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
- length = XUD_GetBuffer(c_ep0_out, buffer);
-
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
-
- length = XUD_GetBuffer(c_ep0_out, buffer);
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
- length = XUD_GetBuffer(c_ep0_out, buffer);
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
-
- /* Send 0 length back */
- SendTxPacket(c_ep0_in, 0, epNum);
-
- /* Wait for Setup data */
- slength = XUD_GetSetupBuffer(c_ep0_out, c_ep0_in, buffer);
-
- if(slength != 8)
- {
- printintln(length);
- fail(FAIL_RX_DATAERROR);
- }
-
- if(RxDataCheck(buffer, slength, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
-
- SendTxPacket(c_ep0_in, length, epNum);
- SendTxPacket(c_ep0_in, length, epNum);
- SendTxPacket(c_ep0_in, length, epNum);
-
- length = XUD_GetBuffer(c_ep0_out, buffer);
- if(length != 0)
- {
- fail(FAIL_RX_DATAERROR);
- }
-
-
-
-
- }
-}
-
-void TestEp_select(chanend c_out1, chanend c_out2, chanend c_in1, chanend c_in2)
-{
- XUD_ep ep_out1 = XUD_InitEp(c_out1);
- XUD_ep ep_out2 = XUD_InitEp(c_out2);
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
- XUD_ep ep_in2 = XUD_InitEp(c_in2);
-
- unsigned char buffer1[1024];
- unsigned char buffer1_in[1024];
- unsigned char buffer2[1024];
- unsigned char buffer2_in[1024];
- int tmp;
-
-#pragma unsafe arrays
- for(int i = 0; i < 10; i++)
- {
- int x;
- read_byte_via_xc_ptr_indexed(x, p_txDataCheck, 3);
- buffer1_in[i] = x;
- x++;
- write_byte_via_xc_ptr_indexed(p_txDataCheck,3,x);
- }
-
- XUD_SetReady_Out(ep_out1, buffer1);
- XUD_SetReady_Out(ep_out2, buffer2);
- XUD_SetReady_In(ep_in1, buffer1_in, 10);
-
- /* TODO - reset/CT etc */
- while(1)
- {
- select
- {
- case XUD_GetData_Select(c_out1, ep_out1, tmp):
-
- //doRxData
- if(RxDataCheck(buffer1, tmp, 3))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
- XUD_SetReady_Out(ep_out1, buffer1);
-
- break;
-
- case XUD_GetData_Select(c_out2, ep_out2, tmp):
-
- //doRxData
- if(RxDataCheck(buffer2, tmp, 4))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
- XUD_SetReady_Out(ep_out2, buffer2);
-
- break;
-
- case XUD_SetData_Select(c_in1, ep_in1, tmp):
-
- for (int i = 0; i < 10; i++)
- {
- int x;
- read_byte_via_xc_ptr_indexed(x, p_txDataCheck, 3);
- buffer1_in[i] = x;
- x++;
- write_byte_via_xc_ptr_indexed(p_txDataCheck,3,x);
- }
-
- XUD_SetReady_In(ep_in1, buffer1_in, 10);
-
-
-
- break;
-
- }
- }
-}
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- p_txLength = array_to_xc_ptr(g_txLength);
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- p_usb_rst, clk, -1, XUD_SPEED_HS, null);
-
- TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
-
-#if (TEST_CRC_BAD) || (TEST_ACK)
- TestEp_out(c_ep_out[1], c_sync, 1);
- TestEp_in(c_ep_in[1], c_sync, 1);
- //TestEp_out(c_ep_out[2], c_sync_iso, 2);
- //TestEp_in(c_ep_in[2], c_sync_iso, 2);
- TestEp_select(c_ep_out[3], c_ep_out[4], c_ep_in[3], c_ep_in[4]);
-#endif
- }
-
- return 0;
-}
diff --git a/__app_test/LICENSE.rst b/__app_test_mode/LICENSE.rst
similarity index 100%
rename from __app_test/LICENSE.rst
rename to __app_test_mode/LICENSE.rst
diff --git a/tests/test_bulk_rx_fastpacket/Makefile b/__app_test_mode/Makefile
similarity index 64%
rename from tests/test_bulk_rx_fastpacket/Makefile
rename to __app_test_mode/Makefile
index 83edfc42..99f8226a 100644
--- a/tests/test_bulk_rx_fastpacket/Makefile
+++ b/__app_test_mode/Makefile
@@ -2,13 +2,13 @@
# compiled for. It either refers to an XN file in the source directories
# or a valid argument for the --target option when compiling.
-TARGET = test.xn
+# In this case, the target depends on the build configuration.
+TARGET = XCORE-AI-EXPLORER-NO-DDR.xn
# The APP_NAME variable determines the name of the final .xe file. It should
# not include the .xe postfix. If left blank the name will default to
# the project name
-
-APP_NAME =
+APP_NAME = app_test_mode
# The flags passed to xcc when building the application
# You can also set the following to override flags for a particular language:
@@ -18,29 +18,16 @@ APP_NAME =
# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
+# These flags define multiple build configurations - one for each test mode
+FLAGS_COMMON = -O3 -report -save-temps -DXUD_BYPASS_RESET -DXUD_TEST_SPEED_HS -DXUD_BYPASS_CONNECT
+XCC_FLAGS_TEST_J = $(FLAGS_COMMON) -DTEST_MODE=USB_WINDEX_TEST_J
+XCC_FLAGS_TEST_K = $(FLAGS_COMMON) -DTEST_MODE=USB_WINDEX_TEST_K
+XCC_FLAGS_TEST_SE0_NAK = $(FLAGS_COMMON) -DTEST_MODE=USB_WINDEX_TEST_SE0_NAK
+XCC_FLAGS_TEST_PACKET = $(FLAGS_COMMON) -DTEST_MODE=USB_WINDEX_TEST_PACKET
# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
+USED_MODULES = lib_xud
#=============================================================================
# The following part of the Makefile includes the common build infrastructure
@@ -48,3 +35,5 @@ USED_MODULES = lib_xud
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+
+
diff --git a/__app_test_mode/README.rst b/__app_test_mode/README.rst
new file mode 100644
index 00000000..733fa4fd
--- /dev/null
+++ b/__app_test_mode/README.rst
@@ -0,0 +1,21 @@
+app_test_mode
+=============
+
+
+Summary
+-------
+
+This application provide stand-alone binaries for USB test modes. There are four build configurations, one for each of the four USB Test Modes:
+
+ - Test_SE0_NAK
+ - Test_J
+ - Test_K
+ - Test_Packet
+
+The application enters it's respective test mode from boot, thus removing the requirement to set the mode from a host via the USBHSETT tool.
+
+Note, you not should expect the the device to appear on any USB bus and its probably not advisable to plug into any standard host.
+
+These binaries are most commonly used in device characterisation.
+
+
diff --git a/__app_test_mode/src/XCORE-AI-EXPLORER-NO-DDR.xn b/__app_test_mode/src/XCORE-AI-EXPLORER-NO-DDR.xn
new file mode 100644
index 00000000..b39d5abe
--- /dev/null
+++ b/__app_test_mode/src/XCORE-AI-EXPLORER-NO-DDR.xn
@@ -0,0 +1,60 @@
+
+
+ Board
+ xcore.ai Explorer Kit
+
+
+ tileref tile[2]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/__app_test_mode/src/XCORE-AI-EXPLORER.xn b/__app_test_mode/src/XCORE-AI-EXPLORER.xn
new file mode 100644
index 00000000..0cc287dd
--- /dev/null
+++ b/__app_test_mode/src/XCORE-AI-EXPLORER.xn
@@ -0,0 +1,60 @@
+
+
+ Board
+ xcore.ai Explorer Kit
+
+
+ tileref tile[2]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/__app_test_mode/src/main.xc b/__app_test_mode/src/main.xc
new file mode 100644
index 00000000..5e9f4cdc
--- /dev/null
+++ b/__app_test_mode/src/main.xc
@@ -0,0 +1,30 @@
+// Copyright 2020-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "xud_device.h"
+
+/* Number of Endpoints used by this app */
+#define EP_COUNT_OUT 1
+#define EP_COUNT_IN 1
+
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL};
+
+
+int main()
+{
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
+
+ par
+ {
+ on tile[0]: {
+ XUD_ep ep0_out = XUD_InitEp(c_ep_out[0]);
+
+ XUD_SetTestMode(ep0_out, TEST_MODE);
+ }
+
+ on tile[0]: XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
+ null, epTypeTableOut, epTypeTableIn, XUD_SPEED_HS, XUD_PWR_BUS);
+ }
+
+ return 0;
+}
diff --git a/examples/AN00124_CDC_VCOM_class/Makefile b/examples/AN00124_CDC_VCOM_class/Makefile
index 157952f5..42e269e1 100644
--- a/examples/AN00124_CDC_VCOM_class/Makefile
+++ b/examples/AN00124_CDC_VCOM_class/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_usb_cdc_demo
# The flags passed to xcc when building the application
@@ -19,16 +9,26 @@ APP_NAME = app_usb_cdc_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+BUILD_FLAGS = -O3 -g -report
+
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES -g
-XCC_FLAGS_X200 = -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -g
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud
#=============================================================================
@@ -37,5 +37,3 @@ USED_MODULES = lib_xud
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
-
diff --git a/examples/AN00124_CDC_VCOM_class/src/main.xc b/examples/AN00124_CDC_VCOM_class/src/main.xc
index 2f12c590..993291e5 100644
--- a/examples/AN00124_CDC_VCOM_class/src/main.xc
+++ b/examples/AN00124_CDC_VCOM_class/src/main.xc
@@ -36,7 +36,7 @@ int main() {
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/examples/AN00125_mass_storage_class/Makefile b/examples/AN00125_mass_storage_class/Makefile
index f99c9b9d..35f5d7ef 100644
--- a/examples/AN00125_mass_storage_class/Makefile
+++ b/examples/AN00125_mass_storage_class/Makefile
@@ -1,13 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-TARGET = SLICEKIT-U16
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_mass_storage_demo
# The flags passed to xcc when building the application
@@ -15,14 +9,26 @@ APP_NAME = app_mass_storage_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series
+BUILD_FLAGS = -O3 -report -DUSE_XSCOPE=1 -fxscope -lflash
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES -DUSE_XSCOPE=1 -fxscope -lflash
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud lib_logging(>=2.0.0) lib_xassert(>=3.0.0)
#=============================================================================
@@ -32,4 +38,3 @@ USED_MODULES = lib_xud lib_logging(>=2.0.0) lib_xassert(>=3.0.0)
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
diff --git a/examples/AN00125_mass_storage_class/src/main.xc b/examples/AN00125_mass_storage_class/src/main.xc
index 5503412c..c4e425f3 100644
--- a/examples/AN00125_mass_storage_class/src/main.xc
+++ b/examples/AN00125_mass_storage_class/src/main.xc
@@ -36,7 +36,7 @@ int main()
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/examples/AN00126_printer_class/Makefile b/examples/AN00126_printer_class/Makefile
index eb235012..271b2ad9 100644
--- a/examples/AN00126_printer_class/Makefile
+++ b/examples/AN00126_printer_class/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_printer_demo
# The flags passed to xcc when building the application
@@ -19,16 +9,26 @@ APP_NAME = app_printer_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+BUILD_FLAGS = -O3 -report -DUSE_XSCOPE=1 -fxscope
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES -DUSE_XSCOPE=1 -fxscope
-XCC_FLAGS_X200 = -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSE_XSCOPE=1 -fxscope
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud lib_logging
#=============================================================================
@@ -38,4 +38,3 @@ USED_MODULES = lib_xud lib_logging
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
diff --git a/examples/AN00126_printer_class/src/main.xc b/examples/AN00126_printer_class/src/main.xc
index 8cf06802..0ecedeb4 100644
--- a/examples/AN00126_printer_class/src/main.xc
+++ b/examples/AN00126_printer_class/src/main.xc
@@ -84,7 +84,7 @@ int main()
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/examples/AN00127_video_class/Makefile b/examples/AN00127_video_class/Makefile
index dce383df..c5f24dc4 100644
--- a/examples/AN00127_video_class/Makefile
+++ b/examples/AN00127_video_class/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_video_demo
# The flags passed to xcc when building the application
@@ -19,16 +9,26 @@ APP_NAME = app_video_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+BUILD_FLAGS = -O3 -report
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-XCC_FLAGS_X200 = -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud lib_logging
#=============================================================================
@@ -38,4 +38,3 @@ USED_MODULES = lib_xud lib_logging
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
diff --git a/examples/AN00127_video_class/src/main.xc b/examples/AN00127_video_class/src/main.xc
index cd78905f..0a5eed46 100644
--- a/examples/AN00127_video_class/src/main.xc
+++ b/examples/AN00127_video_class/src/main.xc
@@ -37,7 +37,7 @@ int main() {
{
on USB_TILE: XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/examples/AN00129_hid_class/Makefile b/examples/AN00129_hid_class/Makefile
index 8583bc54..e8effa65 100644
--- a/examples/AN00129_hid_class/Makefile
+++ b/examples/AN00129_hid_class/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_hid_mouse_demo
# The flags passed to xcc when building the application
@@ -19,23 +9,32 @@ APP_NAME = app_hid_mouse_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+# These flags define two build configurations - one for xCORE-200 and one for
+# the xCORE.AI series.
+BUILD_FLAGS = -O3 -report
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-XCC_FLAGS_X200 = -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_200 = $(BUILD_FLAGS) -DXUD_CORE_CLOCK=500
+XCC_FLAGS_AI = $(BUILD_FLAGS) -DXUD_CORE_CLOCK=600
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+# In this case, the target depends on the build configuration.
+ifeq ($(CONFIG),AI)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
#=============================================================================
# The following part of the Makefile includes the common build infrastructure
# for compiling XMOS applications. You should not need to edit below here.
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
-
diff --git a/examples/AN00129_hid_class/doc/rst/AN00129.rst b/examples/AN00129_hid_class/doc/rst/AN00129.rst
index fadec4df..18582b7e 100644
--- a/examples/AN00129_hid_class/doc/rst/AN00129.rst
+++ b/examples/AN00129_hid_class/doc/rst/AN00129.rst
@@ -70,15 +70,9 @@ To start using the USB library, you need to add ``lib_xud`` to your ``Makefile``
USED_MODULES = ... lib_xud
-You also have to add a define to the build to say which variant of the
-USB library you want. In this case, the example is for the U-Series
-USB library. So the following is in the ``Makefile``::
+You can then access the USB functions in your source code via the xud_device.h header file::
- XCC_FLAGS = ... -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-You can then access the USB functions in your source code via the usb.h header file::
-
- #include
+ #include "xud_device.h"
The application main() function
...............................
@@ -197,7 +191,7 @@ USB HID Class requests
Inside ``endpoint0.xc`` there is a function for handling the USB HID device class specific requests. The code for handling these requests is shown as follows:
.. literalinclude:: endpoint0.xc
- :lines: 167-224
+ :lines: 142-198
These HID specific requests are implemented by the application as they do not form part of the standard requests which have to be accepted by all device classes via endpoint0.
@@ -209,7 +203,7 @@ USB HID Class Endpoint0
The function ``Endpoint0()`` contains the code for dealing with device requests made from the host to the standard endpoint0 which is present in all USB devices. In addition to requests required for all devices, the code handles the requests specific to the HID class.
.. literalinclude:: endpoint0.xc
- :lines: 260-306
+ :lines: 201-301
|newpage|
@@ -219,7 +213,7 @@ Reporting HID mouse data to the host
The application endpoint for reporting mouse movement data to the host machine is implemented in the file ``main.xc``. This is contained within the function ``hid_mouse()`` which is shown below:
.. literalinclude:: main.xc
- :lines: 22-81
+ :lines: 24-80
From this you can see the following.
diff --git a/examples/AN00129_hid_class/src/XCORE-AI-EXPLORER-NO-DDR.xn b/examples/AN00129_hid_class/src/XCORE-AI-EXPLORER-NO-DDR.xn
new file mode 100644
index 00000000..b39d5abe
--- /dev/null
+++ b/examples/AN00129_hid_class/src/XCORE-AI-EXPLORER-NO-DDR.xn
@@ -0,0 +1,60 @@
+
+
+ Board
+ xcore.ai Explorer Kit
+
+
+ tileref tile[2]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/AN00129_hid_class/src/XCORE-AI-EXPLORER.xn b/examples/AN00129_hid_class/src/XCORE-AI-EXPLORER.xn
new file mode 100644
index 00000000..0cc287dd
--- /dev/null
+++ b/examples/AN00129_hid_class/src/XCORE-AI-EXPLORER.xn
@@ -0,0 +1,60 @@
+
+
+ Board
+ xcore.ai Explorer Kit
+
+
+ tileref tile[2]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/AN00129_hid_class/src/endpoint0.xc b/examples/AN00129_hid_class/src/endpoint0.xc
index 60bbafee..c0050f67 100644
--- a/examples/AN00129_hid_class/src/endpoint0.xc
+++ b/examples/AN00129_hid_class/src/endpoint0.xc
@@ -6,33 +6,13 @@
#include
#include "xud_device.h"
#include "hid.h"
+#include "hid_defs.h"
/* USB HID Device Product Defines */
#define BCD_DEVICE 0x1000
#define VENDOR_ID 0x20B1
#define PRODUCT_ID 0x1010
-/* Standard HID Request Defines */
-
-/* 7. Requests */
-
-/* 7.1 Standard Requests - Class Descriptor Types - High byte of wValue
- * The following defines valid types of Class descriptors */
-
-#define HID_HID 0x2100
-#define HID_REPORT 0x2200
-#define HID_PHYSICAL_DESCRIPTOR 0x2300
-/* 0x24 - 0x2F: Reserved */
-
-/* 7.2 Class-Specific Requests - bRequest values */
-#define HID_GET_REPORT 0x01 /* Mandatory */
-#define HID_GET_IDLE 0x02
-#define HID_GET_PROTOCOL 0x03 /* Required only for boot devices */
-/* Ox04 - 0x08 reserved */
-#define HID_SET_REPORT 0x09
-#define HID_SET_IDLE 0x0A
-#define HID_SET_PROTOCOL 0x0B /* Required only for boot devices */
-
/* Device Descriptor */
static unsigned char devDesc[] =
{
@@ -81,12 +61,12 @@ static unsigned char cfgDesc[] = {
0x09, /* 0 bLength. Note this is currently
replicated in hidDescriptor[] below */
0x21, /* 1 bDescriptorType (HID) */
- 0x10, /* 2 bcdHID */
- 0x11, /* 3 bcdHID */
+ 0x11, /* 2 bcdHID */
+ 0x01, /* 3 bcdHID */
0x00, /* 4 bCountryCode */
0x01, /* 5 bNumDescriptors */
0x22, /* 6 bDescriptorType[0] (Report) */
- 0x48, /* 7 wDescriptorLength */
+ 0x32, /* 7 wDescriptorLength */
0x00, /* 8 wDescriptorLength */
0x07, /* 0 bLength */
@@ -95,62 +75,51 @@ static unsigned char cfgDesc[] = {
0x03, /* 3 bmAttributes */
0x40, /* 4 wMaxPacketSize */
0x00, /* 5 wMaxPacketSize */
- 0x01 /* 6 bInterval */
+ 0x0a /* 6 bInterval */
};
static unsigned char hidDescriptor[] =
{
0x09, /* 0 bLength */
0x21, /* 1 bDescriptorType (HID) */
- 0x10, /* 2 bcdHID */
- 0x11, /* 3 bcdHID */
+ 0x11, /* 2 bcdHID */
+ 0x01, /* 3 bcdHID */
0x00, /* 4 bCountryCode */
0x01, /* 5 bNumDescriptors */
0x22, /* 6 bDescriptorType[0] (Report) */
- 0x48, /* 7 wDescriptorLength */
+ 0x32, /* 7 wDescriptorLength */
0x00, /* 8 wDescriptorLength */
};
/* HID Report Descriptor */
static unsigned char hidReportDescriptor[] =
{
- 0x05, 0x01, // Usage page (desktop)
- 0x09, 0x02, // Usage (mouse)
- 0xA1, 0x01, // Collection (app)
- 0x05, 0x09, // Usage page (buttons)
- 0x19, 0x01,
- 0x29, 0x03,
- 0x15, 0x00, // Logical min (0)
- 0x25, 0x01, // Logical max (1)
- 0x95, 0x03, // Report count (3)
- 0x75, 0x01, // Report size (1)
- 0x81, 0x02, // Input (Data, Absolute)
- 0x95, 0x01, // Report count (1)
- 0x75, 0x05, // Report size (5)
- 0x81, 0x03, // Input (Absolute, Constant)
- 0x05, 0x01, // Usage page (desktop)
- 0x09, 0x01, // Usage (pointer)
- 0xA1, 0x00, // Collection (phys)
- 0x09, 0x30, // Usage (x)
- 0x09, 0x31, // Usage (y)
- 0x15, 0x81, // Logical min (-127)
- 0x25, 0x7F, // Logical max (127)
- 0x75, 0x08, // Report size (8)
- 0x95, 0x02, // Report count (2)
- 0x81, 0x06, // Input (Data, Rel=0x6, Abs=0x2)
- 0xC0, // End collection
- 0x09, 0x38, // Usage (Wheel)
- 0x95, 0x01, // Report count (1)
- 0x81, 0x02, // Input (Data, Relative)
- 0x09, 0x3C, // Usage (Motion Wakeup)
- 0x15, 0x00, // Logical min (0)
- 0x25, 0x01, // Logical max (1)
- 0x75, 0x01, // Report size (1)
- 0x95, 0x01, // Report count (1)
- 0xB1, 0x22, // Feature (No preferred, Variable)
- 0x95, 0x07, // Report count (7)
- 0xB1, 0x01, // Feature (Constant)
- 0xC0 // End collection
+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
+ 0x09, 0x02, /* Usage (Mouse) */
+ 0xA1, 0x01, /* Collection (Application) */
+ 0x09, 0x01, /* Usage (Pointer) */
+ 0xA1, 0x00, /* Collection (Physical) */
+ 0x05, 0x09, /* Usage Page (Buttons) */
+ 0x19, 0x01, /* Usage Minimum (01) */
+ 0x29, 0x03, /* Usage Maximum (03) */
+ 0x15, 0x00, /* Logical Minimum (0) */
+ 0x25, 0x01, /* Logical Maximum (1) */
+ 0x95, 0x03, /* Report Count (3) */
+ 0x75, 0x01, /* Report Size (1) */
+ 0x81, 0x02, /* Input (Data,Variable,Absolute); 3 button bits */
+ 0x95, 0x01, /* Report Count (1) */
+ 0x75, 0x05, /* Report Size (5) */
+ 0x81, 0x01, /* Input(Constant); 5 bit padding */
+ 0x05, 0x01, /* Usage Page (Generic Desktop) */
+ 0x09, 0x30, /* Usage (X) */
+ 0x09, 0x31, /* Usage (Y) */
+ 0x15, 0x81, /* Logical Minimum (-127) */
+ 0x25, 0x7F, /* Logical Maximum (127) */
+ 0x75, 0x08, /* Report Size (8) */
+ 0x95, 0x02, /* Report Count (2) */
+ 0x81, 0x06, /* Input (Data,Variable,Relative); 2 position bytes (X & Y) */
+ 0xC0, /* End Collection */
+ 0xC0 /* End Collection */
};
unsafe{
@@ -164,7 +133,10 @@ static char * unsafe stringDescriptors[]=
};
}
-extern unsigned char g_reportBuffer[4];
+/* It is essential that HID_REPORT_BUFFER_SIZE, defined in hid_defs.h, matches the */
+/* infered length of the report described in hidReportDescriptor above. In this case */
+/* it is three bytes, three button bits padded to a byte, plus a byte each for X & Y */
+unsigned char g_reportBuffer[HID_REPORT_BUFFER_SIZE] = {0, 0, 0};
/* HID Class Requests */
XUD_Result_t HidInterfaceClassRequests(XUD_ep c_ep0_out, XUD_ep c_ep0_in, USB_SetupPacket_t sp)
@@ -327,11 +299,3 @@ void Endpoint0(chanend chan_ep0_out, chanend chan_ep0_in)
}
}
}
-//:
-
-
-
-
-
-
-
diff --git a/examples/AN00129_hid_class/src/hid.h b/examples/AN00129_hid_class/src/hid.h
deleted file mode 100644
index a6df0f11..00000000
--- a/examples/AN00129_hid_class/src/hid.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2015-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * @brief Defines from USB Device Class Definition for Human Interface Devices Specification
- */
-
-/* 7. Requests */
-
-/* 7.1 Standard Requests - Class Descriptor Types - High byte of wValue
- * The following defines valid types of Class descriptors */
-#define HID_HID 0x2100
-#define HID_REPORT 0x2200
-#define HID_PHYSICAL_DESCRIPTOR 0x2300
-/*0x24 - 0x2F: Reserved */
-
-/* 7.2 Class-Specific Requests - bRequest values */
-#define HID_GET_REPORT 0x01 /* Mandatory */
-#define HID_GET_IDLE 0x02
-#define HID_GET_PROTOCOL 0x03 /* Required only for boot devices */
-/* Ox04 - 0x08 reserved */
-#define HID_SET_REPORT 0x09
-#define HID_SET_IDLE 0x0A
-#define HID_SET_PROTOCOL 0x0B /* Required only for boot devices */
diff --git a/examples/AN00129_hid_class/src/hid_defs.h b/examples/AN00129_hid_class/src/hid_defs.h
new file mode 100644
index 00000000..d246a16e
--- /dev/null
+++ b/examples/AN00129_hid_class/src/hid_defs.h
@@ -0,0 +1,14 @@
+// Copyright 2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+/*
+ * @brief Defines shared data for HID example threads.
+ */
+#ifndef HID_DEFS_H
+#define HID_DEFS_H
+
+/* Global report buffer */
+#define HID_REPORT_BUFFER_SIZE 3
+extern char g_reportBuffer[HID_REPORT_BUFFER_SIZE];
+
+#endif // HID_DEFS_H
diff --git a/examples/AN00129_hid_class/src/main.xc b/examples/AN00129_hid_class/src/main.xc
index f3296377..439b2147 100644
--- a/examples/AN00129_hid_class/src/main.xc
+++ b/examples/AN00129_hid_class/src/main.xc
@@ -1,6 +1,7 @@
// Copyright 2015-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#include "xud_device.h"
+#include "hid_defs.h"
/* Number of Endpoints used by this app */
#define EP_COUNT_OUT 1
@@ -15,9 +16,6 @@ XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, X
/* Prototype for Endpoint0 function in endpoint0.xc */
void Endpoint0(chanend c_ep0_out, chanend c_ep0_in);
-/* Global report buffer, global since used by Endpoint0 core */
-unsigned char g_reportBuffer[4] = {0, 0, 0, 0};
-
/*
* This function responds to the HID requests
* - It draws a square using the mouse moving 40 pixels in each direction
@@ -25,77 +23,80 @@ unsigned char g_reportBuffer[4] = {0, 0, 0, 0};
*/
void hid_mouse(chanend chan_ep_hid)
{
- int counter = 0;
- int state = 0;
-
+ unsigned int counter = 0;
+ enum {RIGHT, DOWN, LEFT, UP} state = RIGHT;
+
XUD_ep ep_hid = XUD_InitEp(chan_ep_hid);
- while (1)
+ for(;;)
{
- /* Unsafe region so we can use shared memory. */
- unsafe {
- char * unsafe p_reportBuffer = g_reportBuffer;
- int x;
- p_reportBuffer[1] = 0;
- p_reportBuffer[2] = 0;
-
/* Move the pointer around in a square (relative) */
- counter++;
- if (counter >= 500)
+ if(counter++ >= 500)
{
- counter = 0;
- if (state == 0)
- {
- p_reportBuffer[1] = 40;
- p_reportBuffer[2] = 0;
- state+=1;
- }
- else if (state == 1)
- {
- p_reportBuffer[1] = 0;
- p_reportBuffer[2] = 40;
- state+=1;
- }
- else if (state == 2)
- {
- p_reportBuffer[1] = -40;
- p_reportBuffer[2] = 0;
- state+=1;
+ int x;
+ int y;
+
+ switch(state) {
+ case RIGHT:
+ x = 40;
+ y = 0;
+ state = DOWN;
+ break;
+
+ case DOWN:
+ x = 0;
+ y = 40;
+ state = LEFT;
+ break;
+
+ case LEFT:
+ x = -40;
+ y = 0;
+ state = UP;
+ break;
+
+ case UP:
+ default:
+ x = 0;
+ y = -40;
+ state = RIGHT;
+ break;
}
- else if (state == 3)
- {
- p_reportBuffer[1] = 0;
- p_reportBuffer[2] = -40;
- state = 0;
+
+ /* Unsafe region so we can use shared memory. */
+ unsafe {
+ /* global buffer 'g_reportBuffer' defined in hid_defs.h */
+ char * unsafe p_reportBuffer = g_reportBuffer;
+
+ p_reportBuffer[1] = x;
+ p_reportBuffer[2] = y;
+
+ /* Send the buffer off to the host. Note this will return when complete */
+ XUD_SetBuffer(ep_hid, (char *) p_reportBuffer, sizeof(g_reportBuffer));
+ counter = 0;
}
}
-
- /* Send the buffer off to the host. Note this will return when complete */
- XUD_SetBuffer(ep_hid, (char *) p_reportBuffer, 4);
- }
}
}
-
/* The main function runs three cores: the XUD manager, Endpoint 0, and a HID endpoint. An array of
* channels is used for both IN and OUT endpoints, endpoint zero requires both, HID requires just an
* IN endpoint to send HID reports to the host.
*/
int main()
{
- chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
+ chan c_ep_out[EP_COUNT_OUT];
+ chan c_ep_in[EP_COUNT_IN];
par
{
- on tile[0]: XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
-
- on tile[0]: Endpoint0(c_ep_out[0], c_ep_in[0]);
+ on tile[0]: XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN, null,
+ epTypeTableOut, epTypeTableIn, XUD_SPEED_HS, XUD_PWR_BUS);
- on tile[0]: hid_mouse(c_ep_in[1]);
+ on tile[0]: Endpoint0(c_ep_out[0], c_ep_in[0]);
+ on tile[0]: hid_mouse(c_ep_in[1]);
}
return 0;
diff --git a/examples/AN00129_hid_class/src/mic_array_ref.xn b/examples/AN00129_hid_class/src/mic_array_ref.xn
deleted file mode 100644
index dc790657..00000000
--- a/examples/AN00129_hid_class/src/mic_array_ref.xn
+++ /dev/null
@@ -1,84 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/examples/AN00131_CDC_EDC_class/Makefile b/examples/AN00131_CDC_EDC_class/Makefile
index dab73420..d7c0b808 100644
--- a/examples/AN00131_CDC_EDC_class/Makefile
+++ b/examples/AN00131_CDC_EDC_class/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_cdc_edc_demo
# The flags passed to xcc when building the application
@@ -19,16 +9,26 @@ APP_NAME = app_cdc_edc_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+BUILD_FLAGS = -Wall -O3 -report -DUSE_XSCOPE=1 -fxscope
-XCC_FLAGS_U = -Wall -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES -DUSE_XSCOPE=1 -fxscope
-XCC_FLAGS_X200 = -Wall -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES -DUSE_XSCOPE=1 -fxscope
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud
#=============================================================================
@@ -38,4 +38,3 @@ USED_MODULES = lib_xud
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
diff --git a/examples/AN00131_CDC_EDC_class/src/main.xc b/examples/AN00131_CDC_EDC_class/src/main.xc
index 325fb689..c06fd8dc 100644
--- a/examples/AN00131_CDC_EDC_class/src/main.xc
+++ b/examples/AN00131_CDC_EDC_class/src/main.xc
@@ -35,7 +35,7 @@ int main() {
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/examples/AN00132_image_class/Makefile b/examples/AN00132_image_class/Makefile
index 9719d880..dc2fd25a 100644
--- a/examples/AN00132_image_class/Makefile
+++ b/examples/AN00132_image_class/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_usb_image_demo
# The flags passed to xcc when building the application
@@ -19,16 +9,26 @@ APP_NAME = app_usb_image_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+BUILD_FLAGS = -O3 -report
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-XCC_FLAGS_X200 = -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud
SOURCE_DIRS = src
@@ -40,4 +40,3 @@ SOURCE_DIRS = src
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
diff --git a/examples/AN00132_image_class/src/main.xc b/examples/AN00132_image_class/src/main.xc
index 2d78b957..00704a51 100644
--- a/examples/AN00132_image_class/src/main.xc
+++ b/examples/AN00132_image_class/src/main.xc
@@ -166,7 +166,7 @@ int main()
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/examples/AN00135_test_and_measurement_class/Makefile b/examples/AN00135_test_and_measurement_class/Makefile
index 3cf183ab..65052e14 100644
--- a/examples/AN00135_test_and_measurement_class/Makefile
+++ b/examples/AN00135_test_and_measurement_class/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_test_and_measurement
# The flags passed to xcc when building the application
@@ -19,16 +9,26 @@ APP_NAME = app_test_and_measurement
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+BUILD_FLAGS = -O3 -report
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-XCC_FLAGS_X200 = -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud lib_logging
#=============================================================================
@@ -38,4 +38,3 @@ USED_MODULES = lib_xud lib_logging
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
diff --git a/examples/AN00135_test_and_measurement_class/host/usbtmc_test.py b/examples/AN00135_test_and_measurement_class/host/usbtmc_test.py
index 84a48ac4..b5190dc6 100644
--- a/examples/AN00135_test_and_measurement_class/host/usbtmc_test.py
+++ b/examples/AN00135_test_and_measurement_class/host/usbtmc_test.py
@@ -5,27 +5,28 @@
import usb.util
# Find XMOS USBTMC test device
-dev = usb.core.find(idVendor=0x20b1, idProduct=0x2337)
+dev = usb.core.find(idVendor=0x20B1, idProduct=0x2337)
import usbtmc
-instr = usbtmc.Instrument(0x20b1, 0x2337)
+
+instr = usbtmc.Instrument(0x20B1, 0x2337)
# Test SCPI commands
# ------------------
-print('Starting basic SCPI commands testing...')
-print ('')
+print("Starting basic SCPI commands testing...")
+print("")
# Request device identification details
print(instr.ask("*IDN?"))
# Reset device; this command is not implemented!
print(instr.ask("*RST"))
-print ('')
+print("")
# Fetch DC voltage value from the device
print(instr.ask("*MEASure:VOLTage:DC?"))
-print('Exiting...')
+print("Exiting...")
diff --git a/examples/AN00135_test_and_measurement_class/src/main.xc b/examples/AN00135_test_and_measurement_class/src/main.xc
index 61b2c849..ef520060 100644
--- a/examples/AN00135_test_and_measurement_class/src/main.xc
+++ b/examples/AN00135_test_and_measurement_class/src/main.xc
@@ -28,7 +28,7 @@ int main()
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/examples/AN00136_vendor_specific/Makefile b/examples/AN00136_vendor_specific/Makefile
index 73fe84b2..896f389f 100644
--- a/examples/AN00136_vendor_specific/Makefile
+++ b/examples/AN00136_vendor_specific/Makefile
@@ -1,17 +1,7 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-# In this case, the target depends on the build configuration.
-ifeq ($(CONFIG),X200)
-TARGET = XCORE-200-EXPLORER
-else
-TARGET = SLICEKIT-U16
-endif
-
# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
+# not include the .xe postfix. If left blank the name will default to
# the project name
+
APP_NAME = app_vendor_specific_demo
# The flags passed to xcc when building the application
@@ -19,16 +9,26 @@ APP_NAME = app_vendor_specific_demo
#
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
+# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
-# These flags define two build configurations - one for U-series and one for
-# the xCORE-200 series.
+BUILD_FLAGS = -O3 -report
-XCC_FLAGS_U = -O3 -report -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-XCC_FLAGS_X200 = -O3 -report -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcore200 = $(BUILD_FLAGS) -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+XCC_FLAGS_xcoreai = $(BUILD_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+
+ifeq ($(CONFIG),xcoreai)
+TARGET = XCORE-AI-EXPLORER
+else
+TARGET = XCORE-200-EXPLORER
+endif
+
+# The USED_MODULES variable lists other module used by the application.
-# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud
SOURCE_DIRS = src
@@ -41,4 +41,3 @@ INCLUDE_DIRS = src
XMOS_MAKE_PATH ?= ../..
include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
-
diff --git a/examples/AN00136_vendor_specific/src/main.xc b/examples/AN00136_vendor_specific/src/main.xc
index 2a79249a..1d70c7dd 100644
--- a/examples/AN00136_vendor_specific/src/main.xc
+++ b/examples/AN00136_vendor_specific/src/main.xc
@@ -92,7 +92,7 @@ int main()
{
on USB_TILE: XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
diff --git a/lib_xud/api/xud.h b/lib_xud/api/xud.h
index ff29dbc8..d5517d84 100644
--- a/lib_xud/api/xud.h
+++ b/lib_xud/api/xud.h
@@ -4,60 +4,25 @@
* \brief User defines and functions for XMOS USB Device library
*/
-#ifndef __xud_h__
-#define __xud_h__
+#ifndef _XUD_H_
+#define _XUD_H_
+#include
-#ifndef XUD_U_SERIES
-#define XUD_U_SERIES 1
-#endif
-
-#ifndef XUD_L_SERIES
-#define XUD_L_SERIES 2
-#endif
-
-#ifndef XUD_G_SERIES
-#define XUD_G_SERIES 3
-#endif
-
-#ifndef XUD_X200_SERIES
-#define XUD_X200_SERIES 4
-#endif
-
-#if XUD_SERIES_SUPPORT==1
-#ifndef ARCH_S
-#define ARCH_S 1
-#endif
-#ifndef ARCH_L
-#define ARCH_L 1
-#endif
-#endif
-
-#if XUD_SERIES_SUPPORT==2
-#ifndef ARCH_L
-#define ARCH_L 1
-#endif
-#endif
-
-#if XUD_SERIES_SUPPORT==3
-#ifndef ARCH_G
-#define ARCH_G 1
-#endif
-#endif
-
-#if XUD_SERIES_SUPPORT==4
-#ifndef ARCH_L
-#define ARCH_L 1
-#endif
-#ifndef ARCH_X200
-#define ARCH_X200 1
-#endif
+#if defined(__XS3A__)
+#define XUD_OPT_SOFTCRC5 (1)
+#else
+#define XUD_OPT_SOFTCRC5 (0)
#endif
#ifdef __xud_conf_h_exists__
#include "xud_conf.h"
#endif
+#ifndef XUD_STARTUP_ADDRESS
+#define XUD_STARTUP_ADDRESS (0)
+#endif
+
#ifndef __ASSEMBLER__
#include
@@ -69,49 +34,17 @@
#define USB_TILE tile[0]
#endif
-#if defined(PORT_USB_CLK)
-
- /* Ports declared in the .xn file. Automatically detect device series */
- #if defined(PORT_USB_RX_READY)
- #if !defined(XUD_SERIES_SUPPORT)
- #define XUD_SERIES_SUPPORT XUD_U_SERIES
- #endif
-
-#if (XUD_SERIES_SUPPORT != XUD_U_SERIES) && (XUD_SERIES_SUPPORT != XUD_X200_SERIES)
- #error (XUD_SERIES_SUPPORT != XUD_U_SERIES) with PORT_USB_RX_READY defined
- #endif
-
- #else
- #if !defined(XUD_SERIES_SUPPORT)
- #define XUD_SERIES_SUPPORT XUD_L_SERIES
- #endif
-
-#if (XUD_SERIES_SUPPORT != XUD_L_SERIES) && (XUD_SERIES_SUPPORT != XUD_G_SERIES) && (XUD_SERIES_SUPPORT != XUD_X200_SERIES)
- #error (XUD_SERIES_SUPPORT != XUD_L_SERIES) when PORT_USB_RX_READY not defined
- #endif
-
- #endif
-
-#else // PORT_USB_CLK
-
- #if !defined(XUD_SERIES_SUPPORT)
- // Default to U-Series if no series is defined
- #define XUD_SERIES_SUPPORT XUD_U_SERIES
- #endif
+#ifndef REF_CLK_FREQ
+#define REF_CLK_FREQ 100
+#endif
- /* Ports have not been defined in the .xn file */
+#ifndef XUD_CORE_CLOCK
+#warning XUD_CORE_CLOCK not defined, using default (700MHz)
+#define XUD_CORE_CLOCK (700)
+#endif
- #if (XUD_SERIES_SUPPORT == XUD_U_SERIES)
- #define PORT_USB_CLK on USB_TILE: XS1_PORT_1J
- #define PORT_USB_TXD on USB_TILE: XS1_PORT_8A
- #define PORT_USB_RXD on USB_TILE: XS1_PORT_8C
- #define PORT_USB_TX_READYOUT on USB_TILE: XS1_PORT_1K
- #define PORT_USB_TX_READYIN on USB_TILE: XS1_PORT_1H
- #define PORT_USB_RX_READY on USB_TILE: XS1_PORT_1M
- #define PORT_USB_FLAG0 on USB_TILE: XS1_PORT_1N
- #define PORT_USB_FLAG1 on USB_TILE: XS1_PORT_1O
- #define PORT_USB_FLAG2 on USB_TILE: XS1_PORT_1P
- #elif (XUD_SERIES_SUPPORT == XUD_X200_SERIES)
+#if !defined(PORT_USB_CLK)
+ /* Ports have not been defined in the .xn file */
#define PORT_USB_CLK on USB_TILE: XS1_PORT_1J
#define PORT_USB_TXD on USB_TILE: XS1_PORT_8A
#define PORT_USB_RXD on USB_TILE: XS1_PORT_8B
@@ -120,18 +53,10 @@
#define PORT_USB_RX_READY on USB_TILE: XS1_PORT_1I
#define PORT_USB_FLAG0 on USB_TILE: XS1_PORT_1E
#define PORT_USB_FLAG1 on USB_TILE: XS1_PORT_1F
- #define PORT_USB_FLAG2 on USB_TILE: XS1_PORT_1G
- #else
- #define PORT_USB_CLK on USB_TILE: XS1_PORT_1H
- #define PORT_USB_REG_WRITE on USB_TILE: XS1_PORT_8C
- #define PORT_USB_REG_READ on USB_TILE: XS1_PORT_8D
- #define PORT_USB_TXD on USB_TILE: XS1_PORT_8A
- #define PORT_USB_RXD on USB_TILE: XS1_PORT_8B
- #define PORT_USB_STP_SUS on USB_TILE: XS1_PORT_1E
- #define PORT_USB_FLAG0 on USB_TILE: XS1_PORT_1N
- #define PORT_USB_FLAG1 on USB_TILE: XS1_PORT_1O
- #define PORT_USB_FLAG2 on USB_TILE: XS1_PORT_1P
- #endif
+ #ifdef __XS2A__
+ /* XS2A has an additional flag port */
+ #define PORT_USB_FLAG2 on USB_TILE: XS1_PORT_1G
+ #endif
#endif // PORT_USB_CLK
/**
@@ -165,7 +90,8 @@ typedef unsigned int XUD_ep;
typedef enum XUD_BusSpeed
{
XUD_SPEED_FS = 1,
- XUD_SPEED_HS = 2
+ XUD_SPEED_HS = 2,
+ XUD_SPEED_KILL = 3
} XUD_BusSpeed_t;
typedef enum XUD_PwrConfig
@@ -212,14 +138,6 @@ typedef enum XUD_Result
* endpoints, the second array contains the
* endpoint types for each of the IN
* endpoints.
- * \param p_usb_rst The port to used to connect to an external phy reset line.
- * Should be ``null`` for U-Series.
- * \param clk The clock block to use for the p_usb_rst port -
- * this should not be clock block 0. Should be ``null`` for U-Series.
- * \param rstMask The mask to use when taking an external phy into/out of reset. The mask is
- * ORed into the port to disable reset, and unset when
- * deasserting reset. Use '-1' as a default mask if this
- * port is not shared.
* \param desiredSpeed This parameter specifies what speed the device will attempt to run at
* i.e. full-speed (ie 12Mbps) or high-speed (480Mbps) if supported
* by the host. Pass ``XUD_SPEED_HS`` if high-speed is desired or ``XUD_SPEED_FS``
@@ -229,14 +147,11 @@ typedef enum XUD_Result
* Valid values are XUD_PWR_SELF and XUD_PWR_BUS.
*
*/
-int XUD_Main(/*tileref * unsafe usbtileXUD_res_t &xudres, */ chanend c_epOut[], int noEpOut,
-
+int XUD_Main(/*tileref * unsafe usbtileXUD_res_t &xudres, */
+ chanend c_epOut[], int noEpOut,
chanend c_epIn[], int noEpIn,
NULLABLE_RESOURCE(chanend, c_sof),
XUD_EpType epTypeTableOut[], XUD_EpType epTypeTableIn[],
- NULLABLE_RESOURCE(out port, p_usb_rst),
- NULLABLE_RESOURCE(clock, clk),
- unsigned rstMask,
XUD_BusSpeed_t desiredSpeed,
XUD_PwrConfig pwrConfig);
#endif
@@ -341,10 +256,21 @@ XUD_Result_t XUD_SetDevAddr(/*tileref usbtile*/ unsigned addr);
* \param one IN or OUT endpoint identifier to perform the reset on.
* \param two Optional second IN or OUT endpoint structure to perform a reset on.
* \return Either ``XUD_SPEED_HS`` - the host has accepted that this device can execute
- * at high speed, or ``XUD_SPEED_FS`` - the device is runnig at full speed.
+ * at high speed, ``XUD_SPEED_FS`` - the device is runnig at full speed,
+ * or ``XUD_SPEED_KILL`` to indicate that the USB stack has been shut down
+ * by another part of the user code (using XUD_Kill). If the last value is
+ * returned, the endpoint code should call XUD_CloseEndpoint and then
+ * terminate.
*/
XUD_BusSpeed_t XUD_ResetEndpoint(XUD_ep one, NULLABLE_REFERENCE_PARAM(XUD_ep, two));
+/**
+ * \brief This function closes an endpoint. It should be called when the USB stack
+ * is shutting down. It should be called on all endpoints, either in parallel
+ * or in numerical order, first all OUT and then all IN endpoints
+ * \param one endpoint to close.
+ */
+void XUD_CloseEndpoint(XUD_ep one);
/**
* \brief Initialises an XUD_ep
@@ -406,6 +332,12 @@ void XUD_ResetEpStateByAddr(unsigned epNum);
*/
void XUD_SetTestMode(XUD_ep ep, unsigned testMode);
+/**
+ * \brief Terminate XUD core
+ * \param ep XUD_ep type (must be endpoint 0 in or out)
+ * \warning Must be run on same tile as XUD core
+ */
+void XUD_Kill(XUD_ep ep);
/**********************************************************************************************
* Below are prototypes for main assembly functions for data transfer to/from USB I/O thread
@@ -513,8 +445,8 @@ inline XUD_Result_t XUD_SetReady_InPtr(XUD_ep ep, unsigned addr, int len)
{
int chan_array_ptr;
int tmp, tmp2;
- int wordlength;
- int taillength;
+ int wordLength;
+ int tailLength;
int reset;
@@ -525,29 +457,37 @@ inline XUD_Result_t XUD_SetReady_InPtr(XUD_ep ep, unsigned addr, int len)
return XUD_RES_RST;
}
- /* Knock off the tail bits */
- wordlength = len >>2;
- wordlength <<=2;
-
- taillength = zext((len << 5),7);
+ /* Tail length bytes to bits */
+ tailLength = zext((len << 3),5);
- asm ("ldw %0, %1[0]":"=r"(chan_array_ptr):"r"(ep));
+ /* Datalength (bytes) --> datalength (words) */
+ wordLength = len >> 2;
- // Get end off buffer address
- asm ("add %0, %1, %2":"=r"(tmp):"r"(addr),"r"(wordlength));
+ /* If tail-length is 0 and word-length not 0. Make tail-length 32 and word-length-- */
+ if ((tailLength == 0) && (wordLength != 0))
+ {
+ wordLength = wordLength - 1;
+ tailLength = 32;
+ }
+
+ /* Get end off buffer address */
+ asm ("add %0, %1, %2":"=r"(tmp):"r"(addr),"r"(wordLength << 2));
- asm ("neg %0, %1":"=r"(tmp2):"r"(len>>2)); // Produce negative offset from end off buffer
+ /* Produce negative offset from end of buffer */
+ asm ("neg %0, %1":"=r"(tmp2):"r"(wordLength));
- // Store neg index
- asm ("stw %0, %1[6]"::"r"(tmp2),"r"(ep)); // Store index
+ /* Store neg index */
+ asm ("stw %0, %1[6]"::"r"(tmp2),"r"(ep));
- // Store buffer pointer
+ /* Store buffer pointer */
asm ("stw %0, %1[3]"::"r"(tmp),"r"(ep));
- // Store tail len
- asm ("stw %0, %1[7]"::"r"(taillength),"r"(ep));
+ /* Store tail len */
+ asm ("stw %0, %1[7]"::"r"(tailLength),"r"(ep));
- asm ("stw %0, %1[0]"::"r"(ep),"r"(chan_array_ptr)); // Mark ready
+ /* Finally, mark ready */
+ asm ("ldw %0, %1[0]":"=r"(chan_array_ptr):"r"(ep));
+ asm ("stw %0, %1[0]"::"r"(ep),"r"(chan_array_ptr));
return XUD_RES_OKAY;
}
@@ -588,11 +528,15 @@ void XUD_GetData_Select(chanend c, XUD_ep ep, REFERENCE_PARAM(unsigned, length),
*/
#pragma select handler
void XUD_SetData_Select(chanend c, XUD_ep ep, REFERENCE_PARAM(XUD_Result_t, result));
-#endif
+#endif //__XC__ || __DOXYGEN__
/* Control token defines - used to inform EPs of bus-state types */
#define USB_RESET_TOKEN 8 /* Control token value that signals RESET */
-#endif //__XC__ || __STDC__
+#ifndef XUD_OSC_MHZ
+#define XUD_OSC_MHZ (24)
+#endif
+
+#endif //__ASSEMBLER__
-#endif // __xud_h__
+#endif // _XUD_H_
diff --git a/lib_xud/doc/rst/resource_usage_summary.rst b/lib_xud/doc/rst/resource_usage_summary.rst
deleted file mode 100644
index e52c430a..00000000
--- a/lib_xud/doc/rst/resource_usage_summary.rst
+++ /dev/null
@@ -1,28 +0,0 @@
-Typical Resource Usage
-----------------------
-
-.. resusage::
-
- * - configuration: USB device (xCORE-200 series)
- - target: XCORE-200-EXPLORER
- - flags: -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
- - globals: XUD_EpType epTypeTableOut[1] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE};
- XUD_EpType epTypeTableIn[1] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE};
- - locals: chan c_ep_out[1];chan c_ep_in[1];
- - fn: XUD_Main(c_ep_out, 1, c_ep_in, 1,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
- - pins: 23 (internal)
- - ports: 11
-
- * - configuration: USB device (U series)
- - target: SLICEKIT-U16
- - flags: -DXUD_SERIES_SUPPORT=XUD_U_SERIES
- - globals: XUD_EpType epTypeTableOut[1] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE};
- XUD_EpType epTypeTableIn[1] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE};
- - locals: chan c_ep_out[1];chan c_ep_in[1];
- - fn: XUD_Main(c_ep_out, 1, c_ep_in, 1,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1 , XUD_SPEED_HS, XUD_PWR_BUS);
- - pins: 23 (internal)
- - ports: 11
diff --git a/lib_xud/doc/rst/version.rst b/lib_xud/doc/rst/version.rst
index 5647263e..ecc91957 100644
--- a/lib_xud/doc/rst/version.rst
+++ b/lib_xud/doc/rst/version.rst
@@ -1 +1 @@
-.. version:: 1.2.0
+.. version:: 2.0.0
diff --git a/lib_xud/module_build_info b/lib_xud/module_build_info
index 2448c7e7..a089bc44 100644
--- a/lib_xud/module_build_info
+++ b/lib_xud/module_build_info
@@ -1,6 +1,4 @@
-VERSION = 1.2.0
-
-DEPENDENT_MODULES =
+VERSION = 2.0.0
MODULE_XCC_FLAGS = $(XCC_FLAGS) \
-O3 \
@@ -18,18 +16,18 @@ XCC_FLAGS_dfu_flash.xc = $(MODULE_XCC_FLAGS) -Os
XCC_FLAGS_XUD_Client.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue
XCC_FLAGS_XUD_Main.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue
XCC_FLAGS_XUD_SetDevAddr.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue
-XCC_FLAGS_XUD_DeviceAttach.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue -Wno-return-type
XCC_FLAGS_XUD_PhyResetUser.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue
XCC_FLAGS_XUD_Support.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue
XCC_FLAGS_XUD_IOLoopCall.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue
-XCC_FLAGS_XUD_PowerSig.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue -Wno-return-type
+XCC_FLAGS_XUD_Signalling.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue -Wno-return-type
XCC_FLAGS_XUD_TestMode.xc = $(MODULE_XCC_FLAGS) -mno-dual-issue
-XCC_FLAGS_XUD_GetDone.c = $(MODULE_XCC_FLAGS) -mno-dual-issue
XCC_FLAGS_XUD_SetCrcTableAddr.c = $(MODULE_XCC_FLAGS) -mno-dual-issue
XCC_FLAGS_XUD_User.c = $(MODULE_XCC_FLAGS) -mno-dual-issue
OPTIONAL_HEADERS += xud_conf.h
+DEPENDENT_MODULES =
+
EXPORT_INCLUDE_DIRS = api \
src/user
@@ -42,11 +40,13 @@ SOURCE_DIRS = src/core \
src/user/client \
src/user/control
-EXCLUDE_FILES += XUD_Token_In.S \
+EXCLUDE_FILES += XUD_CrcAddrCheck.S \
+ XUD_G_Crc.S \
+ XUD_PidJumpTable.S \
+ XUD_RxData.S \
+ XUD_Token_In_DI.S \
+ XUD_Token_Out_DI.S \
XUD_Token_Ping.S \
XUD_Token_SOF.S \
- XUD_Token_Out.S \
- XUD_Token_Setup.S \
- XUD_G_Crc.S \
- XUD_TokenJmp.S \
- XUD_PidJumpTable.S
+ XUD_Token_Setup_DI.S \
+ XUD_TokenJmp.S
diff --git a/lib_xud/src/core/XUD_AlignmentDefines.h b/lib_xud/src/core/XUD_AlignmentDefines.h
new file mode 100644
index 00000000..ed4e7f41
--- /dev/null
+++ b/lib_xud/src/core/XUD_AlignmentDefines.h
@@ -0,0 +1,23 @@
+// Copyright 2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+/* XUD_AlignmentDefines.h
+ * @brief Architecture-specific ASM function alignment
+ */
+
+#ifndef _XUD_ALIGNMENT_DEFINES_
+#define _XUD_ALIGNMENT_DEFINES_
+#if defined(__XS3A__)
+#define IBUFFER_FETCH_CORRECTION 1
+#else
+#define IBUFFER_FETCH_CORRECTION 0
+#endif
+
+#if IBUFFER_FETCH_CORRECTION == 1
+#define FUNCTION_ALIGNMENT 16
+#elif IBUFFER_FETCH_CORRECTION == 0
+#define FUNCTION_ALIGNMENT 4
+#else
+#error IBUFFER_FETCH_CORRECTION not defined
+#endif
+
+#endif // _XUD_ALIGNMENT_DEFINES_
diff --git a/lib_xud/src/core/XUD_CRC5_Table.S b/lib_xud/src/core/XUD_CRC5_Table.S
index 37ba2cb6..57d18dc5 100755
--- a/lib_xud/src/core/XUD_CRC5_Table.S
+++ b/lib_xud/src/core/XUD_CRC5_Table.S
@@ -3,7 +3,6 @@
/** XUD_CRC5_Table.S
* @brief Full USB CRC5 table
* @author Ross Owen, XMOS Limited
- * @version 0v9
*/
.section .dp.data, "adw", @progbits
diff --git a/lib_xud/src/core/XUD_CRC5_Table_Addr.S b/lib_xud/src/core/XUD_CRC5_Table_Addr.S
new file mode 100755
index 00000000..43390e3a
--- /dev/null
+++ b/lib_xud/src/core/XUD_CRC5_Table_Addr.S
@@ -0,0 +1,2063 @@
+// Copyright 2011-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+/** XUD_CRC5_Table_Addr.S
+ * @brief CRC5 table
+ * @author Ross Owen, XMOS Limited
+ */
+
+.section .dp.data, "adw", @progbits
+.globl crc5Table_Addr
+.type crc5Table_Addr, @object
+.cc_top crc5Table_Addr.func, crc5Table_Addr
+.align 4
+crc5Table_Addr:
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0xf
+.byte 0x10
+.byte 0x18
+.byte 0x7
+.byte 0x8
+.byte 0x17
+.byte 0x1f
+.byte 0x0
+.byte 0x1
+.byte 0x1e
+.byte 0x16
+.byte 0x9
+.byte 0x6
+.byte 0x19
+.byte 0x11
+.byte 0xe
+.byte 0x13
+.byte 0xc
+.byte 0x4
+.byte 0x1b
+.byte 0x14
+.byte 0xb
+.byte 0x3
+.byte 0x1c
+.byte 0x1d
+.byte 0x2
+.byte 0xa
+.byte 0x15
+.byte 0x1a
+.byte 0x5
+.byte 0xd
+.byte 0x12
+.byte 0x1e
+.byte 0x1
+.byte 0x9
+.byte 0x16
+.byte 0x19
+.byte 0x6
+.byte 0xe
+.byte 0x11
+.byte 0x10
+.byte 0xf
+.byte 0x7
+.byte 0x18
+.byte 0x17
+.byte 0x8
+.byte 0x0
+.byte 0x1f
+.byte 0x2
+.byte 0x1d
+.byte 0x15
+.byte 0xa
+.byte 0x5
+.byte 0x1a
+.byte 0x12
+.byte 0xd
+.byte 0xc
+.byte 0x13
+.byte 0x1b
+.byte 0x4
+.byte 0xb
+.byte 0x14
+.byte 0x1c
+.byte 0x3
+.byte 0x4
+.byte 0x1b
+.byte 0x13
+.byte 0xc
+.byte 0x3
+.byte 0x1c
+.byte 0x14
+.byte 0xb
+.byte 0xa
+.byte 0x15
+.byte 0x1d
+.byte 0x2
+.byte 0xd
+.byte 0x12
+.byte 0x1a
+.byte 0x5
+.byte 0x18
+.byte 0x7
+.byte 0xf
+.byte 0x10
+.byte 0x1f
+.byte 0x0
+.byte 0x8
+.byte 0x17
+.byte 0x16
+.byte 0x9
+.byte 0x1
+.byte 0x1e
+.byte 0x11
+.byte 0xe
+.byte 0x6
+.byte 0x19
+.byte 0x15
+.byte 0xa
+.byte 0x2
+.byte 0x1d
+.byte 0x12
+.byte 0xd
+.byte 0x5
+.byte 0x1a
+.byte 0x1b
+.byte 0x4
+.byte 0xc
+.byte 0x13
+.byte 0x1c
+.byte 0x3
+.byte 0xb
+.byte 0x14
+.byte 0x9
+.byte 0x16
+.byte 0x1e
+.byte 0x1
+.byte 0xe
+.byte 0x11
+.byte 0x19
+.byte 0x6
+.byte 0x7
+.byte 0x18
+.byte 0x10
+.byte 0xf
+.byte 0x0
+.byte 0x1f
+.byte 0x17
+.byte 0x8
+.size crc5Table_Addr, .-crc5Table_Addr
+.cc_bottom crc5Table_Addr.func
diff --git a/lib_xud/src/core/XUD_Client.xc b/lib_xud/src/core/XUD_Client.xc
deleted file mode 100644
index a0222667..00000000
--- a/lib_xud/src/core/XUD_Client.xc
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright 2012-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#include
-
-//extern void XUD_SetReady_In(XUD_ep e, unsigned bufferPtr, int len);
-
-//extern void XUD_SetData_Inline(XUD_ep e, chanend c);
diff --git a/lib_xud/src/core/XUD_CrcAddrCheck.S b/lib_xud/src/core/XUD_CrcAddrCheck.S
new file mode 100644
index 00000000..6baf4459
--- /dev/null
+++ b/lib_xud/src/core/XUD_CrcAddrCheck.S
@@ -0,0 +1,37 @@
+// Copyright 2011-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+// On Entry:
+// r0: rxd port
+// r8: 16 (XS3 only)
+
+// Required on exit:
+// r4: 0
+// r10: Extracted EP number
+
+#ifdef __XS3A__
+ {in r10, res[RXD]; sub r1, r8, 5} // ldc r1 11
+ {shr r10, r10, 16; mkmsk r11, r1}
+ {and r11, r10, r11; shr r4, r10, r1} // r4: Received CRC
+
+ ldaw r8, dp[crc5Table_Addr]
+ ld8u r8, r8[r11] // Correct CRC
+
+ xor r4, r4, r8 // R4 set to 0 in L code with in from valid tok port
+ {BRFF_ru6 r4, 5; shr r10, r11, 7} // Extract EP number
+
+ ldw r11, sp[STACK_RXA_PORT] // Wait for RXA to gow low (i.e. end of packet)
+ in r10, res[r11]
+ bt r10, waitforRXALow0
+ setc res[RXD], XS1_SETC_RUN_CLRBUF
+ bu Loop_BadPid
+#else
+ // __XS2A__
+ inpw r10, res[RXD], 8; // Read EP Number
+ shr r10, r10, 24; // Shift off junk
+
+ in r4, res[r1];
+ bt r4, XUD_InvalidToken; // If VALID_TOKEN not high, ignore token - PORT INVERTED! */
+#endif
+
+
diff --git a/lib_xud/src/core/XUD_Default.c b/lib_xud/src/core/XUD_Default.c
new file mode 100644
index 00000000..426c65a4
--- /dev/null
+++ b/lib_xud/src/core/XUD_Default.c
@@ -0,0 +1,20 @@
+// Copyright 2019-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "xud.h"
+
+#if defined(__XS3A__)
+unsigned int XUD_HAL_GetVBusState(void) __attribute__((weak));
+#else
+unsigned int read_vbus();
+#endif
+
+unsigned int XUD_HAL_GetVBusState(void)
+{
+#if defined(__XS3A__)
+ return 1u;
+#elif defined(__XS2A__)
+ return read_vbus();
+#else
+#error no architecture defined
+#endif
+}
diff --git a/lib_xud/src/core/XUD_DeviceAttach.xc b/lib_xud/src/core/XUD_DeviceAttach.xc
index 03ed4107..c9da944e 100755
--- a/lib_xud/src/core/XUD_DeviceAttach.xc
+++ b/lib_xud/src/core/XUD_DeviceAttach.xc
@@ -1,47 +1,25 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef SIMULATION
+#if !defined(XUD_BYPASS_RESET)
#include
-#include
#include
-#include "XUD_UIFM_Functions.h"
-#include "XUD_UIFM_Defines.h"
+#include "xud.h"
#include "XUD_USB_Defines.h"
#include "XUD_TimingDefines.h"
-#include "XUD_Support.h"
-#include "xud.h"
-
-#ifdef ARCH_S
-#include "xs1_su_registers.h"
-#endif
-
-#ifdef ARCH_X200
-#include "xs1_to_glx.h"
-#include "xs2_su_registers.h"
-#endif
-
-#if defined(ARCH_S) || defined(ARCH_X200)
-#include "XUD_USBTile_Support.h"
-extern unsigned get_tile_id(tileref ref);
-extern tileref USB_TILE_REF;
-#endif
+#include "XUD_HAL.h"
extern in port flag0_port;
extern in port flag1_port;
extern in port flag2_port;
-#if defined(ARCH_S) || defined(ARCH_X200)
extern out buffered port:32 p_usb_txd;
-#define reg_write_port null
-#define reg_read_port null
-#else
-extern out port reg_write_port;
-extern in port reg_read_port;
-extern out port p_usb_txd;
-#endif
-#define TUCHEND_DELAY_us 1500 // 1.5ms
+#define TUCHEND_DELAY_us (1500) // 1.5ms
#define TUCHEND_DELAY (TUCHEND_DELAY_us * REF_CLK_FREQ)
-#define INVALID_DELAY_us 2500 // 2.5ms
+
+#ifndef INVALID_DELAY_us
+#define INVALID_DELAY_us (2500) // 2.5ms
+#endif
+
#define INVALID_DELAY (INVALID_DELAY_us * REF_CLK_FREQ)
extern int resetCount;
@@ -58,119 +36,119 @@ int XUD_DeviceAttachHS(XUD_PwrConfig pwrConfig)
int start_time;
int detecting_k = 1;
int tx;
- int chirpCount;
-
- chirpCount = 0;
+ unsigned int chirpCount = 0;
clearbuf(p_usb_txd);
-#ifndef ARCH_X200
-#ifndef ARCH_S
- clearbuf(reg_write_port);
-#endif
+
+ /* On detecting the SE0 move into chirp mode */
+ XUD_HAL_EnterMode_PeripheralChirp();
+
+ /* output k-chirp for required time */
+#if defined(XUD_SIM_RTL) || (XUD_SIM_XSIM)
+ for (int i = 0; i < 800; i++)
+#else
+ for (int i = 0; i < 16000; i++) // 16000 words @ 480 MBit = 1.066 ms
+#endif
+ {
+ p_usb_txd <: 0;
+ }
+
+ // J, K, SE0 on flag ports 0, 1, 2 respectively (on XS2)
+ // XS3 has raw linestate on flag port 0 and 1
+ // Wait for fs chirp k (i.e. HS chirp j)
+#if defined(__XS2A__)
+ flag1_port when pinseq(0) :> tmp; // Wait for out k to go
#endif
- // On detecting the SE0:
- // De-assert XCVRSelect and set opmode=2
- // DEBUG - write to ulpi reg 0x54. This is:
- // opmode = 0b10, termsel = 1, xcvrsel = 0b00;
-#if defined(ARCH_S) || defined(ARCH_X200)
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 0b1010);
+ t :> start_time;
+ while(1)
+ {
+ select
+ {
+ case t when timerafter(start_time + INVALID_DELAY) :> void:
+
+ /* Go into full speed mode: XcvrSelect and Term Select (and suspend) high */
+ XUD_HAL_EnterMode_PeripheralFullSpeed();
+
+ /* Wait for end of SE0 */
+ while(1)
+ {
+ /* TODO Use a timer to save some juice...*/
+#ifdef __XS3A__
+ unsigned dp, dm;
+ flag0_port :> dm;
+ flag1_port :> dp;
+
+ if(dp || dm)
+ {
+ /* SE0 gone, return 0 to indicate FULL SPEED */
+ return 0;
+ }
#else
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_PHYCON, 0x15);
-#endif
- XUD_Sup_Delay(50);
-
-//#ifdef ARCH_S
- /* Added a bit of a delay before chirp to match an example HS device */
- t :> start_time;
- t when timerafter(start_time+10000):> void;
-//#endif
- // output k-chirp for required time
+ flag2_port :> tmp;
- for (int i = 0; i < 16000; i++) { // 16000 words @ 480 MBit = 1.066 ms
- p_usb_txd <: 0;
-
- }
-
- //XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_CTRL, 0x04);
- // J, K, SE0 on flag ports 0, 1, 2 respectively
- // Wait for fs chirp k (i.e. HS chirp j)
- flag1_port when pinseq(0) :> tmp; // Wait for out k to go
-
- t :> start_time;
- while(1) {
- select {
- case t when timerafter(start_time + INVALID_DELAY) :> void:
-
- /* Go into full speed mode: XcvrSelect and Term Select (and suspend) high */
-#if defined(ARCH_S) || defined(ARCH_X200)
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM,
- XS1_SU_PER_UIFM_FUNC_CONTROL_NUM,
- (1< tmp;
-
- if(!tmp) {
- return 0; /* SE0 gone, return 0 to indicate FULL SPEED */
- }
-
- if(pwrConfig == XUD_PWR_SELF) {
- unsigned x;
-#if defined(ARCH_S) || defined(ARCH_X200)
- read_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM,
- XS1_SU_PER_UIFM_OTG_FLAGS_NUM, x);
- if(!(x&(1< flag1_port when pinseq(1):> void @ tx: // K Chirp
- flag1_port @ tx + T_FILT :> tmp;
- if (tmp) {
- detecting_k = 0;
- }
- break;
- case !detecting_k => flag0_port when pinseq(0) :> void @ tx: // J Chirp, inverted!
- flag0_port @ tx + T_FILT :> tmp;
- if (tmp == 0) { // inverted!
- chirpCount ++; // Seen an extra K-J pair
- detecting_k = 1;
- if (chirpCount == 3) { // On 3 we have seen a HS
-
- // Three pairs of KJ received... de-assert TermSelect...
- // (and opmode = 0, suspendm = 1)
-#if defined(ARCH_S) || defined(ARCH_X200)
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM,
- XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 0b0000);
+ case detecting_k => k_port when pinseq(1):> void @ tx: // K Chirp
+ k_port @ tx + T_FILT_ticks :> tmp;
+ if (tmp)
+ {
+ detecting_k = 0;
+ }
+ break;
+
+ case !detecting_k => j_port when pinseq(1) :> void @ tx: // J Chirp
+ j_port @ tx + T_FILT_ticks :> tmp;
+ if (tmp == 1)
+ {
+ chirpCount++; // Seen an extra K-J pair
+ detecting_k = 1;
+
+ if (chirpCount == 3)
+ {
+ /* Three pairs of KJ received. Enter high-speed mode */
+ XUD_HAL_EnterMode_PeripheralHighSpeed();
+
+ // Wait for SE0 (TODO consume other chirps?)
+#ifdef __XS3A__
+ // TODO ideally dont use a polling loop here
+ while (XUD_HAL_GetLineState() != XUD_LINESTATE_SE0);
#else
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_PHYCON, 0x1);
-#endif
- //wait for SE0 (TODO consume other chirps?)
- flag2_port when pinseq(1) :> tmp;
- return 1; // Return 1 for HS
- }
- }
- break;
- }
- }
+ flag2_port when pinseq(1) :> tmp;
+#endif
+
+ /* Return 1 to indicate successful HS handshake*/
+ return 1;
+
+ }
+ }
+ break;
+ }
+ }
+ // Unreachable
+ return -1;
}
#endif
diff --git a/lib_xud/src/core/XUD_G_Crc.S b/lib_xud/src/core/XUD_G_Crc.S
deleted file mode 100644
index 5d7908ea..00000000
--- a/lib_xud/src/core/XUD_G_Crc.S
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-// On Entry:
-// ldw r1, dp[crcmask]
-#if 0
-//CrcAddrCheck: // Extract 11 bits for CRC5: | EP(4) | ADDR(7) |
- in r10, res[RXD]
- shr r10, r10, 16
- and r11, r10, r1
-
- ldaw r8, dp[crc5Table_Addr]
- ld8u r8, r8[r11] // Correct CRC
-
- shr r4, r10, 5
- shr r4, r4, 6 // Received CRC
- //eq r6, r6, r8
- xor r4, r4, r8 // R4 set to 0 in L code with in from valid tok port
- bt r4, BadCrcAddr
-
-//ExtractEP:
- shr r10, r11, 7
-
-#else
- in r10, res[RXD]
- ldaw r1, dp[crc5Table_Addr]
- ldc r8, 30
- lmul r11, r10, r10, r8, r10, r10 // r11 is CRC5, r10 is EP(4):ADDR(7):CRAP(16):0(5)
- shr r10, r10, 16 // r10 is 0(16):EP(4):ADDR(7):CRAP(5)
- shr r10, r10, 5 // r10 is 0(21):EP(4):ADDR(7)
- ld8u r8, r1[r10] // r8 is CRC of r10
- sub r4, r11, r8 // R4 set to 0 in L code with in from valid tok port
- bt r4, BadCrcAddr
-//ExtractEP:
- shr r10, r10, 7
-
-#endif
-
-// Required on exit:
-// r4: 0
-// r10: Extracted EP number
diff --git a/lib_xud/src/core/XUD_GetDone.c b/lib_xud/src/core/XUD_GetDone.c
deleted file mode 100644
index 4c54462a..00000000
--- a/lib_xud/src/core/XUD_GetDone.c
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2015-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/** @file XUD_GetDone.c
- * @author Matt Fyles, XMOS Limited
- * @version 1v0
- */
-
-extern int XUD_USB_Done;
-
-int XUD_GetDone() {
- return XUD_USB_Done;
-}
-
-
diff --git a/lib_xud/src/core/XUD_HAL.h b/lib_xud/src/core/XUD_HAL.h
new file mode 100644
index 00000000..af6ecbc1
--- /dev/null
+++ b/lib_xud/src/core/XUD_HAL.h
@@ -0,0 +1,89 @@
+// Copyright 2019-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+/**
+ * @file XUD_HAL.h
+ * \brief USB HAL Layer
+**/
+
+#include "xud.h"
+#include
+
+#define USB_TILE_REF usb_tile
+
+#ifdef __XS3A__
+#include
+// TODO should be properlty in HAL
+unsigned XtlSelFromMhz(unsigned m);
+#else
+#include "XUD_USBTile_Support.h"
+#include "xs1_to_glx.h"
+#include "xs2_su_registers.h"
+#endif
+
+/**
+ * \enum XUD_LineState_t
+ * \brief USB Line States
+ */
+typedef enum XUD_LineState_t
+{
+ XUD_LINESTATE_SE0 = 0, /**< SE0 State */
+ XUD_LINESTATE_J = 1, /**< J State */
+ XUD_LINESTATE_K = 2, /**< K State */
+ XUD_LINESTATE_SE1 = 3 /**< Invalid bus state both lines high **/
+} XUD_LineState_t;
+
+void XUD_HAL_EnterMode_PeripheralChirp();
+void XUD_HAL_EnterMode_PeripheralFullSpeed();
+void XUD_HAL_EnterMode_PeripheralHighSpeed();
+void XUD_HAL_EnterMode_PeripheralTestJTestK();
+void XUD_HAL_EnterMode_TristateDrivers();
+
+/**
+ * \brief Get current linestate status
+ * \return XUD_LineState_t representing current line status
+**/
+XUD_LineState_t XUD_HAL_GetLineState(/*XUD_HAL_t &xudHal*/);
+
+/**
+ * \brief Wait for a change in linestate and return, or timeout
+ * \param Reference to current linestate (updated with new linestate
+ * \return 1 for timed out, otherwise 0
+**/
+unsigned XUD_HAL_WaitForLineStateChange(XUD_LineState_t ¤tLs, unsigned timeout);
+
+/**
+ * \brief HAL function to set xCORE into signalling mode
+ * (as opposed to "data transfer" mode)
+ *
+ * TODO Should this be combined with EnterMode_PeripheralChirp()?
+ **/
+void XUD_HAL_Mode_PowerSig();
+
+/**
+ * \brief HAL function to set xCORE into data transfer mode
+ * (as opposed to "signalling" mode )
+ *
+ * TODO Should this be combined with EnterMode_PeripheralHigh/FullSpeed()?
+ **/
+void XUD_HAL_Mode_DataTransfer();
+
+/**
+ * \brief HAL function to set xCORE to correct USB device address
+ * \param address The new address
+ * \return void
+ **/
+void XUD_HAL_SetDeviceAddress(unsigned char address);
+
+/**
+ * \brief Enable USB funtionality in the device
+ **/
+void XUD_HAL_EnableUsb(unsigned pwrConfig);
+
+/**
+ * \brief HAL funtion to get state of VBUS line, if any
+ * \param none
+ * \return unsigned int non-zero if VBUS asserted, zero otherwise
+ **/
+unsigned int XUD_HAL_GetVBusState(void);
+
diff --git a/lib_xud/src/core/XUD_HAL.xc b/lib_xud/src/core/XUD_HAL.xc
new file mode 100644
index 00000000..8865167b
--- /dev/null
+++ b/lib_xud/src/core/XUD_HAL.xc
@@ -0,0 +1,401 @@
+// Copyright 2019-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#include
+#include "xud.h"
+
+#include "XUD_HAL.h"
+
+#ifdef __XS2A__
+#include "xs1_to_glx.h"
+#include "xs2_su_registers.h"
+extern in port flag0_port;
+extern in port flag1_port;
+extern in port flag2_port;
+extern buffered in port:32 p_usb_clk;
+#else
+extern in port flag0_port; /* For XS3: RXA or DP */
+extern in port flag1_port; /* For XS3: RXE or DM */
+extern buffered in port:32 p_usb_clk;
+void XUD_SetCrcTableAddr(unsigned addr);
+unsigned XtlSelFromMhz(unsigned m)
+{
+ switch(m)
+ {
+ case 10:
+ return 0b000;
+ case 12:
+ return 0b001;
+ case 25:
+ return 0b010;
+ case 30:
+ return 0b011;
+ case 19: /*.2*/
+ return 0b100;
+ case 24:
+ return 0b101;
+ case 27:
+ return 0b110;
+ case 40:
+ return 0b111;
+ default:
+ /* Panic */
+ while(1);
+ break;
+ }
+
+ return 0b000;
+}
+#endif
+
+unsigned int XUD_EnableUsbPortMux();
+
+void XUD_HAL_EnableUsb(unsigned pwrConfig)
+{
+ /* For xCORE-200 enable USB port muxing before enabling phy etc */
+ XUD_EnableUsbPortMux(); //setps(XS1_PS_XCORE_CTRL0, UIFM_MODE);
+
+#ifndef XUD_SIM_XSIM
+
+#ifdef __XS2A__
+ /* Enable the USB clock */
+ write_sswitch_reg(get_tile_id(USB_TILE_REF), XS1_SU_CFG_RST_MISC_NUM, ( 1 << XS1_SU_CFG_USB_CLK_EN_SHIFT));
+
+ /* Now reset the phy */
+ write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_GLX_PER_UIFM_PHY_CONTROL_NUM, 0); //(0< int _;
+ p_usb_clk when pinseq(0) :> int _;
+ p_usb_clk when pinseq(1) :> int _;
+ p_usb_clk when pinseq(0) :> int _;
+
+#ifdef __XS2A__
+ /* Some extra settings are required for proper operation on XS2A */
+ #define XS1_UIFM_USB_PHY_EXT_CTRL_REG 0x50
+ #define XS1_UIFM_USB_PHY_EXT_CTRL_VBUSVLDEXT_MASK 0x4
+
+ /* Remove requirement for VBUS in bus-powered mode */
+ if(pwrConfig == XUD_PWR_BUS)
+ {
+ write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_UIFM_USB_PHY_EXT_CTRL_REG, XS1_UIFM_USB_PHY_EXT_CTRL_VBUSVLDEXTSEL_MASK | XS1_UIFM_USB_PHY_EXT_CTRL_VBUSVLDEXT_MASK);
+ }
+
+ #define PHYTUNEREGVAL 0x0093B264
+ #define XS1_UIFM_USB_PHY_TUNE_REG 0x4c
+ /* Phy Tuning parameters */
+ /* OTG TUNE: 3b'100
+ * TXFSLSTUNE: 4b'1001
+ * TXVREFTUNE:4b'1001 -- +1.25% adjustment in HS DC voltage level
+ * BIASTUNE: 1b'0
+ * COMDISTUNE:3b'011 -- -1.5% adjustment from default (disconnect threshold adjustment)
+ * SQRXTUNE:3b'010 -- +5% adjustment from default (Squelch Threshold)
+ * TXRISETUNE: 1b'0
+ * TXPREEMPHASISTUNE:1b'1 -- enabled (default is disabled)
+ * TXHSXVTUNE: 2b'11
+ */
+ write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_UIFM_USB_PHY_TUNE_REG, PHYTUNEREGVAL);
+
+ write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_CONTROL_NUM, (1<> 1) & 1};
+}
+
+static inline XUD_LineState_t LinesToLineState(unsigned dp, unsigned dm)
+{
+ return (XUD_LineState_t) (dp & 1) | ((dm & 1)<< 1);
+}
+
+/* TODO pass structure */
+XUD_LineState_t XUD_HAL_GetLineState(/*XUD_HAL_t &xudHal*/)
+{
+#ifdef __XS3A__
+ unsigned dp, dm;
+ dp_port :> dp;//flag1
+ dm_port :> dm;//flag0
+ return LinesToLineState(dp, dm);
+#else
+ unsigned j, k, se0;
+ flag0_port :> j;
+ flag1_port :> k;
+ flag2_port :> se0;
+
+ if(j)
+ return XUD_LINESTATE_J;
+ if(k)
+ return XUD_LINESTATE_K;
+ if(se0)
+ return XUD_LINESTATE_SE0;
+
+ return XUD_LINESTATE_SE1;
+#endif
+}
+
+unsigned XUD_HAL_WaitForLineStateChange(XUD_LineState_t ¤tLs, unsigned timeout)
+{
+#ifdef __XS3A__
+ unsigned dp, dm;
+ timer t;
+ unsigned time;
+
+ /* Look up line values from linestate */
+ {dp, dm} = LineStateToLines(currentLs);
+
+ if (timeout != null)
+ t :> time;
+
+ /* Wait for change */
+ select
+ {
+ case dp_port when pinsneq(dp) :> dp:
+ dm_port :> dm; //Both might have changed!
+ break;
+ case dm_port when pinsneq(dm) :> dm:
+ dp_port :> dp; //Both might have changed!
+ break;
+ case timeout != null => t when timerafter(time + timeout) :> int _:
+ return 1;
+
+ }
+
+ /* Return new linestate */
+ currentLs = LinesToLineState(dp, dm);
+ return 0;
+#else
+ //TODO XUD_HAL_WaitForLineStateChange() not implemented for XS2
+ //Note, this is not currently used for XS2
+ return 1;
+#endif
+}
+
+void XUD_HAL_SetDeviceAddress(unsigned char address)
+{
+#ifdef __XS3A__
+ XUD_SetCrcTableAddr(address);
+#else
+ write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_DEVICE_ADDRESS_NUM, address);
+#endif
+}
+
+#ifdef __XS2A__
+unsigned read_vbus()
+{
+ unsigned int x;
+ read_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_GLX_PER_UIFM_OTG_FLAGS_NUM, x);
+ return x & (1 << XS1_UIFM_OTG_FLAGS_SESSVLDB_SHIFT);
+}
+#endif
diff --git a/lib_xud/src/core/XUD_IoLoop.S b/lib_xud/src/core/XUD_IoLoop.S
index 2357940c..b088c148 100755
--- a/lib_xud/src/core/XUD_IoLoop.S
+++ b/lib_xud/src/core/XUD_IoLoop.S
@@ -12,14 +12,14 @@
#include
#include "xud.h"
#include "XUD_USB_Defines.h"
-#include "XUD_UIFM_Defines.h"
#include "XUD_TimingDefines.h"
+#include "XUD_AlignmentDefines.h"
.section .cp.const4,"aMc",@progbits,4
.cc_top suspendTimeout.data
.align 4
suspendTimeout:
-.long SUSPEND_TIMEOUT
+.long SUSPEND_TIMEOUT_ticks
.cc_bottom suspendTimeout.data
.text
@@ -27,7 +27,7 @@ suspendTimeout:
.cc_top suspend_t_wtwrsths.data
.align 4
suspend_t_wtwrsths:
-.long SUSPEND_T_WTWRSTHS
+.long SUSPEND_T_WTWRSTHS_ticks
.cc_bottom suspend_t_wtwrsths.data
.text
@@ -37,35 +37,30 @@ suspend_t_wtwrsths:
// Stack frame:
// 0
// 1..7: : Reg save
-// 8 : TX handshake timer
-// 9 : Out timer
-#define STACK_FLAG1_PORT (STACK_EXTEND-12)// 10 : RXA_port
-#define STACK_FLAG0_PORT (STACK_EXTEND-11)// 11 : Valid token port
-// 12 : ?
-// 13 : Suspend timeout
-// 14 : Suspend/Reset timer
-// 15 : RxError port (flag 2)
-
-#define STACK_PID_JUMP_TABLE (STACK_EXTEND-3)
+// 8 : Unused
+#define STACK_OUT_TIMER (9) // Used for out data timeout
+#define STACK_RXA_PORT (10) // RXA_port
+// 11 : Unused
+// 12 : Unused
+#define STACK_SUSPEND_TIMEOUT (13)
+#define STACK_SUSPEND_TIMER (14)
+#define STACK_RXE_PORT (15)
+#define STACK_RXCRC_TAIL0 (16)
+#define STACK_RXCRC_TAIL1 (17)
+#define STACK_RXCRC_TAIL2 (18)
+#define STACK_RXCRC_TAIL3 (19)
+#define STACK_TXCRC_INIT (20)
+#define STACK_RXCRC_INIT (21)
+#define STACK_PIDJUMPTABLE (22)
+#define STACK_HANDSHAKETABLEIN (23)
// Params
-// STACK_EXTEND + 1 : Flag0_port
-// STACK_EXTEND + 2 : reg_read_port
-// STACK_EXTEND + 3 : reg_write_port
-// STACK_EXTEND + 4 : 0
-// STACK_EXTEND + 5 : c_ctl_buf
-
-#define SP_EPTYPES_OUT (STACK_EXTEND +6) // STACK_EXTEND + 6 : EP Type table (out)
-#define SP_EPTYPES_IN (STACK_EXTEND + 7) // EP Type table (in)
-#define SP_EPCHANS (STACK_EXTEND + 7)
-#define SP_EPCOUNT (STACK_EXTEND + 9)
-#define SP_REGREAD (STACK_EXTEND + 10)
-#define SP_REGWRITE (STACK_EXTEND + 11)
-
-
-
-
-
+#define STACK_VTOK_PORT (STACK_EXTEND + 1)
+#define STACK_EPTYPES_OUT (STACK_EXTEND + 2) // STACK_EXTEND + 6 : EP Type table (out)
+#define STACK_EPTYPES_IN (STACK_EXTEND + 3) // EP Type table (in)
+#define STACK_EPCHANS (STACK_EXTEND + 4)
+#define SP_EPCOUNT (STACK_EXTEND + 5)
+#define STACK_SOFCHAN (STACK_EXTEND + 6)
#ifndef XUD_TEST_MODE_SUPPORT_DISABLED
//////////////////////////////////////////////////////////////////////////
@@ -77,67 +72,28 @@ suspend_t_wtwrsths:
.globl UsbTestModeHandler_asm
.text
.cc_top UsbTestModeHandler_asm.func, UsbTestModeHandler_asm
+.issue_mode single
+.align FUNCTION_ALIGNMENT
UsbTestModeHandler_asm:
+ ENTSP_lu6 0
clrsr 0x18
clrsr 0x2
- clre // clear all events
+ clre // clear all events
get r11, ed
chkct res[r11], XS1_CT_END
outct res[r11], XS1_CT_END
in r0, res[r11]
chkct res[r11], XS1_CT_END
outct res[r11], XS1_CT_END
-// in r0, res[r11]
- retsp 0
+
+ bf r0, Return // Special case for Exit
+
+ bl XUD_UsbTestModeHandler
+
+ retsp 0
.cc_bottom UsbTestModeHandler_asm.func
#endif
-
-.globl XUD_UsbTestSE0.nstackwords
-.linkset XUD_UsbTestSE0.nstackwords, 0
-.globl XUD_UsbTestSE0
-.text
-.cc_top XUD_UsbTestSE0.func, XUD_UsbTestSE0
-XUD_UsbTestSE0:
- ldw r0, dp[p_usb_rxd] // Load RXD port
- ldw r1, dp[flag0_port] // Valid token port
- ldw r2, dp[p_usb_txd] // Load TXD port
- ldw r3, dp[flag1_port] // Load RXA port
-
-XUD_UsbTestSE0_loop:
- inpw r11, res[r0], 8 // Read 8 bit PID
- shr r11, r11, 24 // shift off junk
-
- inpw r9, res[r0], 8 // Read EP Number (dont care)
-
- in r9, res[r1]
- bt r9, InvalidTestToken // If VALID_TOKEN high, ignore token
-
- eq r10, r11, USB_PID_IN
- bf r10, XUD_UsbTestSE0_loop
-
- nop
- nop
- nop
- nop
- nop
-
- ldc r11, USB_PIDn_NAK
- outpw res[r2], r11, 8
- syncr res[r2]
- bu XUD_UsbTestSE0_loop
-
-InvalidTestToken:
- in r11, res[r3]
- bt r11, InvalidTestToken
- setc res[r0], XS1_SETC_RUN_CLRBUF // Clear RXD port
- bu XUD_UsbTestSE0_loop
-
-
-// End of code for Test_SE0_NAK
-.cc_bottom XUD_UsbTestSE0.func
-
-
/////////////////////////////////////////////////////////////////////////
// void ResetIntHandler()
// Interupt handler for reset/suspend timer
@@ -146,9 +102,12 @@ InvalidTestToken:
.globl ResetIntHandler
.text
.cc_top ResetIntHandler.func, ResetIntHandler
+.issue_mode dual
+.align FUNCTION_ALIGNMENT
ResetIntHandler:
+ DUALENTSP_lu6 0
clrsr 0x18 // Clear InInterrupt bit (and InKernel)
- clrsr 0x2
+ clrsr 0x3 // Clear thread events and interrupts
get r11, ed // Get timer resource ID
setc res[r11], XS1_SETC_IE_MODE_EVENT // Set IE mode back to events
@@ -158,23 +117,8 @@ ResetIntHandler:
ldw r10, dp[SavedSp] // Restore stack pointer
set sp, r10
-#if 0 // RxError Interrupts Disabled
- ldw r11, sp[15] // Put RxE back to events..
- setc res[r11], XS1_SETC_IE_MODE_EVENT // Set IE mode back to events
-#endif
-
-
-ResetDetect:
- ldc r0, 0 // Return 0 for reset
- bu writesuspendvar
-
-
-SuspendDetect:
- ldc r0, 1
-
-writesuspendvar:
- //stw r0, dp[suspend]
- bu Return // Return 1 for suspend
+ ldc r0, 1 // Load non-zero (zero is kill)
+ bu Return
.cc_bottom ResetIntHandler.func
@@ -196,21 +140,32 @@ writesuspendvar:
.cc_top XUD_LLD_IoLoop.func, XUD_LLD_IoLoop
.text
+.issue_mode dual
// Note, included here so in same elimination blocks to avoid long jumps
-#include "./included/XUD_Token_Out.S"
+#include "./included/XUD_Token_In_DI.S"
+#include "./included/XUD_Token_Setup_DI.S"
+#include "./included/XUD_Token_Out_DI.S"
+#include "./included/XUD_RxData.S"
#include "./included/XUD_Token_Ping.S"
-#include "./included/XUD_Token_In.S"
-#include "./included/XUD_Token_Setup.S"
#include "./included/XUD_Token_SOF.S"
-.align 4
+BadCrcAddr:
+ // zext r11, 8
+ // ldc r10, PIDn_SOF
+ // eq r11, r11, r10
+ //ecallt r11
+ //bt r11, Pid_Sof_NoChan // TODO we should really CRC SOFs
+ ldw r11, sp[STACK_RXA_PORT]
+
+waitforRXALow0:
+ in r10, res[r11]
+ bt r10, waitforRXALow0
+ setc res[RXD], XS1_SETC_RUN_CLRBUF
+ bu Loop_BadPid
+
+.align FUNCTION_ALIGNMENT
XUD_LLD_IoLoop:
-#if defined(__XS2A__)
-.issue_mode single
- ENTSP_lu6 STACK_EXTEND
-#else
- entsp STACK_EXTEND
-#endif
+ DUALENTSP_lu6 STACK_EXTEND
stw r4, sp[1]
stw r5, sp[2]
stw r6, sp[3]
@@ -218,6 +173,9 @@ XUD_LLD_IoLoop:
stw r8, sp[5]
stw r9, sp[6]
stw r10, sp[7]
+PortsOnStack: // Put ports on stack (loads therefore short insts)
+ stw r1, sp[STACK_RXA_PORT]
+ stw r3, sp[STACK_RXE_PORT]
SaveStackPointer:
ldaw r11, sp[0]
@@ -225,51 +183,31 @@ SaveStackPointer:
ldw r11, cp[suspendTimeout]
- stw r11, sp[13]
+ stw r11, sp[STACK_SUSPEND_TIMEOUT]
-ConfigRxDEventVector: // Configure events
+ConfigRxDEventVector: // Configure event on RXD port for receiveing a handshake after Tx
setc res[RXD], XS1_SETC_IE_MODE_EVENT
- ldap r11, TxHandShakeReceived
- setv res[RXD], r11
-
-
-
-ConfigRxA:
- setc res[RXA], XS1_SETC_COND_EQ
- setc res[RXA], XS1_SETC_IE_MODE_EVENT
- ldc r11, 0
- setd res[r1], r11
- ldap r11, RxALow
- setv res[r1], r11
- eeu res[RXA]
+ ldap r11, TxHandShakeReceived
+ setv res[RXD], r11
+
+ConfigRxA: // Configure a event on RXA going low, used during packet reception
+ setc res[RXA], XS1_SETC_COND_EQ
+ setc res[RXA], XS1_SETC_IE_MODE_EVENT
+ ldc r11, 0
+ setd res[RXA], r11
+ ldap r11, RxALow
+ setv res[RXA], r11
+ eeu res[RXA]
ConfigValidToken:
- ldw r10, dp[flag0_port] // Valid token port
- setc res[r10], XS1_SETC_COND_NONE
- ldap r11, TxHandshakeTimeOut // ValidToken is used for timing timeout period when expecting an ack after tx
- setv res[r10], r11
-#if 0
- // Port counter used instead
-TxHandShakeTimer: // Used for timeout waiting for handshake after tx
- getr r10, XS1_RES_TYPE_TIMER
- ecallf r10
-
- ldap r11, TxHandshakeTimeOut
- setv res[r10], r11
- setc res[r10], XS1_SETC_COND_AFTER
-
- stw r10, sp[8] // Save timer resource ID to the stack
+#ifdef __XS2A__
+ ldw r10, sp[STACK_VTOK_PORT] // ValidToken is used for timing timeout period when expecting an ack after tx
+#else
+ ldw r10, dp[rx_rdy] // TODO use from stack
#endif
-
-SetupOutTimer:
- getr r10, XS1_RES_TYPE_TIMER
- ecallf r10
-
- ldap r11, OutDataTimeOut
- setv res[r10], r11
- setc res[r10], XS1_SETC_COND_AFTER
-
- stw r10, sp[9]
+ setc res[r10], XS1_SETC_COND_NONE
+ ldap r11, TxHandshakeTimeOut
+ setv res[r10], r11
#ifndef XUD_TEST_MODE_SUPPORT_DISABLED
SetupUsbTestMode:
@@ -277,7 +215,7 @@ SetupUsbTestMode:
ldaw r9, dp[epChans0]
ldw r10, r9[0] // Load channel 0
- ldap r11, XUD_UsbTestModeHandler
+ ldap r11, UsbTestModeHandler_asm
setc res[r10], XS1_SETC_IE_MODE_INTERRUPT
setv res[r10], r11
eeu res[r10]
@@ -289,34 +227,43 @@ SetupUsbTestMode:
setv res[r10], r11
eeu res[r10]
#endif
-
-PortsOnStack: // Put ports on stack (loads therefore short insts)
- ldw r11, dp[flag1_port] // RxA
- stw r11, sp[10]
- ldw r11, dp[flag0_port] // Valid token port
- stw r11, sp[STACK_FLAG0_PORT]
+
+CrcRxResidualsOnStack:
+ ldc r11, 0x7000
+ stw r11, sp[STACK_RXCRC_TAIL0]
+ ldc r11, 0x80be
+ stw r11, sp[STACK_RXCRC_TAIL1]
ldc r11, 0x3ffe
- stw r11, sp[12]
-
- ldw r11, sp[(STACK_EXTEND+7)]
+ stw r11, sp[STACK_RXCRC_TAIL2]
+ ldc r11, 0x3ffe
+ stw r11, sp[STACK_RXCRC_TAIL3]
+
+ ldc r11, 0xf335 // CRC16 init (in)
+ stw r11, sp[STACK_TXCRC_INIT]
+
+ ldc r11, 0x3334 // CRC16 init (out)
+ stw r11, sp[STACK_RXCRC_INIT]
+
+ ldw r11, sp[STACK_EPCHANS]
stw r11, dp[chanArray]
ConfigSofJump:
- ldw r11, sp[(STACK_EXTEND+9)]
+ ldw r11, sp[STACK_SOFCHAN]
+ ldaw r10, dp[PidJumpTable]
bt r11, ConfigSofJump_Done
ldap r11, Pid_Sof_NoChan
- ldaw r10, dp[PidJumpTable]
-#ifdef ARCH_L
+#ifdef __XS2A__
stw r11, r10[5]
#else
ldc r9, 0xa5
stw r11, r10[r9]
#endif
ConfigSofJump_Done:
+ stw r10, sp[STACK_PIDJUMPTABLE]
+ ldaw r10, dp[handshakeTable_IN] // Load handshake table
+ stw r10, sp[STACK_HANDSHAKETABLEIN]
ConfigRxErrEventVector:
- stw r3, sp[15] // Store flag port to stack
-#if 0 // RxError Interrupts Disabled
setc res[r3], XS1_SETC_COND_EQ
setc res[r3], XS1_SETC_IE_MODE_INTERRUPT
ldap r11, Err_RxErr
@@ -324,14 +271,12 @@ ConfigRxErrEventVector:
ldc r11, 1
setd res[r3], r11 // Set event cond data to 1
eeu res[r3]
-#endif
-
SetupSuspendResetTimer:
getr r10, XS1_RES_TYPE_TIMER
ecallf r10
- stw r10, sp[14]
+ stw r10, sp[STACK_SUSPEND_TIMER]
ldap r11, ResetIntHandler
setv res[r10], r11
@@ -341,7 +286,6 @@ SetupSuspendResetTimer:
ldw r9, cp[suspendTimeout]
add r11, r11, r9
setd res[r10], r11
-
setc res[r10], XS1_SETC_COND_AFTER
setc res[r10], XS1_SETC_IE_MODE_INTERRUPT
eeu res[r10] // Enable events/interupts on resource
@@ -353,135 +297,66 @@ SetupSuspendResetTimer:
bu NextToken
// Main IO Loop
-.align 4
+.align FUNCTION_ALIGNMENT
.skip 0
NextToken:
ldc r9, 0xa001 // CRC16 poly, used in doRxData
- ldw r5, sp[(STACK_EXTEND+7)] // EP structures array - pointers to EP tables or 0
- ldc r7, 0xf335 // TX Crc init
+ ldw r5, sp[(STACK_EXTEND+4)] // EP structures array - pointers to EP tables or 0
NextTokenAfterOut:
+ ldc r7, 0xf335 // TX Crc init
ldc r6, 0x3334 // CRC16 init (out) - Needs reseting after an out
-#ifndef ARCH_G
- ldw r1, sp[STACK_FLAG0_PORT]
-#else
- //ldaw r1, dp[crc5Table_Addr]
+#ifdef __XS2A__
+ ldw r1, sp[STACK_VTOK_PORT]
#endif
+
NextTokenAfterInNak:
Loop_BadPid:
- //ldc r4, XUD_MAX_NUM_EP_OUT // Number of OUT endpoints
NextTokenAfterPing:
setsr 1 // Enable thread events
-
-
-//------------------------------------------------------------------------------------------------
-#ifdef ARCH_L
- //ldw r1, sp[11] // Load Valid Token port
- ldaw r10, dp[PidJumpTable] // TODO Could load from sp here
- // Original USB Token: | CRC | EP | ADDR | PID | junk
- // Received token is address and CRC checked.
- // We receive: | 0000 4-bit EP | 0000 4-bit PID |
-XUD_TokenRx_Pid:
- inpw r11, res[RXD], 8 // Read 8 bit PID
- shr r11, r11, 24 // Shift off junk
-
- ldw r10, r10[r11] // Load relevant branch address
-
-#if 1
-BranchOnTokenPid:
-.xtabranch Pid_Out, Pid_Sof, Pid_In, Pid_Setup, Pid_Sof_NoChan
-
- bau r10
-
-#else
-XUD_TokenRx_Ep:
- inpw r10, res[RXD], 8 // Read EP Number
- shr r10, r10, 24 // Shift off junk
-
-CheckValidToken:
- in r1, res[r1]
- bt r1, InvalidToken // If VALID_TOKEN not high, ignore token
- // REMEMBER VALID TOKEN NOW INVERTED!
-
-BranchOnTokenPid:
-.xtabranch Pid_Out, Pid_Sof, Pid_In, Pid_Setup, Pid_Sof_NoChan
- bau r11 // Branch on PID to relevant token handing code
- // (e.g. in utmi_out.S etc). When done branchs back to NextToken
-#endif
-#else // ARCH_G
- ldc r4, 16
-
-ReadToken:
- inpw r11, res[RXD], 8 // Read 3 byte token from data port | CRC[5] | EP[4] | ADDR[7] | PID[8] | junk
- ldaw r10, dp[PidJumpTable]
- setpsc res[RXD], r4
- shr r11, r11, 24
-
-JumpOnPid:
- ldw r11, r10[r11]
-.xtabranch Pid_Out, Pid_Sof, Pid_In, Pid_Setup
- bau r11
-
-BadCrcAddr:
- // zext r11, 8
- // ldc r10, PIDn_SOF
- // eq r11, r11, r10
- //ecallt r11
- //bt r11, Pid_Sof_NoChan // TODO we should really CRC SOFs
-
- ldw r11, sp[10]
-waitforRXALow0:
- in r10, res[r11]
- bt r10, waitforRXALow0
- setc res[RXD], XS1_SETC_RUN_CLRBUF
- bu Loop_BadPid
-
-#endif
-
+ #include "XUD_TokenJmp.S"
// Un-implemented PID list
-Pid_Reserved: // Should never get here
-//Pid_Out:
+Pid_Reserved:
Pid_Ack:
-//Pid_Ping:
-//Pid_Sof: // Should never get here: (G4) hardware swallows SOF
Pid_NYet:
Pid_Nyet:
Pid_Data2:
Pid_Split:
-//Pid_In:
Pid_Nak:
Pid_Pre:
-//Pid_Setup:
Pid_Stall:
Pid_MData:
Pid_Datam:
Pid_Data0:
Pid_Data1:
-Pid_Bad: // Bad PID received, ignore
+Pid_Bad: // Bad PID received, ignore
-InvalidToken:
XUD_InvalidToken:
- ldw r10, sp[10] // Load RxA Port ID (r1)
-waitforRXALow:
+ ldw r10, sp[STACK_RXA_PORT] // Load RxA Port ID (r1)
XUD_InvalidTok_waitforRXALow:
in r11, res[r10]
- bt r11, waitforRXALow
+ bt r11, XUD_InvalidTok_waitforRXALow
setc res[RXD], XS1_SETC_RUN_CLRBUF
- bu Loop_BadPid // Invalid token received Ignore unknown toks
+ bu Loop_BadPid // Invalid token received Ignore unknown toks
-
-.align 4
+.align FUNCTION_ALIGNMENT
Return:
- //ldw r11, sp[8] # Free timers
- //freer res[r11]
- ldw r11, sp[9]
- freer res[r11]
- ldw r11, sp[14]
+ clre
+ ldw r11, sp[STACK_SUSPEND_TIMER] // Free suspend/reset timer
+ edu res[r11]
freer res[r11]
- ldw r4, sp[1] # Register restore
+ ldw r11, sp[STACK_RXE_PORT] // Put RxE IE mode back to events..
+ setc res[r11], XS1_SETC_COND_NONE
+ edu res[r11]
+ setc res[r11], XS1_SETC_IE_MODE_EVENT
+
+ ldw r11, sp[STACK_RXA_PORT]
+ edu res[r11]
+
+ ldw r4, sp[1] // Register restore
ldw r5, sp[2]
ldw r6, sp[3]
ldw r7, sp[4]
@@ -494,7 +369,6 @@ Return:
.cc_bottom XUD_LLD_IoLoop.func
-
-
// Tables of tables...
#include "./included/XUD_PidJumpTable.S"
+
diff --git a/lib_xud/src/core/XUD_Main.xc b/lib_xud/src/core/XUD_Main.xc
index 599061fb..09318418 100755
--- a/lib_xud/src/core/XUD_Main.xc
+++ b/lib_xud/src/core/XUD_Main.xc
@@ -1,8 +1,9 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/** XUD_Manager.xc
- * @brief XMOS USB Device(XUD) Layer
+/**
+ * @file XUD_Main.xc
+ * @brief XMOS USB Device (XUD) Layer
* @author Ross Owen
**/
/* Error printing functions */
@@ -20,287 +21,52 @@ void XUD_Error_hex(char errString[], int i_err);
#include
#include "xud.h" /* External user include file */
-#include "XUD_UIFM_Defines.h"
#include "XUD_USB_Defines.h"
-#include "XUD_USBTile_Support.h"
#include "XUD_Support.h"
-#include "XUD_UIFM_Functions.h"
#include "XUD_DeviceAttach.h"
-#include "XUD_PowerSig.h"
-
-#ifdef ARCH_L
-#elif ARCH_G
-#else
-#error ARCH_L or ARCH_G must be defined
-#endif
-
-#ifdef ARCH_S
-#include "xs1_su_registers.h"
-#endif
-
-#ifdef ARCH_X200
-#include "xs1_to_glx.h"
-#include "xs2_su_registers.h"
-#endif
-
-#if defined(ARCH_X200) || defined(ARCH_S)
-#include "XUD_USBTile_Support.h"
-//#include
-extern unsigned get_tile_id(tileref ref);
-extern tileref USB_TILE_REF;
-#endif
+#include "XUD_Signalling.h"
+#include "XUD_HAL.h"
+#include "XUD_TimingDefines.h"
#if (USB_MAX_NUM_EP_IN != 16)
#error USB_MAX_NUM_EP_IN must be 16!
#endif
-
#if (USB_MAX_NUM_EP_OUT != 16)
#error USB_MAX_NUM_EP_OUT must be 16!
#endif
-extern int XUD_GetDone();
-
void XUD_UserSuspend();
void XUD_UserResume();
void XUD_PhyReset_User();
-#if 0
-#pragma xta command "config threads stdcore[0] 6"
-#pragma xta command "add exclusion Pid_Out"
-#pragma xta command "add exclusion Pid_Setup"
-#pragma xta command "add exclusion Pid_Sof"
-#pragma xta command "add exclusion Pid_Reserved"
-#pragma xta command "add exclusion Pid_Ack"
-#pragma xta command "add exclusion Pid_Data0"
-#pragma xta command "add exclusion Pid_Ping"
-#pragma xta command "add exclusion Pid_Nyet"
-#pragma xta command "add exclusion Pid_Data2"
-#pragma xta command "add exclusion Pid_Data1"
-#pragma xta command "add exclusion Pid_Data0"
-#pragma xta command "add exclusion Pid_Datam"
-#pragma xta command "add exclusion Pid_Split"
-#pragma xta command "add exclusion Pid_Stall"
-#pragma xta command "add exclusion Pid_Pre"
-#pragma xta command "add exclusion InvalidToken"
-#pragma xta command "add exclusion InReady"
-
-#pragma xta command "analyse path XUD_TokenRx_Pid XUD_TokenRx_Ep"
-#pragma xta command "set required - 33 ns"
-#endif
-
-
-/* Rx to TX 16 clks required with SMSC phy (14 in spec). SIE Decision Time */
-#if 0
-#pragma xta command "analyse path XUD_TokenRx_Ep XUD_IN_TxNak"
-#pragma xta command "set required - 233 ns"
-#pragma xta command "add exclusion InNotReady"
-#pragma xta command "remove exclusion InReady"
-
-
-#pragma xta command "add exclusion XUD_IN_TxPid_Tail1"
-#pragma xta command "add exclusion XUD_IN_TxPid_Tail2"
-#pragma xta command "add exclusion XUD_IN_TxPid_Tail3"
-#pragma xta command "add exclusion XUD_IN_TxPid_TailS0"
-#pragma xta command "add exclusion XUD_IN_TxPid_TailS1"
-#pragma xta command "add exclusion XUD_IN_TxPid_TailS2"
-#pragma xta command "add exclusion XUD_IN_TxPid_TailS3"
-#endif
-#if 0
-#pragma xta command "analyse path XUD_TokenRx_Ep XUD_IN_TxPid_Tail0"
-#pragma xta command "set required - 266 ns"
-#endif
-
-#if 0
-#pragma xta command "remove exclusion XUD_IN_TxPid_TailS0"
-#pragma xta command "add exclusion XUD_IN_TxPid_Tail0"
-#pragma xta command "analyse path XUD_TokenRx_Ep XUD_IN_TxPid_TailS0"
-#pragma xta command "set required - 266 ns"
-
-#pragma xta command "remove exclusion XUD_IN_TxPid_Tail1"
-#pragma xta command "add exclusion XUD_IN_TxPid_TailS0"
-#if 0
-#pragma xta command "analyse path XUD_TokenRx_Ep XUD_IN_TxPid_Tail1"
-#pragma xta command "set required - 266 ns"
-#endif
-
-#pragma xta command "remove exclusion XUD_IN_TxPid_TailS1"
-#pragma xta command "add exclusion XUD_IN_TxPid_Tail1"
-#if 0
-#pragma xta command "analyse path XUD_TokenRx_Ep XUD_IN_TxPid_TailS1"
-#pragma xta command "set required - 266 ns"
-#endif
-
-//#pragma xta command "remove exclusion ShortPacket"
-//pragma xta command "add exclusion NormalPacket"
-//#pragma xta command "analyse path XUD_TokenRx_Ep XUD_IN_TxPid_Short"
-//#pragma xta command "set required - 233 ns"
-
-/* TX TO RX */
-/* Tx IN NAK to Token Rx */
-#pragma xta command "remove exclusion InNotReady"
-#pragma xta command "add exclusion InReady"
-#if 0
-#pragma xta command "analyse path XUD_TokenRx_Pid XUD_IN_TxNak"
-#pragma xta command "set required - 100 ns"
-#endif
-
-/* Tx OUT NAK to Token RX */
-#if 0
-#pragma xta command "analyse path XUD_OUT_TxNak XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-#endif
-
-/* Tx OUT ACK to Token Tx */
-#if 0
-#pragma xta command "analyse path XUD_OUT_TxAck XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-#endif
-
-/* Tx IN Data (so crc) to Rx Ack (Non ISO IN) */
-#pragma xta command "add exclusion InNotReady"
-#pragma xta command "remove exclusion InReady"
-#if 0
-#pragma xta command "add exclusion InISO"
-#pragma xta command "add exclusion TxHandshakeTimeOut"
-#endif
-
-#pragma xta command "remove exclusion XUD_IN_TxPid_Tail0"
-#pragma xta command "add exclusion XUD_IN_TxPid_TailS1"
-#if 0
-#pragma xta command "analyse path XUD_IN_TxCrc_Tail0 XUD_IN_RxAck"
-#pragma xta command "set required - 100 ns"
-#endif
-
-#pragma xta command "add exclusion XUD_IN_TxPid_Tail0"
-#pragma xta command "remove exclusion XUD_IN_TxPid_Tail1"
-#if 0
-#pragma xta command "analyse path XUD_IN_TxCrc_Tail1 XUD_IN_RxAck"
-#pragma xta command "set required - 100 ns"
-#endif
-
-#pragma xta command "add exclusion XUD_IN_TxPid_Tail1"
-#pragma xta command "remove exclusion XUD_IN_TxPid_TailS0"
-#if 0
-#pragma xta command "analyse path XUD_IN_TxCrc_TailS0 XUD_IN_RxAck"
-#pragma xta command "set required - 100 ns"
-#endif
-
-#pragma xta command "add exclusion XUD_IN_TxPid_TailS0"
-#pragma xta command "remove exclusion XUD_IN_TxPid_TailS1"
-#if 0
-#pragma xta command "analyse path XUD_IN_TxCrc_TailS1 XUD_IN_RxAck"
-#pragma xta command "set required - 100 ns"
-#endif
-
-/* Tx IN Data (so crc) to Rx Token PID (ISO In) */
-#pragma xta command "remove exclusion InISO"
-#pragma xta command "add exclusion InNonISO"
-
-#if 0
-#pragma xta command "analyse path XUD_IN_TxCrc_Tail0 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-
-#pragma xta command "analyse path XUD_IN_TxCrc_Tail1 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-
-#pragma xta command "analyse path XUD_IN_TxCrc_Tail2 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-
-#pragma xta command "analyse path XUD_IN_TxCrc_Tail3 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-
-#pragma xta command "analyse path XUD_IN_TxCrc_TailS0 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-
-#pragma xta command "analyse path XUD_IN_TxCrc_TailS1 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-
-#pragma xta command "analyse path XUD_IN_TxCrc_TailS2 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-
-#pragma xta command "analyse path XUD_IN_TxCrc_TailS3 XUD_TokenRx_Pid"
-#pragma xta command "set required - 100 ns"
-#endif
-
-/* RX TO RX */
-/* Rx SOF to Rx SOF - This is a non-interesting case since timing will be ~125uS */
-
-//#pragma xta command "remove exclusion Pid_Sof"
-//#pragma xta command "add exclusion Pid_Out"
-//#pragma xta command "add exclusion Pid_In"
-#if 0
-#pragma xta command "analyse path XUD_TokenRx_Ep XUD_TokenRx_Pid"
-#pragma xta command "set required - 50 ns"
-#endif
-
-/* Rx OUT Data end to Rx Token (ISO Out Data) */
-//#pragma xta command "add exclusion OutTail0"
-//#pragma xta command "add exclusion OutTail1"
-//#pragma xta command "add exclusion OutTail2"
-//#pragma xta command "add exclusion OutTail3"
-//#pragma xta command "add exclusion OutTail4"
-//#pragma xta command "add exclusion OutTail5"
-//#pragma xta command "add exclusion ReportBadCrc"
-//#pragma xta command "add exclusion DoOutHandShakeOut"
-#if 0
-#pragma xta command "analyse path XUD_OUT_RxTail XUD_TokenRx_Pid"
-#pragma xta command "set required - 50 ns"
-#endif
-
-
-#endif
-/* TX INTRA PACKET TIMING */
-#if 0
-#pragma xta command "analyse path XUD_IN_TxPid_Tail0 TxLoop0_Out"
-#pragma xta command "set required - 83 ns"
-#endif
-
-/* Timeout differences due to using 60MHz vs 100MHz */
-#if !defined(ARCH_S) && !defined(ARCH_X200)
-#define HS_TX_HANDSHAKE_TIMEOUT 100
-#define FS_TX_HANDSHAKE_TIMEOUT 3000
-#else
#define HS_TX_HANDSHAKE_TIMEOUT (167)
#define FS_TX_HANDSHAKE_TIMEOUT (5000)
-#endif
/* Global vars for current and desired USB speed */
unsigned g_curSpeed;
unsigned g_desSpeed;
unsigned g_txHandshakeTimeout;
-unsigned g_prevPid=0xbadf00d;
-unsigned int data_pid=0xbadf00d;
-
-#if defined(ARCH_S) || defined (ARCH_X200)
-/* USB Port declarations - for Zevious with Galaxion */
-extern out port tx_readyout; // aka txvalid
-extern in port tx_readyin;
-extern out buffered port:32 p_usb_txd;
-extern in buffered port:32 p_usb_rxd;
-extern in port rx_rdy;
-extern in port flag0_port;
-extern in port flag1_port;
-extern in port flag2_port;
-extern in buffered port:32 p_usb_clk;
-extern clock tx_usb_clk;
-extern clock rx_usb_clk;
-#define reg_write_port null
-#define reg_read_port null
+
+in port flag0_port = PORT_USB_FLAG0; /* For XS3: Mission: RXE, XS2 is configurable and set to RXE in mission mode */
+in port flag1_port = PORT_USB_FLAG1; /* For XS3: Mission: RXA, XS2 is configuratble and set to RXA in mission mode*/
+
+/* XS2A has an additonal flag port. In Mission mode this is set to VALID_TOKEN */
+#ifdef __XS2A__
+in port flag2_port = PORT_USB_FLAG2;
#else
-extern in buffered port:32 p_usb_clk;
-extern out port reg_write_port;
-extern in port reg_read_port;
-extern in port flag0_port;
-extern in port flag1_port;
-extern in port flag2_port;
-extern out port p_usb_txd;
-extern port p_usb_rxd;
+#define flag2_port null
#endif
-#ifdef XUD_ISO_OUT_COUNTER
-int xud_counter = 0;
-#endif
+in buffered port:32 p_usb_clk = PORT_USB_CLK;
+out buffered port:32 p_usb_txd = PORT_USB_TXD;
+in buffered port:32 p_usb_rxd = PORT_USB_RXD;
+out port tx_readyout = PORT_USB_TX_READYOUT;
+in port tx_readyin = PORT_USB_TX_READYIN;
+in port rx_rdy = PORT_USB_RX_READY;
+
+on USB_TILE: clock tx_usb_clk = XS1_CLKBLK_2;
+on USB_TILE: clock rx_usb_clk = XS1_CLKBLK_3;
XUD_chan epChans[USB_MAX_NUM_EP];
XUD_chan epChans0[USB_MAX_NUM_EP];
@@ -324,51 +90,20 @@ typedef struct XUD_ep_info
XUD_ep_info ep_info[USB_MAX_NUM_EP];
-/* Sets the UIFM flags into a mode suitable for power signalling */
-void XUD_UIFM_PwrSigFlags()
-{
-#if defined(ARCH_X200)
- write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_GLX_PER_UIFM_MASK_NUM, ((1< 500)
+ #define RX_RISE_DELAY 2
+ #define RX_FALL_DELAY 5
+ #define TX_RISE_DELAY 2
+ #define TX_FALL_DELAY 3
+ #elif (XUD_CORE_CLOCK > 400)
+ #define RX_RISE_DELAY 5
+ #define RX_FALL_DELAY 5
+ #define TX_RISE_DELAY 2
+ #define TX_FALL_DELAY 3
+ #else /* 400 */
+ #define RX_RISE_DELAY 3
+ #define RX_FALL_DELAY 5
+ #define TX_RISE_DELAY 3
+ #define TX_FALL_DELAY 3
+ #endif
#else
-#define TX_FALL_DELAY 1
+ #define RX_RISE_DELAY 5
+ #define RX_FALL_DELAY 5
+ #define TX_RISE_DELAY 5
+ #define TX_FALL_DELAY 1
#endif
-#define RX_RISE_DELAY 5
-#define RX_FALL_DELAY 5
// Set up USB ports. Done in ASM as read port used in both directions initially.
// Main difference from xevious is IFM not enabled.
@@ -483,8 +216,8 @@ static int XUD_Manager_loop(XUD_chan epChans0[], XUD_chan epChans[], chanend ?c
// Xevious needed asm as non-standard usage (to avoid clogging 1-bit ports)
// GLX uses 1bit ports so shouldn't be needed.
// Handshaken ports need USB clock
- configure_clock_src (tx_usb_clk, p_usb_clk);
- configure_clock_src (rx_usb_clk, p_usb_clk);
+ configure_clock_src(tx_usb_clk, p_usb_clk);
+ configure_clock_src(rx_usb_clk, p_usb_clk);
//this along with the following delays forces the clock
//to the ports to be effectively controlled by the
@@ -492,7 +225,7 @@ static int XUD_Manager_loop(XUD_chan epChans0[], XUD_chan epChans[], chanend ?c
set_port_inv(p_usb_clk);
set_port_sample_delay(p_usb_clk);
-#ifndef SIMULATION
+#if !defined(XUD_SIM_XSIM)
//This delay controls the capture of rdy
set_clock_rise_delay(tx_usb_clk, TX_RISE_DELAY);
@@ -502,139 +235,32 @@ static int XUD_Manager_loop(XUD_chan epChans0[], XUD_chan epChans[], chanend ?c
//this delay th capture of the rdyIn and data.
set_clock_rise_delay(rx_usb_clk, RX_RISE_DELAY);
set_clock_fall_delay(rx_usb_clk, RX_FALL_DELAY);
-#else
- set_clock_fall_delay(tx_usb_clk, TX_FALL_DELAY+5);
#endif
-
- //set_port_sample_delay(p_usb_rxd);
- //set_port_sample_delay(rx_rdy);
- set_port_inv(flag0_port);
-#ifndef SIMULATION
- set_pad_delay(flag1_port, 2);
+#ifdef __XS3A__
+ set_pad_delay(flag1_port, 3);
+#else
+ set_pad_delay(flag1_port, 2);
#endif
+
+ start_clock(tx_usb_clk);
+ start_clock(rx_usb_clk);
- start_clock(tx_usb_clk);
- start_clock(rx_usb_clk);
configure_out_port_handshake(p_usb_txd, tx_readyin, tx_readyout, tx_usb_clk, 0);
configure_in_port_strobed_slave(p_usb_rxd, rx_rdy, rx_usb_clk);
-#endif
- while(!XUD_GetDone())
- {
-#if !defined(ARCH_S) && !defined(ARCH_X200)
- p_usb_rxd <: 0; // Note, this is important else phy clocks in invalid data before UIFM is enabled causing
- clearbuf(p_usb_rxd); // connection issues
-#endif
+ /* Clock RxA port from USB clock - helps fall event */
+ configure_in_port(flag1_port, rx_usb_clk);
-#if defined(ARCH_S) || defined(ARCH_X200)
+ unsigned noExit = 1;
-#ifndef SIMULATION
+ while(noExit)
+ {
unsigned settings[] = {0};
-
-#if defined (ARCH_X200)
- /* For xCORE-200 enable USB port muxing before enabling phy etc */
- XUD_EnableUsbPortMux(); //setps(XS1_PS_XCORE_CTRL0, UIFM_MODE);
-#endif
- /* Enable the USB clock */
- write_sswitch_reg(get_tile_id(USB_TILE_REF), XS1_SU_CFG_RST_MISC_NUM, ( 1 << XS1_SU_CFG_USB_CLK_EN_SHIFT));
-
-#ifdef ARCH_S
- /* Now reset the phy */
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_PHY_CONTROL_NUM, 1); //(1< int _;
- p_usb_clk when pinseq(0) :> int _;
- p_usb_clk when pinseq(1) :> int _;
- p_usb_clk when pinseq(0) :> int _;
-
-#if !defined(ARCH_S) && !defined(ARCH_X200)
- /* Configure ports and clock blocks for use with UIFM */
- XUD_UIFM_PortConfig(p_usb_clk, reg_write_port, reg_read_port, flag0_port, flag1_port, flag2_port, p_usb_txd, p_usb_rxd) ;
-
- //set_pad_delay(flag1_port, 5);
- set_port_inv(flag0_port);
-
-#endif
-
-#if (defined(ARCH_L) && !defined(ARCH_X200) && !defined(ARCH_S)) || defined(ARCH_G)
- /* For L/G series we wait for clock from phy, then enable UIFM logic */
- // 3 u series, else 2
-#if defined (ARCH_S)
- XUD_UIFM_Enable(3); //setps(XS1_PS_XCORE_CTRL0, UIFM_MODE);
-#else
- XUD_UIFM_Enable(2); //setps(XS1_PS_XCORE_CTRL0, UIFM_MODE);
-#endif
-#endif
-
-#if defined(ARCH_X200)
-#define XS1_UIFM_USB_PHY_EXT_CTRL_REG 0x50
-#define XS1_UIFM_USB_PHY_EXT_CTRL_VBUSVLDEXT_MASK 0x4
- /* Remove requirement for VBUS in bus-powered mode */
- if(pwrConfig == XUD_PWR_BUS)
- {
- write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_UIFM_USB_PHY_EXT_CTRL_REG, XS1_UIFM_USB_PHY_EXT_CTRL_VBUSVLDEXTSEL_MASK | XS1_UIFM_USB_PHY_EXT_CTRL_VBUSVLDEXT_MASK);
- }
-
-#define PHYTUNEREGVAL 0x0093B264
-#define XS1_UIFM_USB_PHY_TUNE_REG 0x4c
- /* Phy Tuning parameters */
- /* OTG TUNE: 3b'100
- * TXFSLSTUNE: 4b'1001
- * TXVREFTUNE:4b'1001 -- +1.25% adjustment in HS DC voltage level
- * BIASTUNE: 1b'0
- * COMDISTUNE:3b'011 -- -1.5% adjustment from default (disconnect threshold adjustment)
- * SQRXTUNE:3b'010 -- +5% adjustment from default (Squelch Threshold)
- * TXRISETUNE: 1b'0
- * TXPREEMPHASISTUNE:1b'1 -- enabled (default is disabled)
- * TXHSXVTUNE: 2b'11
- */
- write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_UIFM_USB_PHY_TUNE_REG, PHYTUNEREGVAL);
-#endif
-
-#if defined(ARCH_S) || defined(ARCH_X200)
-#ifndef SIMULATION
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_CONTROL_NUM, (1< void;
}
}
-#ifndef SIMULATION
-#if defined(ARCH_S) || defined(ARCH_X200)
+
/* Go into full speed mode: XcvrSelect and Term Select (and suspend) high */
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM,
- (1< time;
+ t when timerafter(time + SUSPEND_T_WTWRSTHS_ticks) :> int _;// T_WTRSTHS: 100-875us
/* Sample line state and check for reset (or suspend) */
- flag2_port :> reset; /* SE0 Line */
+ XUD_LineState_t ls = XUD_HAL_GetLineState();
+ if(ls == XUD_LINESTATE_SE0)
+ reset == 1;
+ else
+ reset = 0;
}
-#endif
/* Inspect for suspend or reset */
if(!reset)
{
@@ -714,9 +330,8 @@ static int XUD_Manager_loop(XUD_chan epChans0[], XUD_chan epChans[], chanend ?c
/* Run user resume code */
XUD_UserResume();
}
-
/* Test if coming back from reset or suspend */
- if(reset==1)
+ if(reset == 1)
{
if(!sentReset)
@@ -724,53 +339,38 @@ static int XUD_Manager_loop(XUD_chan epChans0[], XUD_chan epChans[], chanend ?c
SendResetToEps(epChans0, epChans, epTypeTableOut, epTypeTableIn, noEpOut, noEpIn, USB_RESET_TOKEN);
sentReset = 1;
}
-#ifdef ARCH_G
- XUD_SetCrcTableAddr(0);
-#endif
-
- /* Check for exit */
- if (XUD_GetDone())
- {
- break;
- }
-
+
/* Reset the OUT ep structures */
for(int i = 0; i< noEpOut; i++)
{
-#ifdef ARCH_G
+#ifdef __XS3A__
ep_info[i].pid = USB_PIDn_DATA0;
#else
ep_info[i].pid = USB_PID_DATA0;
#endif
}
-
/* Reset in the ep structures */
for(int i = 0; i< noEpIn; i++)
{
ep_info[USB_MAX_NUM_EP_OUT+i].pid = USB_PIDn_DATA0;
}
- /* Set default device address */
-#if defined(ARCH_S) || defined(ARCH_X200)
-#ifndef SIMULATION
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_DEVICE_ADDRESS_NUM, 0);
-#endif
-#else
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_ADDRESS, 0x0);
-#endif
+ /* Set default device address - note, for normal operation this is 0, but can be other values for testing */
+ XUD_HAL_SetDeviceAddress(XUD_STARTUP_ADDRESS);
-#ifdef SIMULATION
- if(g_desSpeed == XUD_SPEED_HS)
- {
+#ifdef XUD_BYPASS_RESET
+ #if defined(XUD_TEST_SPEED_HS)
g_curSpeed = XUD_SPEED_HS;
g_txHandshakeTimeout = HS_TX_HANDSHAKE_TIMEOUT;
- }
- else
- {
+ XUD_HAL_EnterMode_PeripheralHighSpeed();
+ #elif defined(XUD_TEST_SPEED_FS)
g_curSpeed = XUD_SPEED_FS;
g_txHandshakeTimeout = FS_TX_HANDSHAKE_TIMEOUT;
- }
+ XUD_HAL_EnterMode_PeripheralFullSpeed(); //Technically not required since we should already be in FS mode..
+ #else
+ #error XUD_TEST_SPEED_ must be defined if using XUD_BYPASS_RESET!
+ #endif
#else
if(g_desSpeed == XUD_SPEED_HS)
{
@@ -807,96 +407,32 @@ static int XUD_Manager_loop(XUD_chan epChans0[], XUD_chan epChans[], chanend ?c
}
}
-
- /* Set UIFM to CHECK TOKENS mode and enable LINESTATE_DECODE
- NOTE: Need to do this every iteration since CHKTOK would break power signaling */
-#ifdef ARCH_L
-#if defined(ARCH_S) || defined(ARCH_X200)
-#ifndef SIMULATION
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_CONTROL_NUM, (1<
-
-void XUD_PhyReset_User()
-{
- return;
-}
-
-
-
-
diff --git a/lib_xud/src/core/XUD_Ports.xc b/lib_xud/src/core/XUD_Ports.xc
deleted file mode 100644
index 33b7a5e1..00000000
--- a/lib_xud/src/core/XUD_Ports.xc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2015-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#include "xud.h"
-
-#if 0
-in port flag0_port = PORT_USB_FLAG0;
-in port flag1_port = PORT_USB_FLAG1;
-in port flag2_port = PORT_USB_FLAG2;
-
-in buffered port:32 p_usb_clk = PORT_USB_CLK;
-out buffered port:32 p_usb_txd = PORT_USB_TXD;
-in buffered port:32 p_usb_rxd = PORT_USB_RXD;
-out port tx_readyout = PORT_USB_TX_READYOUT;
-in port tx_readyin = PORT_USB_TX_READYIN;
-in port rx_rdy = PORT_USB_RX_READY;
-
-// TODO - clockblocks should not be hard coded here */
-on USB_TILE: clock tx_usb_clk = XS1_CLKBLK_5;
-on USB_TILE: clock rx_usb_clk = XS1_CLKBLK_4;
-
-
-
-#else
-in port flag0_port = PORT_USB_FLAG0;
-in port flag1_port = PORT_USB_FLAG1;
-in port flag2_port = PORT_USB_FLAG2;
-
-//#if (XUD_SERIES_SUPPORT == XUD_U_SERIES)
-#if defined(ARCH_S) || defined(ARCH_X200)
- in buffered port:32 p_usb_clk = PORT_USB_CLK;
- out buffered port:32 p_usb_txd = PORT_USB_TXD;
- in buffered port:32 p_usb_rxd = PORT_USB_RXD;
- out port tx_readyout = PORT_USB_TX_READYOUT;
- in port tx_readyin = PORT_USB_TX_READYIN;
- in port rx_rdy = PORT_USB_RX_READY;
-
- on USB_TILE: clock tx_usb_clk = XS1_CLKBLK_5;
- on USB_TILE: clock rx_usb_clk = XS1_CLKBLK_4;
-
-//#elif (XUD_SERIES_SUPPORT == XUD_L_SERIES) || (XUD_SERIES_SUPPORT == XUD_G_SERIES)
-#elif defined(ARCH_L) || defined(ARCH_G)
-
- in port p_usb_clk = PORT_USB_CLK;
- out port reg_write_port = PORT_USB_REG_WRITE;
- in port reg_read_port = PORT_USB_REG_READ;
- out port p_usb_txd = PORT_USB_TXD;
- port p_usb_rxd = PORT_USB_RXD;
- in port p_usb_stp = PORT_USB_STP_SUS;
-#else
- #error XUD_SERIES_SUPPORT not equal to XUD_U_SERIES, XUD_G_SERIES or XUD_L_SERIES
-#endif
-#endif
-
-
-
-
diff --git a/lib_xud/src/core/XUD_PowerSig.xc b/lib_xud/src/core/XUD_PowerSig.xc
deleted file mode 100755
index 5cb4f2f7..00000000
--- a/lib_xud/src/core/XUD_PowerSig.xc
+++ /dev/null
@@ -1,459 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/** @file XUD_PowerSig.xc
- * @brief Functions for USB power signaling
- * @author Ross Owen, XMOS Limited
- **/
-
-#include
-#include
-
-#include "xud.h"
-#include "XUD_Support.h"
-#include "XUD_UIFM_Functions.h"
-#include "XUD_USB_Defines.h"
-#include "XUD_UIFM_Defines.h"
-
-#ifdef ARCH_X200
-#include "xs1_to_glx.h"
-#include "xs2_su_registers.h"
-#endif
-
-#ifdef ARCH_S
-#include "xs1_su_registers.h"
-#endif
-
-#if defined(ARCH_S) || defined(ARCH_X200)
-#include "XUD_USBTile_Support.h"
-extern unsigned get_tile_id(tileref ref);
-extern tileref USB_TILE_REF;
-#endif
-
-
-void XUD_UIFM_PwrSigFlags();
-
-#define T_WTRSTFS_us 26 // 26us
-#ifndef T_WTRSTFS
-#define T_WTRSTFS (T_WTRSTFS_us * REF_CLK_FREQ)
-#endif
-#define STATE_START_TO_us 3000 // 3ms
-#define STATE_START_TO (STATE_START_TO_us * REF_CLK_FREQ)
-#define DELAY_6ms_us 6000
-#define DELAY_6ms (DELAY_6ms_us * REF_CLK_FREQ)
-#define T_FILTSE0 250
-
-#ifndef SUSPEND_VBUS_POLL_TIMER_TICKS
-#define SUSPEND_VBUS_POLL_TIMER_TICKS 500000
-#endif
-
-extern buffered in port:32 p_usb_clk;
-extern in port reg_read_port;
-extern in port flag0_port;
-extern in port flag1_port;
-extern in port flag2_port;
-extern out port p_usb_txd;
-#if defined(ARCH_S) || defined(ARCH_X200)
-extern in buffered port:32 p_usb_rxd;
-#define reg_read_port null
-#define reg_write_port null
-#else
-extern out port reg_write_port;
-extern port p_usb_rxd;
-#endif
-extern unsigned g_curSpeed;
-
-/* Reset USB transceiver for specified time */
-void XUD_PhyReset(out port p_rst, int time, unsigned rstMask)
-{
- unsigned x;
-
- x = peek(p_rst);
- x &= (~rstMask);
- p_rst <: x;
-
- XUD_Sup_Delay(time);
-
- x = peek(p_rst);
- x |= rstMask;
- p_rst <: x;
-}
-
-int XUD_Init()
-{
- timer SE0_timer;
- unsigned SE0_start_time = 0;
-
-#ifdef DO_TOKS
- /* Set default device address */
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_ADDRESS, 0x0);
-#endif
-
- /* Wait for host */
- while (1)
- {
- select
- {
- /* SE0 State */
- case flag2_port when pinseq(1) :> void:
- SE0_timer :> SE0_start_time;
- select
- {
- case flag2_port when pinseq(0) :> void:
- break;
-
- case SE0_timer when timerafter(SE0_start_time + T_WTRSTFS) :> int:
- return 1;
- break;
- }
- break;
-
- /* J State */
- case flag0_port when pinseq(0) :> void: // Inverted!
- SE0_timer :> SE0_start_time;
- select
- {
- case flag0_port when pinseq(1) :> void: // Inverted!
- break;
-
- case SE0_timer when timerafter(SE0_start_time + STATE_START_TO) :> int:
- return 0;
- break;
- }
- break;
- }
- }
- __builtin_trap();
- return -1;
-}
-
-/** XUD_DoSuspend
- * @brief Function called when device is suspended. This should include any clock down code etc.
- * @return True if reset detected during resume */
-int XUD_Suspend(XUD_PwrConfig pwrConfig)
-{
- unsigned tmp;
- timer t;
- unsigned time;
-
- /* Suspend can be handled in multiple ways:
- - Poll flags registers for resume/reset
- - Suspend phy and poll line status in test status reg for resume/reset
- - Power down zevious and use the suspend controller to wake zevious up
- */
-#if defined(ARCH_L) && defined(GLX_SUSPHY)
-#ifdef GLX_PWRDWN
- unsigned devAddr;
- unsigned before;
- /* Power suspend phy, power down zevious and used suspend controller to wake up */
-
- /* NOTE CURRENTLY XEV DOES NOT GET TURNED OFF, WE JUST ARE USING SUSPEND CONTROLLER TO
- * VERIFY FUNCTIONALITY */
-
- /* Wait for suspend J to make its way through filter */
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_CONTROL_REG, before);
-
- while(1)
- {
- unsigned x;
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_TESTSTATUS_REG, x);
- x >>= 9;
- x &= 0x3;
- if(x == 1)
- {
- break;
- }
- }
-
- /* Save device address to Glx scratch*/
- {
- char wData[] = {0};
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_DEVICE_ADDRESS_REG, devAddr);
- wData[0] = (char) devAddr;
-
- write_periph_reg_8(USB_TILE_REF, XS1_GLX_PERIPH_SCTH_ID, 0x0, 1, wData);
- }
-
- /* Suspend Phy etc
- * SEOFILTBASE sets a bit in a counter for anti-glitch (i.e 2 looks for change in 0b10)
- * This is a simple counter with check from wrap in this bit, so worst case could be x2 off
- * Counter runs at 32kHz by (31.25uS period). So setting 2 is about 63-125uS
- */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_CONTROL_REG,
- (1 << XS1_UIFM_PHY_CONTROL_AUTORESUME) |
- (0x2 << XS1_UIFM_PHY_CONTROL_SE0FILTVAL_BASE)
- | (1 << XS1_UIFM_PHY_CONTROL_FORCESUSPEND)
- );
-
- /* Mark scratch reg */
- {
- char x[] = {1};
- write_periph_reg_8(USB_TILE_REF, XS1_GLX_PERIPH_SCTH_ID, 0xff, 1, x);
- }
-
- /* Finally power down Xevious, keep sysclk running, keep USB enabled. */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_PWR_ID, XS1_GLX_PWR_MISC_CTRL_ADRS,
- (1 << XS1_GLX_PWR_SLEEP_INIT_BASE) /* Sleep */
- | (1 << XS1_GLX_PWR_SLEEP_CLK_SEL_BASE) /* Default clock */
- | (0x3 << XS1_GLX_PWR_USB_PD_EN_BASE ) ); /* Enable usb power up/down */
-
- /* Normally XCore will now be off and will reboot on resume/reset
- * However, all supplies enabled to test suspend controller so we'll poll resume reason reg.. */
-
- while(1)
- {
- unsigned wakeReason = 0;
-
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_CONTROL_REG, wakeReason);
-
- if(wakeReason & (1< int _;
- p_usb_clk when pinseq(0) :> int _;
- p_usb_clk when pinseq(1) :> int _;
- p_usb_clk when pinseq(0) :> int _;
-
- /* Func control reg will be default of 0x4 here term: 0 xcvSel: 0, opmode: 0b01 (non-driving) */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_FUNC_CONTROL_REG,
- (1< void;
-
- if(g_curSpeed == XUD_SPEED_HS)
- {
- /* Back to high-speed */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_FUNC_CONTROL_REG, 0);
- }
- return 0;
- }
- }
- else if(wakeReason & (1< int _;
- p_usb_clk when pinseq(0) :> int _;
- p_usb_clk when pinseq(1) :> int _;
- p_usb_clk when pinseq(0) :> int _;
-
- /* Set IFM to decoding linestate.. IFM regs reset when phy suspended */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_IFM_CONTROL_REG,
- (1< time;
- t when timerafter(time+250000) :> void;
- }
- return 1;
- }
-
-#else /* GLX_PWRDWN */
- unsigned rdata = 0;
-
- /* TODO Wait for suspend (j) to come through filter */
- while(1)
- {
- unsigned x;
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_TESTSTATUS_REG, x);
- x >>= 9;
- x &= 0x3;
- if(x == 1)
- {
- break;
- }
- }
-
- while(1)
- {
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_TESTSTATUS_REG, rdata);
- rdata >>= 9;
- rdata &= 0x3;
-
- if(rdata == 2)
- {
- /* Resume */
-
- /* Un-suspend phy */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_CONTROL_REG, 0);
-
- /* Wait for usb clock */
- set_thread_fast_mode_on();
- p_usb_clk when pinseq(1) :> int _;
- p_usb_clk when pinseq(0) :> int _;
- p_usb_clk when pinseq(1) :> int _;
- p_usb_clk when pinseq(0) :> int _;
- set_thread_fast_mode_off();
- if(g_curSpeed == XUD_SPEED_HS)
- {
- /* Back to high-speed */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_FUNC_CONTROL_REG, 0);
- }
-
- /* Wait for end of resume */
- while(1)
- {
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_TESTSTATUS_REG, rdata);
- rdata >>= 9;
- rdata &= 0x3;
-
- if(rdata == 0)
- {
- /* SE0 */
- return 0;
- }
- else if(rdata == 1)
- {
- /* Glitch */
- break;
- }
- }
- }
- else if(rdata == 0)
- {
-#if 0
- /* Reset */
- while(1)
- {
- int count = 0;
- read_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_TESTSTATUS_REG, rdata);
- rdata >>= 9;
- rdata &= 0x3;
-
- if(rdata != 0)
- {
- /* Se0 gone away...*/
- break;
- }
- else
- {
- count++;
- if(count>0)
- {
-#endif
- /* Un-suspend phy */
- write_periph_word(USB_TILE_REF, XS1_GLX_PERIPH_USB_ID, XS1_UIFM_PHY_CONTROL_REG, 0);
- return 1;
-#if 0
- }
- }
-#endif
- }
- }
- }
-#endif
-
-
-#elif defined ARCH_S || defined ARCH_X200 /* "Normal" polling suspend for L or S series */
- while (1)
- {
- t :> time;
-
- // linestate is K on flag0 (inverted), J on flag1, SE0 on flag2
- // note that if you look in device-attach function, high-speed chirps are opposite polarity
- // that is chirp K on flag1 and chirp J on flag0 (inverted)
- select
- {
- case (pwrConfig == XUD_PWR_SELF) => t when timerafter(time + SUSPEND_VBUS_POLL_TIMER_TICKS) :> void:
- read_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_OTG_FLAGS_NUM, tmp);
- if (!(tmp & (1 << XS1_SU_UIFM_OTG_FLAGS_SESSVLDB_SHIFT)))
- {
- // VBUS not valid
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 4 /* OpMode 01 */);
- return -1;
- }
- break;
-
- // SE0, that looks like a reset
- case flag2_port when pinseq(1) :> void:
- t :> time;
- select
- {
- case flag2_port when pinseq(0) :> void:
- // SE0 gone away, keep looping
- break;
-
- case t when timerafter(time + T_FILTSE0) :> void:
- // consider 2.5ms a complete reset
- t :> time;
- t when timerafter(time + 250000) :> void;
- return 1;
- }
- break;
-
- // K, start of resume
- case flag0_port when pinseq(0) :> void: // inverted port
- // TODO debounce?
- unsafe chanend c;
- asm("getr %0, 2" : "=r"(c)); // XS1_RES_TYPE_CHANEND=2 (no inline assembly immediate operands in xC)
-
- if (g_curSpeed == XUD_SPEED_HS)
- {
- // start high-speed switch so it's completed as quickly as possible after end of resume is seen
- unsafe {
- write_periph_word_two_part_start((chanend)c, USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 0);
- }
- }
-
- select
- {
- // J, unexpected, return
- case flag1_port when pinseq(1) :> void:
- // we have to complete the high-speed switch now
- // revert to full speed straight away - causes a blip on the bus
- // Note, switching to HS then back to FS is not ideal
- if (g_curSpeed == XUD_SPEED_HS)
- {
- unsafe {
- write_periph_word_two_part_end((chanend)c, 0);
- }
- }
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, (1 << XS1_SU_UIFM_FUNC_CONTROL_XCVRSELECT_SHIFT) | (1 << XS1_SU_UIFM_FUNC_CONTROL_TERMSELECT_SHIFT));
- break;
-
- // SE0, end of resume
- case flag2_port when pinseq(1) :> void:
- if (g_curSpeed == XUD_SPEED_HS)
- {
- // complete the high-speed switch
- unsafe {
- write_periph_word_two_part_end((chanend)c, 0);
- }
- }
- break;
- }
-
- asm("freer res[%0]" :: "r"(c));
- return 0;
- }
- }
- __builtin_trap();
- return -1;
-#endif
-}
-
-
diff --git a/lib_xud/src/core/XUD_SetCrcTableAddr.c b/lib_xud/src/core/XUD_SetCrcTableAddr.c
index a82c4f6b..55590abb 100644
--- a/lib_xud/src/core/XUD_SetCrcTableAddr.c
+++ b/lib_xud/src/core/XUD_SetCrcTableAddr.c
@@ -3,14 +3,12 @@
/** @file XUD_SetCrcTableAddr.c
* @author Ross Owen, XMOS Limited
*/
-
-#ifdef ARCH_G
+#include
/* Global table used to store complete valid CRC5 table */
-/* TODO Should be char */
extern unsigned char crc5Table[2048];
-/* Glocal table used to store valid CRCs for current address, all other address is this table are invalidated */
+/* Global table used to store valid CRCs for current address, all other address is this table are invalidated */
extern unsigned char crc5Table_Addr[2048];
/** XUD_SetCrcTableAddress
@@ -21,25 +19,15 @@ extern unsigned char crc5Table_Addr[2048];
*/
void XUD_SetCrcTableAddr(unsigned addr)
{
- int index, i, j;
+ unsigned index;
+
+ /* Set whole table to invalid CRC */
+ memset(crc5Table_Addr, 0xff, 2048);
- /* Addresses 0 - 0x7F */
- for (i = 0; i <= 0x7F; i++)
+ /* Copy over relevant entries */
+ for(unsigned ep = 0; ep <= 0xF; ep++)
{
- /* EPs 0 - 0xF */
- for(j = 0; j <= 0xF; j++)
- {
- index = i + (j<<7);
- if(i == addr)
- {
- crc5Table_Addr[index] = crc5Table[index];
- }
- else
- {
- /* Invalid CRC */
- crc5Table_Addr[index] = 0xff;
- }
- }
+ index = addr + (ep << 7);
+ crc5Table_Addr[index] = crc5Table[index];
}
}
-#endif
diff --git a/lib_xud/src/core/XUD_PowerSig.h b/lib_xud/src/core/XUD_Signalling.h
similarity index 100%
rename from lib_xud/src/core/XUD_PowerSig.h
rename to lib_xud/src/core/XUD_Signalling.h
diff --git a/lib_xud/src/core/XUD_Signalling.xc b/lib_xud/src/core/XUD_Signalling.xc
new file mode 100755
index 00000000..736922c2
--- /dev/null
+++ b/lib_xud/src/core/XUD_Signalling.xc
@@ -0,0 +1,276 @@
+// Copyright 2011-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include
+#include "xud.h"
+#include "XUD_Support.h"
+#include "XUD_USB_Defines.h"
+#include "XUD_HAL.h"
+
+#define T_WTRSTFS_us 26 // 26us
+#ifndef T_WTRSTFS
+#define T_WTRSTFS (T_WTRSTFS_us * REF_CLK_FREQ)
+#endif
+#define STATE_START_TO_us 3000 // 3ms
+#define STATE_START_TO (STATE_START_TO_us * REF_CLK_FREQ)
+#define DELAY_6ms_us 6000
+#define DELAY_6ms (DELAY_6ms_us * REF_CLK_FREQ)
+#define T_FILTSE0 250
+
+#ifndef SUSPEND_VBUS_POLL_TIMER_TICKS
+#define SUSPEND_VBUS_POLL_TIMER_TICKS 500000
+#endif
+
+extern buffered in port:32 p_usb_clk;
+extern in port reg_read_port;
+extern in port flag0_port;
+extern in port flag1_port;
+
+extern in port flag2_port;
+
+extern out port p_usb_txd;
+extern in buffered port:32 p_usb_rxd;
+
+extern unsigned g_curSpeed;
+
+int XUD_Init()
+{
+ /* Wait for host */
+ while (1)
+ {
+#ifdef __XS3A__
+ XUD_LineState_t currentLs = XUD_HAL_GetLineState();
+
+ switch (currentLs)
+ {
+
+ case XUD_LINESTATE_SE0:
+
+ unsigned timedOut = XUD_HAL_WaitForLineStateChange(currentLs, T_WTRSTFS);
+
+ /* If no change in LS then return 1 for reset */
+ if(timedOut)
+ return 1;
+
+ /* Otherwise SE0 went away.. keep looking */
+ break;
+
+ case XUD_LINESTATE_J:
+
+ unsigned timedOut = XUD_HAL_WaitForLineStateChange(currentLs, STATE_START_TO);
+
+ /* If no change in LS then return 0 for suspend */
+ if(timedOut)
+ return 0;
+
+ /* Otherwise J went away.. keep looking */
+ break;
+
+ default:
+ /* Shouldn't expect to get here, but ignore anyway */
+ break;
+ }
+
+#else
+ timer SE0_timer;
+ unsigned SE0_start_time = 0;
+
+ select
+ {
+ /* SE0 State */
+ case flag2_port when pinseq(1) :> void:
+ SE0_timer :> SE0_start_time;
+ select
+ {
+ case flag2_port when pinseq(0) :> void:
+ break;
+
+ case SE0_timer when timerafter(SE0_start_time + T_WTRSTFS) :> int:
+ return 1;
+ break;
+ }
+ break;
+
+ /* J State */
+ case flag0_port when pinseq(1) :> void:
+ SE0_timer :> SE0_start_time;
+ select
+ {
+ case flag0_port when pinseq(0) :> void:
+ break;
+
+ case SE0_timer when timerafter(SE0_start_time + STATE_START_TO) :> int:
+ return 0;
+ break;
+ }
+ break;
+ }
+#endif
+ }
+
+ __builtin_trap();
+ return -1;
+}
+
+
+#ifndef __XS3A__
+/** XUD_Suspend
+ * @brief Function called when device is suspended. This should include any clock down code etc.
+ * @return True if reset detected during resume */
+int XUD_Suspend(XUD_PwrConfig pwrConfig)
+{
+ timer t;
+ unsigned time;
+
+ while (1)
+ {
+ t :> time;
+
+ // linestate is K on flag0 (inverted), J on flag1, SE0 on flag2
+ // note that if you look in device-attach function, high-speed chirps are opposite polarity
+ // that is chirp K on flag1 and chirp J on flag0 (inverted)
+ select
+ {
+ case (pwrConfig == XUD_PWR_SELF) => t when timerafter(time + SUSPEND_VBUS_POLL_TIMER_TICKS) :> void:
+ if(!XUD_HAL_GetVBusState())
+ {
+ // VBUS not valid
+ write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 4 /* OpMode 01 */);
+ return -1;
+ }
+ break;
+
+ // SE0, that looks like a reset
+ case flag2_port when pinseq(1) :> void:
+ t :> time;
+ select
+ {
+ case flag2_port when pinseq(0) :> void:
+ // SE0 gone away, keep looping
+ break;
+
+ case t when timerafter(time + T_FILTSE0) :> void:
+ // consider 2.5ms a complete reset
+ t :> time;
+ t when timerafter(time + 250000) :> void;
+ return 1;
+ }
+ break;
+
+ // K, start of resume
+ case flag0_port when pinseq(1) :> void:
+ // TODO debounce?
+ unsafe chanend c;
+ asm("getr %0, 2" : "=r"(c)); // XS1_RES_TYPE_CHANEND=2 (no inline assembly immediate operands in xC)
+
+ if (g_curSpeed == XUD_SPEED_HS)
+ {
+ // start high-speed switch so it's completed as quickly as possible after end of resume is seen
+ unsafe {
+ write_periph_word_two_part_start((chanend)c, USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 0);
+ }
+ }
+
+ select
+ {
+ // J, unexpected, return
+ case flag1_port when pinseq(1) :> void:
+ // we have to complete the high-speed switch now
+ // revert to full speed straight away - causes a blip on the bus
+ // Note, switching to HS then back to FS is not ideal
+ if (g_curSpeed == XUD_SPEED_HS)
+ {
+ unsafe {
+ write_periph_word_two_part_end((chanend)c, 0);
+ }
+ }
+ write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, (1 << XS1_SU_UIFM_FUNC_CONTROL_XCVRSELECT_SHIFT) | (1 << XS1_SU_UIFM_FUNC_CONTROL_TERMSELECT_SHIFT));
+ break;
+
+ // SE0, end of resume
+ case flag2_port when pinseq(1) :> void:
+ if (g_curSpeed == XUD_SPEED_HS)
+ {
+ // complete the high-speed switch
+ unsafe {
+ write_periph_word_two_part_end((chanend)c, 0);
+ }
+ }
+ break;
+ }
+
+ asm("freer res[%0]" :: "r"(c));
+ return 0;
+ }
+ }
+ __builtin_trap();
+ return -1;
+}
+
+#else
+int XUD_Suspend(XUD_PwrConfig pwrConfig)
+{
+ timer t;
+ unsigned time;
+
+ XUD_LineState_t currentLs = XUD_LINESTATE_J;
+
+ while(1)
+ {
+ unsigned timedOut = XUD_HAL_WaitForLineStateChange(currentLs, 0);
+
+ switch(currentLs)
+ {
+ /* Reset signalliung */
+ case XUD_LINESTATE_SE0:
+
+ timedOut = XUD_HAL_WaitForLineStateChange(currentLs, T_FILTSE0);
+
+ if(timedOut)
+ {
+ /* Consider 2.5ms a complete reset */
+ t :> time;
+ t when timerafter(time + 250000) :> void;
+
+ /* Return 1 for reset */
+ return 1;
+
+ }
+
+ /* If didnt timeout then keep looping...*/
+ break;
+
+ /* K, start of resume */
+ case XUD_LINESTATE_K:
+
+ /* TODO debounce? */
+ XUD_HAL_WaitForLineStateChange(currentLs, 0);
+
+ switch(currentLs)
+ {
+ /* SE0, end of resume */
+ case XUD_LINESTATE_SE0:
+ if (g_curSpeed == XUD_SPEED_HS)
+ {
+ /* Move back into high-speed mode - Notes, writes to XS3A registers orders of magnitude faster than XS2A */
+ XUD_HAL_EnterMode_PeripheralHighSpeed();
+
+ /* Return 0 for resumed */
+ return 0;
+ }
+ break;
+
+ /* J, unexpected, return to suspend.. */
+ case XUD_LINESTATE_J:
+ default:
+ break;
+ }
+ break;
+
+ case XUD_LINESTATE_J:
+ default:
+ /* Do nothing */
+ break;
+ }
+ }
+}
+#endif
diff --git a/lib_xud/src/core/XUD_Support.xc b/lib_xud/src/core/XUD_Support.xc
index 8fc1d9f5..25c7bb2e 100755
--- a/lib_xud/src/core/XUD_Support.xc
+++ b/lib_xud/src/core/XUD_Support.xc
@@ -11,12 +11,3 @@ extern inline unsigned char XUD_Sup_testct(XUD_chan c);
extern inline void XUD_Sup_outuint(XUD_chan c, unsigned x);
extern inline void XUD_Sup_outct(XUD_chan c, unsigned char x);
-void XUD_Sup_Delay(unsigned delay)
-{
- timer t;
- unsigned time;
-
- t :> time;
- time += delay;
- t when timerafter(time) :> void;
-}
diff --git a/lib_xud/src/core/XUD_TestMode.S b/lib_xud/src/core/XUD_TestMode.S
new file mode 100644
index 00000000..f01b65fa
--- /dev/null
+++ b/lib_xud/src/core/XUD_TestMode.S
@@ -0,0 +1,76 @@
+// Copyright 2020-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#include
+#include "XUD_USB_Defines.h"
+
+.issue_mode dual
+
+.globl XUD_UsbTestSE0.nstackwords
+.linkset XUD_UsbTestSE0.nstackwords, 0
+.globl XUD_UsbTestSE0
+.text
+.cc_top XUD_UsbTestSE0.func, XUD_UsbTestSE0
+
+// NAK every IN token if the CRC is correct.
+
+XUD_UsbTestSE0:
+ DUALENTSP_lu6 0 // Note, don't really need DI here..
+ // TODO ideally don't load these from dp..
+ ldw r0, dp[p_usb_rxd] // Load RXD port
+ ldw r2, dp[p_usb_txd] // Load TXD port
+ ldw r3, dp[flag1_port] // Load RXA port
+
+XUD_UsbTestSE0_loop:
+#ifdef __XS2A__
+ ldw r1, dp[flag2_port] // Valid token port
+
+ inpw r11, res[r0], 8 // Read 8 bit PID
+ shr r11, r11, 24 // shift off junk
+
+ inpw r9, res[r0], 8 // Read EP Number (dont care)
+
+ in r9, res[r1]
+ bt r9, InvalidTestToken // If VALID_TOKEN high, ignore token
+
+ eq r10, r11, USB_PID_IN
+ bf r10, XUD_UsbTestSE0_loop
+#else
+ ldc r8, 16
+ inpw r11, res[r0], 8 // Read 3 byte token from data port | CRC[5] | EP[4] | ADDR[7] | PID[8] | junk
+ {setpsc res[r0], r8; shr r11, r11, 24}
+ // TODO ideally share this with XUD_CrcAddrCheck rather than a duplication here..
+ {in r10, res[r0]; sub r1, r8, 5} // ldc r1, 11
+ {shr r10, r10, 16; mkmsk r11, r1}
+ {and r11, r10, r11; shr r4, r10, r1} // r4: Received CRC
+
+ ldaw r8, dp[crc5Table_Addr]
+ ld8u r8, r8[r11] // Correct CRC
+
+ xor r4, r4, r8 // Check received CRC against expected CRC
+ bt r4, InvalidTestToken; // Note, EP number is ignored
+
+ ldc r4, USB_PIDn_IN
+ eq r11, r11, r4 // Check received PID
+ bf r11, XUD_UsbTestSE0_loop
+#endif
+
+ nop // If all is well respond with a NAK to any IN token..
+ nop
+ nop
+ nop
+ nop
+
+ ldc r11, USB_PIDn_NAK
+ outpw res[r2], r11, 8
+ syncr res[r2]
+ bu XUD_UsbTestSE0_loop
+
+InvalidTestToken:
+ in r11, res[r3]
+ bt r11, InvalidTestToken
+ setc res[r0], XS1_SETC_RUN_CLRBUF // Clear RXD port
+ bu XUD_UsbTestSE0_loop
+
+
+.cc_bottom XUD_UsbTestSE0.func
diff --git a/lib_xud/src/core/XUD_TestMode.h b/lib_xud/src/core/XUD_TestMode.h
index 03088bc8..465e054e 100644
--- a/lib_xud/src/core/XUD_TestMode.h
+++ b/lib_xud/src/core/XUD_TestMode.h
@@ -4,12 +4,9 @@
#define __XUD_TESTMODE_H__
#include
-#include
-#include "XUD_UIFM_Functions.h"
-#include "XUD_UIFM_Defines.h"
+#include "XUD_HAL.h"
#include "XUD_USB_Defines.h"
-#include "XUD_Support.h"
unsigned UsbTestModeHandler_asm();
unsigned XUD_UsbTestSE0();
diff --git a/lib_xud/src/core/XUD_TestMode.xc b/lib_xud/src/core/XUD_TestMode.xc
index 4c8348c2..9d4a79aa 100644
--- a/lib_xud/src/core/XUD_TestMode.xc
+++ b/lib_xud/src/core/XUD_TestMode.xc
@@ -1,49 +1,17 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#include
-#include
-#include "XUD_UIFM_Functions.h"
-#include "XUD_UIFM_Defines.h"
-#include "XUD_USB_Defines.h"
-#include "XUD_Support.h"
-#include "XUD_TestMode.h"
#include "xud.h"
+#include "XUD_TestMode.h"
-#ifdef ARCH_S
-#include "xs1_su_registers.h"
-#endif
-
-#ifdef ARCH_X200
-#include "xs2_su_registers.h"
-#endif
-
-#if defined(ARCH_S) || defined(ARCH_X200)
-#include "XUD_USBTile_Support.h"
-extern unsigned get_tile_id(tileref ref);
-extern tileref USB_TILE_REF;
-#endif
-
-extern in port flag0_port;
-extern in port flag1_port;
-extern in port flag2_port;
-#if defined(ARCH_S) || defined(ARCH_X200)
extern out buffered port:32 p_usb_txd;
-#define reg_write_port null
-#define reg_read_port null
-#else
-extern out port reg_write_port;
-extern in port reg_read_port;
-extern out port p_usb_txd;
-extern port p_usb_rxd;
-#endif
-#define TEST_PACKET_LEN 14
#define T_INTER_TEST_PACKET_us 2
#define T_INTER_TEST_PACKET (T_INTER_TEST_PACKET_us * REF_CLK_FREQ)
#ifndef XUD_TEST_MODE_SUPPORT_DISABLED
-unsigned int test_packet[TEST_PACKET_LEN] =
+unsigned int test_packet[] =
{
0x000000c3,
0x00000000,
@@ -61,84 +29,15 @@ unsigned int test_packet[TEST_PACKET_LEN] =
0xceb67efd
};
-
-
-int XUD_TestMode_TestJ ()
-{
-#if defined(ARCH_L) || defined(ARCH_X200)
-
-#else
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_PHYCON, 0x15);
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_CTRL, 0x4);
-#endif
-
- // TestMode remains in J state until exit action is taken (which
- // for a device is power cycle)
- while(1)
- {
- p_usb_txd <: 1;
- }
- return 0;
-};
-
-int XUD_TestMode_TestK ()
-{
-#if defined(ARCH_L) || defined(ARCH_X200)
-
-#else
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_PHYCON, 0x15);
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_CTRL, 0x4);
-#endif
-
- // TestMode remains in J state until exit action is taken (which
- // for a device is power cycle)
- while(1)
- {
- p_usb_txd <: 0;
- }
- return 0;
-};
-
-int XUD_TestMode_TestPacket ()
-{
- // Repetitively transmit specific test packet forever.
- // Timings must still meet minimum interpacket gap
- // Have to relate KJ pairings to data.
- unsigned i;
- timer test_packet_timer;
-
-#pragma unsafe arrays
- while (1)
- {
-#pragma loop unroll
- for (i=0; i < TEST_PACKET_LEN; i++ )
- {
- p_usb_txd <: test_packet[i];
- };
- sync(p_usb_txd);
- test_packet_timer :> i;
- test_packet_timer when timerafter (i + T_INTER_TEST_PACKET) :> int _;
- }
- return 0;
-}
-
// Runs in XUD thread with interrupt on entering testmode.
-int XUD_UsbTestModeHandler()
+int XUD_UsbTestModeHandler(unsigned cmd)
{
- unsigned cmd = UsbTestModeHandler_asm();
-
switch(cmd)
{
case USB_WINDEX_TEST_J:
- //Function Control Reg. Suspend: 1 Opmode 10
-#if defined(ARCH_X200)
- write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_GLX_PER_UIFM_FUNC_CONTROL_NUM, 0b1000);
-#elif defined(ARCH_S)
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 0b1000);
-#else
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_PHYCON, 0x11);
-#endif
-
+
+ XUD_HAL_EnterMode_PeripheralTestJTestK();
+
while(1)
{
p_usb_txd <: 0xffffffff;
@@ -146,15 +45,9 @@ int XUD_UsbTestModeHandler()
break;
case USB_WINDEX_TEST_K:
- //Function Control Reg. Suspend: 1 Opmode 10
-#if defined(ARCH_X200)
- write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_GLX_PER_UIFM_FUNC_CONTROL_NUM, 0b1000);
-#elif defined(ARCH_S)
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_FUNC_CONTROL_NUM, 0b1000);
-#else
- XUD_UIFM_RegWrite(reg_write_port, UIFM_REG_PHYCON, 0x11);
-#endif
-
+
+ XUD_HAL_EnterMode_PeripheralTestJTestK();
+
while(1)
{
p_usb_txd <: 0;
@@ -162,13 +55,36 @@ int XUD_UsbTestModeHandler()
break;
case USB_WINDEX_TEST_SE0_NAK:
- // NAK every IN packet if the CRC is correct.
- // Drop into asm to deal with.
+
+ XUD_HAL_EnterMode_PeripheralHighSpeed();
+
+ /* Drop into asm to deal with this mode */
XUD_UsbTestSE0();
break;
case USB_WINDEX_TEST_PACKET:
- XUD_TestMode_TestPacket();
+ {
+ XUD_HAL_EnterMode_PeripheralHighSpeed();
+
+ // Repetitively transmit specific test packet forever.
+ // Timings must still meet minimum interpacket gap
+ // Have to relate KJ pairings to data.
+ unsigned i;
+ timer test_packet_timer;
+
+#pragma unsafe arrays
+ while (1)
+ {
+#pragma loop unroll
+ for (i=0; i < sizeof(test_packet)/sizeof(test_packet[0]); i++)
+ {
+ p_usb_txd <: test_packet[i];
+ };
+ sync(p_usb_txd);
+ test_packet_timer :> i;
+ test_packet_timer when timerafter (i + T_INTER_TEST_PACKET) :> int _;
+ }
+ }
break;
default:
diff --git a/lib_xud/src/core/XUD_TimingDefines.h b/lib_xud/src/core/XUD_TimingDefines.h
index 9fe6a8d5..cf84b828 100755
--- a/lib_xud/src/core/XUD_TimingDefines.h
+++ b/lib_xud/src/core/XUD_TimingDefines.h
@@ -3,29 +3,33 @@
#ifndef _XUD_USB_DEFINES_H_
#define _XUD_USB_DEFINES_H_
+#ifndef REF_CLK_FREQ
+#define REF_CLK_FREQ (100)
+#endif
+
// Defines relating to USB/ULPI/UTMI/Phy specs
-#define REF_CLK_FREQ 100
-#define SUSPEND_TIMEOUT_us 3000
-#define SUSPEND_TIMEOUT (SUSPEND_TIMEOUT_us * REF_CLK_FREQ)
+#ifndef SUSPEND_TIMEOUT_us
+#define SUSPEND_TIMEOUT_us (3000)
+#endif
+#define SUSPEND_TIMEOUT_ticks (SUSPEND_TIMEOUT_us * REF_CLK_FREQ)
// Device attach timing defines
-#define T_SIGATT_ULPI_us 5000 // 5ms
-#define T_SIGATT_ULPI (T_SIGATT_ULPI_us * REF_CLK_FREQ)
-#define T_ATTDB_us 1000000 // 1000ms
-#define T_ATTDB (T_ATTDB_us * REF_CLK_FREQ)
-#define T_UCHEND_T_UCH_us 1000000 // 1000ms
+#define T_UCHEND_T_UCH_us (1000000) // 1000ms
#define T_UCHEND_T_UCH (T_UCHEND_T_UCH_us * REF_CLK_FREQ)
-#define T_UCHEND_T_UCH_ULPI_us 2000 // 2ms
-#define T_UCHEND_T_UCH_ULPI (T_UCHEND_T_UCH_us * REF_CLK_FREQ)
-#define T_FILT_us 3 // 2.5us
-#define T_FILT (T_FILT_us * REF_CLK_FREQ)
-#define SUSPEND_T_WTWRSTHS_us 200 // 200us Time beforechecking for J after asserting XcvrSelect and Termselect
-#define SUSPEND_T_WTWRSTHS (SUSPEND_T_WTWRSTHS_us * REF_CLK_FREQ)
+#ifndef T_FILT_us
+#define T_FILT_us (3) // 2.5us
+#endif
+#define T_FILT_ticks (T_FILT_us * REF_CLK_FREQ)
+
+#ifndef SUSPEND_T_WTWRSTHS_us
+#define SUSPEND_T_WTWRSTHS_us (200) // 200us Time beforechecking for J after asserting XcvrSelect and Termselect: T_WTRSTHS: 100-875us
+#endif
+#define SUSPEND_T_WTWRSTHS_ticks (SUSPEND_T_WTWRSTHS_us * REF_CLK_FREQ)
-#define OUT_TIMEOUT_us 500 // How long we wait for data after OUT token
-#define OUT_TIMEOUT (OUT_TIMEOUT_us * REF_CLK_FREQ)
-#define TX_HANDSHAKE_TIMEOUT_us 5 // How long we wait for handshake after sending tx data
-#define TX_HANDSHAKE_TIMEOUT (TX_HANDSHAKE_TIMEOUT_us * REF_CLK_FREQ)
+#define OUT_TIMEOUT_us (500) // How long we wait for data after OUT token
+#define OUT_TIMEOUT_ticks (OUT_TIMEOUT_us * REF_CLK_FREQ)
+#define TX_HANDSHAKE_TIMEOUT_us (5) // How long we wait for handshake after sending tx data
+#define TX_HANDSHAKE_TIMEOUT_ticks (TX_HANDSHAKE_TIMEOUT_us * REF_CLK_FREQ)
#endif
diff --git a/lib_xud/src/core/XUD_TokenJmp.S b/lib_xud/src/core/XUD_TokenJmp.S
index a788e519..19fb0507 100644
--- a/lib_xud/src/core/XUD_TokenJmp.S
+++ b/lib_xud/src/core/XUD_TokenJmp.S
@@ -1,28 +1,23 @@
// Copyright 2013-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifdef ARCH_L
+#ifndef __XS3A__
ldaw r10, dp[PidJumpTable] // TODO Could load from sp here
// We receive: | 0000 4-bit EP | 0000 4-bit PID |
inpw r11, res[RXD], 8 // Read 8 bit PID
shr r11, r11, 24 // Shift off junk
ldw r10, r10[r11] // Load relevant branch address
-
-.xtabranch Pid_Out, Pid_Sof, Pid_In, Pid_Setup, Pid_Sof_NoChan
bau r10
-#else // ARCH_G
- //ldaw r8, dp[crc5Table_Addr]
- ldaw r10, dp[PidJumpTable]
- //ldw r6, dp[crcmask]
- ldc r8, 16
+#else //__XS3A__
+ {ldw r10, sp[STACK_PIDJUMPTABLE]
+ ldc r8, 16}
inpw r11, res[RXD], 8 // Read 3 byte token from data port | CRC[5] | EP[4] | ADDR[7] | PID[8] | junk
- setpsc res[RXD], r8
- shr r11, r11, 24
+ {setpsc res[RXD], r8; shr r11, r11, 24}
ldw r11, r10[r11]
-.xtabranch Pid_Out, Pid_Sof, Pid_In, Pid_Setup
- bau r11
+ bau r11 // Branch to Pid_Out, Pid_Sof, Pid_In, Pid_Setup etc
+
#endif
diff --git a/lib_xud/src/core/XUD_UIFM_Defines.h b/lib_xud/src/core/XUD_UIFM_Defines.h
deleted file mode 100755
index 1891279f..00000000
--- a/lib_xud/src/core/XUD_UIFM_Defines.h
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/**
- * \brief Defines for interfacing UIFM (L-series and G-series only)
- * Author Ross Owen
- **/
-
-#if defined (ARCH_L) && !defined(ARCH_X200) & !defined(ARCH_S)
-
-#ifndef _XUD_UIFM_DEFINES_H_
-#define _XUD_UIFM_DEFINES_H_ 1
-
-#define UIFM_MODE 2 // ULPI
-
-#if 1
-/* Flags Register */
-#ifdef ARCH_L
-#define UIFM_REG_FLAGS 6
-#else
-#define UIFM_REG_FLAGS 5
-#endif
-
-#define UIFM_FLAGS_RXE 0x1
-#define UIFM_FLAGS_RXA 0x2
-#define UIFM_FLAGS_CRCFAIL 0x4
-//#define UIFM_FLAGS_FS_K 0x8
-//#define UIFM_FLAGS_FS_J 0x10
-#define XS1_UIFM_IFM_FLAGS_K_MASK 0x10 /* Fullspeed J/High-speed K */
-#define XS1_UIFM_IFM_FLAGS_J_MASK 0x08 /* Fullspeed K/High-speed J */
-#define XS1_UIFM_IFM_FLAGS_SE0_MASK 0x20
-#define UIFM_FLAGS_NEWTOK 0x40
-#define XS1_IFM_FLAGS_HOSTACK 0x80
-
-
-#ifdef ARCH_L
-/* L Series UIFM Defines */
-
-/* UIFM Ports */
-//#define UIFM_INT_CLK_PORT XS1_PORT_1I // Not required in software
-#define UIFM_USB_CLK_PORT XS1_PORT_1H
-
-#define UIFM_REG_WRITE_PORT XS1_PORT_8C
-#define UIFM_REG_READ_PORT XS1_PORT_8D
-#define UIFM_FLAG_0_PORT XS1_PORT_1N
-#define UIFM_FLAG_1_PORT XS1_PORT_1O
-#define UIFM_FLAG_2_PORT XS1_PORT_1P
-#define UIFM_TX_DATA_PORT XS1_PORT_8A
-#define UIFM_RX_DATA_PORT XS1_PORT_8B
-#define UIFM_STP_SUS_PORT XS1_PORT_1E
-#define UIFM_LS_PORT XS1_PORT_4D
-
-/* Basic UIFM Commands */
-#define UIFM_CMD_READ 0x00
-#define UIFM_CMD_WRITE 0x80
-#define UIFM_CMD_WRITEACK 0xc0
-
-/* UIFM Registers */
-
-/* Control Register */
-#define UIFM_REG_CTRL 0x01
-
-#define UIFM_CTRL_DEFAULT 0x00
-#define UIFM_CTRL_DOTOK 0x01
-#define UIFM_CTRL_CHKTOK 0x02
-#define UIFM_CTRL_DECODE_LS 0x04
-#define UIFM_CTRL_PKTBUF 0x08
-#define UIFM_CTRL_BUFFRDY 0x10
-
-
-/* Device Address Register */
-#define UIFM_REG_ADDRESS 0x02
-
-
-/* Phy Control Register */
-#define UIFM_REG_PHYCON 0x03 /* Function Ctl */
-
-#define UIFM_PHYCON_SUSPEND 0x01
-#define UIFM_PHYCON_XCVRSEL 0x02
-#define UIFM_PHYCON_TERMSEL 0x04
-
-
-#define UIFM_REG_ULPICON 4
-
-//#define UIFM_REG_SOF1 13
-//#define UIFM_REG_SOF2 14
-
-
-#define UIFM_REG_STATUS 7 /* NEW */
-#define UIFM_REG_STICKY 8
-
-#define UIFM_REG_FLAG_MASK0 9
-#define UIFM_REG_FLAG_MASK1 10
-#define UIFM_REG_FLAG_MASK2 11
-#define UIFM_REG_FLAG_MASK3 12 /* NEW */
-#define UIFM_REG_SOF0 13
-#define UIFM_REG_SOF1 14
-#define UIFM_REG_PID 15
-#define UIFM_REG_EP 16
-#define UIFM_REG_HANDSHAKE 17
-#define UIFM_REG_BUFFCTRL 18
-#define UIFM_REG_BUFFDATA 19
-
-/* Misc config reg */
-#define UIFM_REG_MISC 55
-#define UIFM_MISC_SOFISTOKEN 0b10000
-
-/* OTG Flags Reg */
-#define UIFM_OTG_FLAGS_REG 5
-#define UIFM_OTG_FLAGS_SESSEND_SHIFT 0
-#define UIFM_OTG_FLAGS_SESSVLD_SHIFT 1
-#define UIFM_OTG_FLAGS_VBUSVLD_SHIFT 2
-#define UIFM_OTG_FLAGS_HOSTDIS_SHIFT 3
-#define UIFM_OTG_FLAGS_NIDGND_SHIFT 4
-
-#define UIFM_IN_REG_OFFSET 36
-#define UIFM_OUT_REG_OFFSET 20
-
-#else
-
-
-
-#define UIFM_INT_CLK_PORT XS1_PORT_1I // Not required in software
-#define UIFM_USB_CLK_PORT XS1_PORT_1H
-
-
-// Basic UIFM Commands
-#define UIFM_CMD_READ 0x00
-#define UIFM_CMD_WRITE 0x80
-#define UIFM_CMD_WRITEACK 0xc0
-// //#define UIFM_CMD_WRITE_BUFFDATA 0x91
-// //#define UIFM_CMD_READ_BUFFDATA 0x11
-// //#define UIFM_CMD_READ_SBUFFDATA 0x34
-//
-// // UIFM Register Address'
- #define UIFM_REG_ADDRESS 2
- #define UIFM_REG_CTRL 1
- #define UIFM_REG_PHYCON 3
- #define UIFM_REG_ULPICON 4
- #define UIFM_REG_STICKY 7
- #define UIFM_REG_FLAG_MASK0 8
- #define UIFM_REG_FLAG_MASK1 9
- #define UIFM_REG_FLAG_MASK2 10
- #define UIFM_REG_SOF0 11
- #define UIFM_REG_SOF1 12
- #define UIFM_REG_PID 13
- #define UIFM_REG_EP 14
- #define UIFM_REG_HANDSHAKE 15
- #define UIFM_REG_BUFFCTRL 16
- #define UIFM_REG_BUFFDATA 17
-//
-// // Control Register defines
- #define UIFM_CTRL_DOTOK 0x1
- #define UIFM_CTRL_CHKTOK 0x2
- #define UIFM_CTRL_DECODE_LS 0x4
- #define UIFM_CTRL_PKTBUF 0x8
- #define UIFM_CTRL_BUFFRDY 0x10
-//
- #define UIFM_IN_REG_OFFSET 36
- #define UIFM_OUT_REG_OFFSET 20
-//
-
-#endif
-#endif
-
-#endif // _XUD_UIFM_DEFINES_H_
-#endif
diff --git a/lib_xud/src/core/XUD_UIFM_Functions.h b/lib_xud/src/core/XUD_UIFM_Functions.h
deleted file mode 100755
index ff14e315..00000000
--- a/lib_xud/src/core/XUD_UIFM_Functions.h
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-#ifndef UIFM_FUNCTIONS_H_
-#define UIFM_FUNCTIONS_H_ 1
-
-#include "XUD_Support.h"
-
-// Sets up the ports for use with UIFM
-void XUD_UIFM_PortConfig(buffered in port:32 clk_port, out port reg_write_port, in port reg_read_port, in port flag0_port, in port flag1_port, in port flag2_port, out port txd_port, in port rxd_port);
-
-// Enables UIFM in the passed mode
-unsigned XUD_UIFM_Enable(unsigned mode);
-
-// Write value to UIFM register
-void XUD_UIFM_RegWrite(out port reg_write_port, unsigned regNo, unsigned val);
-
-// Same as above but loads reg write port from DP
-void XUD_UIFM_RegWrite_( unsigned regNo, unsigned val);
-
-// Read value from specified UIFM register
-unsigned XUD_UIFM_RegRead(out port reg_write_port, in port reg_read_port, unsigned regNo);
-
-/*
-// Write value to UIFM register. Uses a lock for mutual exclusion
-void XUD_UIFM_RegWrite_Locked(out port reg_write_port, XUD_lock l_ifm, unsigned regNo, unsigned val);
-
-// Read value from specified UIFM register. Uses a lock for mutual exclusion
-unsigned XUD_UIFM_RegRead_Locked(out port reg_write_port, in port reg_read_port, XUD_lock l_ifm, unsigned regNo);
-*/
-
-// Write specified endpoint buffer to UIFM packet buffer
-void WriteEpBuffToPktBuff(out port reg_write_port, unsigned ep, unsigned datalength);
-
-// Read data from specified endpoint buffer.
-// Returns DATA PID for sequence checking
-// Does CRC checking... returns 0 if CRC16 bad
-unsigned ReadPktBuffToEpBuff(out port reg_write_port, in port reg_read_port, unsigned ep, unsigned datalength);
-
-unsigned ReadSetupBuffToEpBuff(out port reg_write_port, in port reg_read_port, unsigned ep);
-
-
-#endif
diff --git a/lib_xud/src/core/XUD_UIFM_PConfig.S b/lib_xud/src/core/XUD_UIFM_PConfig.S
deleted file mode 100755
index f13a688d..00000000
--- a/lib_xud/src/core/XUD_UIFM_PConfig.S
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-// XUD_UIFM_PConfig.S
-// Port configuration for UIFM
-// Ross Owen
-
-#include
-
-// From Autodefines...
-#define SETCTRL_LMODE_SHIFT 12
-#define SETCTRL_VALUE_SHIFT 3
-#define SETCTRL_LMODE_PIN_DELAY 7
-#define SETCTRL_LMODE_FALL_DELAY 8
-#define SETCTRL_LMODE_RISE_DELAY 9
-#define SETCTRL_MODE_LONG 7
-#define SETCTRL_MODE_SHIFT 0
-
-.text
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
-// XUD_UIFM_PortConfig(in port clk_port, out port reg_write_port, in port reg_read_port,
-// in port flag0_port,
-// in port flag1_port,
-// in port flag2_port,
-// out port txd_port, in port txd_port);
-//
-
-#define CLK r0
-#define REG_WRITE r1
-#define REG_READ r2
-#define FLAG0 r3
-
-.globl XUD_UIFM_PortConfig
-.type XUD_UIFM_PortConfig, @function
-
-.cc_top XUD_UIFM_PortConfig.function
-XUD_UIFM_PortConfig:
- entsp 16
- stw r10, sp[1]
- stw r9, sp[2]
- stw r8, sp[3]
- stw r7, sp[4]
-
-//EnableClockBuffers:
- //setc res[r0], XS1_SETC_BUF_BUFFERS // Set port to buffered strobed master
- //ldc r11, 32 // Set transfer width to 32 bits
- //settw res[r0], r11
-
-InvertUsbClock:
- setc res[r0], XS1_SETC_INV_INVERT
- setc res[r0], XS1_SETC_COND_NONE
-
-ConfigClockBlock:
- ldc r10, XS1_CLKBLK_REF // TODO Don't use clock block 0
- setc res[r10], XS1_SETC_INUSE_ON
- //setc res[r10], XS1_SETC_RUN_STOPR
- setclk res[r10], r0 // Clock clockblock from usb clock
-
-DelayFallingEdge: // Delay falling clock block pulse
- ldc r8, SETCTRL_LMODE_FALL_DELAY
- ldc r11, SETCTRL_LMODE_SHIFT
- shl r9, r8, r11
- ldc r11, SETCTRL_VALUE_SHIFT
- ldc r7, 1
- shl r8, r7, r11
- or r9, r9, r8
- ldc r8, SETCTRL_MODE_LONG
- ldc r11, SETCTRL_MODE_SHIFT
- shl r8, r8, r11
- or r9, r9, r8
- setc res[r10], r9
-
-DelayRisingEdge: // Delay rising clock block pulse
- ldc r8, SETCTRL_LMODE_RISE_DELAY
- ldc r11, SETCTRL_LMODE_SHIFT
- shl r9, r8, r11
- ldc r11, SETCTRL_VALUE_SHIFT
- ldc r7, 0
- shl r8, r7, r11
- or r9, r9, r8
- ldc r8, SETCTRL_MODE_LONG
- ldc r11, SETCTRL_MODE_SHIFT
- shl r8, r8, r11
- or r9, r9, r8
- setc res[r10], r9
-
-
-
-StartClockBlock:
- setc res[r10], XS1_SETC_RUN_STARTR
-
-ConfigRegWritePort: // UIFM reg write port
- setc res[REG_WRITE], XS1_SETC_SDELAY_SDELAY // Sample on falling edge of clock
- setclk res[REG_WRITE], r10 // Clock off USB clock-block
- ldc r11, 0 // Turn port around
- //out res[REG_WRITE], r11 // Caused intermittant issues on some boards (caused d+/d- spike on first reg-write on on occations
-
- setc res[REG_WRITE], XS1_SETC_BUF_BUFFERS // Set port to buffered strobed master
- setc res[REG_WRITE], XS1_SETC_RDY_STROBED
- setc res[REG_WRITE], XS1_SETC_MS_MASTER
- setc res[REG_WRITE], XS1_SETC_RUN_CLRBUF
-
-ConfigRegReadPort: // UIFM reg read port
- setc res[REG_READ], XS1_SETC_SDELAY_SDELAY
- setclk res[REG_READ], r10
-
- setc res[REG_READ], XS1_SETC_BUF_BUFFERS
- setc res[REG_READ], XS1_SETC_RDY_HANDSHAKE
- setc res[REG_READ], XS1_SETC_MS_MASTER
- setc res[REG_READ], XS1_SETC_RUN_CLRBUF
-
-ConfigFlagPort0: // Config UIFM flag port0
- setc res[FLAG0], XS1_SETC_SDELAY_SDELAY
- setclk res[FLAG0], r10
- setc res[FLAG0], XS1_SETC_RUN_CLRBUF
-
-ConfigFlagPort1: // Config UIFM flag port1
- ldw r11, sp[17] // Flag port1: 5th arg
- setc res[r11], XS1_SETC_SDELAY_SDELAY
- setclk res[r11], r10
- setc res[r11], XS1_SETC_RUN_CLRBUF
- setc res[r11], XS1_SETC_COND_EQ
-
-ConfigFlagPort2: // Config UIFM flag port2
- ldw r11, sp[18] // Flag port2: 6th arg
- setc res[r11], XS1_SETC_SDELAY_SDELAY
- setclk res[r11], r10
- setc res[r11], XS1_SETC_RUN_CLRBUF
- setc res[r11], XS1_SETC_COND_EQ
-
-ConfigureTxDataPort:
- ldw r11, sp[19]
- setc res[r11], XS1_SETC_SDELAY_SDELAY
- setclk res[r11], r10
-
- ldc r9, 0 // Turn port around
- out res[r11], r9
-
- setc res[r11], XS1_SETC_BUF_BUFFERS
- ldc r9, 32 // Set transfer width to 32 bits
- settw res[r11], r9
- setc res[r11], XS1_SETC_RDY_HANDSHAKE // Set port to handshaken master
- setc res[r11], XS1_SETC_MS_MASTER
-
- setc res[r11], XS1_SETC_RUN_CLRBUF
-
-ConfigureRxDataPort:
- ldw r11, sp[20]
- setc res[r11], XS1_SETC_SDELAY_SDELAY
-
- setc res[r11], XS1_SETC_BUF_BUFFERS
- ldc r9, 32
- settw res[r11], r9 // Set transfer width to 32 bits
- setc res[r11], XS1_SETC_RDY_HANDSHAKE
- setc res[r11], XS1_SETC_MS_MASTER
-
-
- setclk res[r11], r10
- setc res[r11], XS1_SETC_RUN_CLRBUF
-
- ldw r10, sp[1]
- ldw r9, sp[2]
- ldw r8, sp[3]
- ldw r7, sp[4]
- retsp 16
-.size XUD_UIFM_PortConfig,.-XUD_UIFM_PortConfig
-.cc_bottom XUD_UIFM_PortConfig.function
-.globl XUD_UIFM_PortConfig.nstackwords
-.globl XUD_UIFM_PortConfig.maxthreads
-.globl XUD_UIFM_PortConfig.maxtimers
-.globl XUD_UIFM_PortConfig.maxchanends
-.set XUD_UIFM_PortConfig.nstackwords, 16
-.set XUD_UIFM_PortConfig.maxchanends, 0
-.set XUD_UIFM_PortConfig.maxtimers, 0
-.set XUD_UIFM_PortConfig.maxthreads, 0
diff --git a/lib_xud/src/core/XUD_UIFM_RegAccess.S b/lib_xud/src/core/XUD_UIFM_RegAccess.S
deleted file mode 100644
index 729f5402..00000000
--- a/lib_xud/src/core/XUD_UIFM_RegAccess.S
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/** XUD_UIFM_RegAccess.S
- * @brief Functions for UIFM register read/write
- * @author Ross Owen, XMOS Limited
- */
-
-#include
-
-#include "XUD_UIFM_Defines.h"
-#include
-
-#ifndef GLX
-#ifndef XS1_PS_XCORE_CTRL0
-#define XS1_PS_XCORE_CTRL0 0x20b
-#endif
-
-.text
-.globl XUD_UIFM_Enable, "f{ui}(ui)"
-.type XUD_UIFM_Enable, @function
-.cc_top XUD_UIFM_Enable.function
-.align 4
-// void XUD_UIFM_Enable (unsigned mode);
-XUD_UIFM_Enable:
- ldc r1, XS1_PS_XCORE_CTRL0
- set ps[r1], r0
-
- // Sanity check, read back and check
- //get r1, ps[r1]
- //eq r1, r0, r1
- //ecallf r1
- retsp 0
-
-.size XUD_UIFM_Enable, .-XUD_UIFM_Enable
-.cc_bottom XUD_UIFM_Enable.function
-.globl XUD_UIFM_Enable.nstackwords
-.globl XUD_UIFM_Enable.maxchanends
-.globl XUD_UIFM_Enable.maxtimers
-.globl XUD_UIFM_Enable.maxcores
-.set XUD_UIFM_Enable.nstackwords, 0
-.set XUD_UIFM_Enable.maxchanends, 0
-.set XUD_UIFM_Enable.maxtimers, 0
-.set XUD_UIFM_Enable.maxcores, 1
-.set XUD_UIFM_Enable.locnochandec, 1
-
-#if !defined (ARCH_S) && !defined (ARCH_X200)
-
-/////////////////////////////////////////////////////////////////////////////////////////////
-// unsigned XUD_UIFM_RegRead(out port reg_write_port, in port reg_read_port, unsigned regNo);
-.globl XUD_UIFM_RegRead
-.type XUD_UIFM_RegRead, @function
-.text
-
-.cc_top XUD_UIFM_RegRead.function
-.align 4
-XUD_UIFM_RegRead:
-
- setc res[r1], XS1_SETC_RUN_CLRBUF
- ldc r11, UIFM_CMD_READ // make register ID
- or r3, r11, r2
-
- out res[r0], r3
- syncr res[r0];
- in r0, res[r1]
-
- retsp 0
-.size XUD_UIFM_RegRead, .-XUD_UIFM_RegRead
-.cc_bottom XUD_UIFM_RegRead.function
-.globl XUD_UIFM_RegRead.nstackwords
-.globl XUD_UIFM_RegRead.maxtimers
-.globl XUD_UIFM_RegRead.maxchanends
-.globl XUD_UIFM_RegRead.maxcores
-.set XUD_UIFM_RegRead.nstackwords, 0
-.set XUD_UIFM_RegRead.maxtimers, 0
-.set XUD_UIFM_RegRead.maxchanends, 0
-.set XUD_UIFM_RegRead.maxcores, 1
-
-
-////////////////////////////////////////////////////////////////////////////////////////
-// void UifmWriteRead(out port reg_write_port, unsigned regNo, unsigned val);
-.globl XUD_UIFM_RegWrite
-.type XUD_UIFM_RegWrite, @function
-
-.text
-
-.cc_top XUD_UIFM_RegWrite.function
-.align 4
-XUD_UIFM_RegWrite:
- ldc r11, UIFM_CMD_WRITE
- or r3, r11, r1
-
- out res[r0], r3
- syncr res[r0];
- out res[r0], r2
- syncr res[r0];
-
- retsp 0
-.size XUD_UIFM_RegWrite, .-XUD_UIFM_RegWrite
-.cc_bottom XUD_UIFM_RegWrite.function
-.globl XUD_UIFM_RegWrite.nstackwords
-.globl XUD_UIFM_RegWrite.maxtimers
-.globl XUD_UIFM_RegWrite.maxchanends
-.globl XUD_UIFM_RegWrite.maxcores
-.set XUD_UIFM_RegWrite.nstackwords, 0
-.set XUD_UIFM_RegWrite.maxtimers, 0
-.set XUD_UIFM_RegWrite.maxchanends, 0
-.set XUD_UIFM_RegWrite.maxcores, 1
-
-// void XUD_UIFM_RegWrite_(unsigned regNo, unsigned val);
-.globl XUD_UIFM_RegWrite_
-.type XUD_UIFM_RegWrite_, @function
-
-.text
-
-.cc_top XUD_UIFM_RegWrite_.function
-.align 4
-XUD_UIFM_RegWrite_:
- ldc r11, UIFM_CMD_WRITE
- or r3, r11, r0
- ldw r2, dp[reg_write_port]
-
- out res[r2], r3
- syncr res[r2];
- out res[r2], r1
- syncr res[r2];
-
- retsp 0
-.size XUD_UIFM_RegWrite_, .-XUD_UIFM_RegWrite_
-.cc_bottom XUD_UIFM_RegWrite_.function
-.globl XUD_UIFM_RegWrite_.nstackwords
-.globl XUD_UIFM_RegWrite_.maxtimers
-.globl XUD_UIFM_RegWrite_.maxchanends
-.globl XUD_UIFM_RegWrite_.maxcores
-.set XUD_UIFM_RegWrite_.nstackwords, 0
-.set XUD_UIFM_RegWrite_.maxtimers, 0
-.set XUD_UIFM_RegWrite_.maxchanends, 0
-.set XUD_UIFM_RegWrite_.maxcores, 1
-
-
-#endif
-#endif
diff --git a/lib_xud/src/core/XUD_USBTile_Support.S b/lib_xud/src/core/XUD_USBTile_Support.S
index 12ad0dce..8a762dbb 100644
--- a/lib_xud/src/core/XUD_USBTile_Support.S
+++ b/lib_xud/src/core/XUD_USBTile_Support.S
@@ -5,23 +5,33 @@
* @author Ross Owen, XMOS Limited
*/
+#ifdef __XS2A__
#include
+#endif
+#ifdef __XS3A__
+#include
+#endif
+#include
.text
.globl XUD_EnableUsbPortMux, "f{ui}()"
.type XUD_EnableUsbPortMux, @function
.cc_top XUD_EnableUsbPortMux.function
-.align 4
+.align FUNCTION_ALIGNMENT
// void XUD_EnableUsbPortMux (unsigned mode);
XUD_EnableUsbPortMux:
+.issue_mode single
+ ENTSP_lu6 0
ldc r1, XS1_PS_XCORE_CTRL0
- ldc r0, 2
+ get r0, ps[r1]
+ ldc r2, 2
+ or r0, r0, r2
set ps[r1], r0
//Sanity check, read back and check
- //get r1, ps[r1]
- //eq r1, r0, r1
- //ecallf r1
+ //get r1, ps[r1]
+ //eq r1, r0, r1
+ //ecallf r1
retsp 0
.size XUD_EnableUsbPortMux, .-XUD_EnableUsbPortMux
@@ -39,7 +49,7 @@ XUD_EnableUsbPortMux:
.globl XUD_DisableUsbPortMux, "f{ui}()"
.type XUD_DisableUsbPortMux, @function
.cc_top XUD_DisableUsbPortMux.function
-.align 4
+.align FUNCTION_ALIGNMENT
// void XUD_DisableUsbPortMux (unsigned mode);
XUD_DisableUsbPortMux:
ldc r1, XS1_PS_XCORE_CTRL0
@@ -47,9 +57,9 @@ XUD_DisableUsbPortMux:
set ps[r1], r0
//Sanity check, read back and check
- //get r1, ps[r1]
- //eq r1, r0, r1
- //ecallf r1
+ //get r1, ps[r1]
+ //eq r1, r0, r1
+ //ecallf r1
retsp 0
.size XUD_DisableUsbPortMux, .-XUD_DisableUsbPortMux
diff --git a/lib_xud/src/core/included/XUD_PidJumpTable.S b/lib_xud/src/core/included/XUD_PidJumpTable.S
index e9224c2f..76ee96b2 100755
--- a/lib_xud/src/core/included/XUD_PidJumpTable.S
+++ b/lib_xud/src/core/included/XUD_PidJumpTable.S
@@ -1,6 +1,6 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifdef ARCH_L
+#if defined (__XS2A__)
// PID jump table
.section .dp.data, "adw", @progbits
@@ -283,7 +283,7 @@ PidJumpTable:
#endif
-#ifdef ARCH_G
+#if defined(__XS3A__)
// Generated using genpidtable.c
.section .dp.data, "adw", @progbits
.globl PidJumpTable
diff --git a/lib_xud/src/core/included/XUD_RxData.S b/lib_xud/src/core/included/XUD_RxData.S
new file mode 100644
index 00000000..dde77ddf
--- /dev/null
+++ b/lib_xud/src/core/included/XUD_RxData.S
@@ -0,0 +1,104 @@
+// Copyright 2019-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+
+#define PASTER(x,y) x ## _ ## y
+#define EVALUATOR(x,y) PASTER(x,y)
+//#define LABEL(fun) EVALUATOR(fun, LABELNO)
+#define LABEL(fun) fun
+
+// r0: RXD: Rx Data port
+// r1: Buffer
+// r2: Tx Port
+// r3: Ep structure
+// r4: zero
+// r5: buffer address
+// r5: ep structures array
+// r6: crc rx init
+// r7: crc tx init
+// r9: crc poly
+// r8:
+// r10: ep number
+// r11: scratch
+
+doRXData_badPid:
+ ldc r8, 16 // Note, this is a cut-down version of XUD_TokenJump.S
+ ldaw r10, dp[PidJumpTable]
+ ldw r11, r10[r7]
+ {bau r11; setpsc res[RXD], r8}
+
+LABEL(doRXData):
+
+ inpw r8, res[r0], 8 // Input PID
+
+ // If pid != DATAx then jump and handle as a token. DATA0, DATA1, DATA2 & MDATA all of the form 0bxx11.
+ // This is a fast alternative to a "timeout"
+ {shr r7, r8, 24; mkmsk r11, 2}
+ and r11, r11, r7
+ eq r11, r11, 3
+ bf r11, doRXData_badPid
+ {setsr 1; ldw r7, sp[STACK_RXA_PORT]} // Load RxA Port ID
+
+LABEL(GotRxPid):
+ eeu res[r7] // Enable events on RxA
+
+LABEL(NextRxWord):
+ in r11, res[r0]
+ stw r11, r1[r4]
+ crc32_inc r6, r11, r9, r4, 1
+ in r11, res[r0]
+ stw r11, r1[r4]
+ crc32_inc r6, r11, r9, r4, 1
+ in r11, res[r0]
+ stw r11, r1[r4]
+ crc32_inc r6, r11, r9, r4, 1
+ in r11, res[r0]
+ stw r11, r1[r4]
+ crc32_inc r6, r11, r9, r4, 1
+ bu LABEL(NextRxWord)
+
+/////////////////////////////////////////////////////////////////////////////
+.align 32
+.skip 20
+RxALow:
+ {stw r8, r3[6]; in r7, res[r7]} // Store (NON-SHIFTED) PID into EP structure,
+ // Clear event data on RXA
+ endin r8, res[r0]
+LABEL(RxTail):
+ {in r11, res[r0]; bru r8}
+
+// Word aligned data (0 byte tail)
+.align 32
+OutTail0:
+ crc32 r6, r8, r9 // CRC zero step
+ ldw r11, sp[STACK_RXCRC_TAIL0]
+ RETSP_u6 0
+
+// 1 Tail Byte
+.align 32
+OutTail1:
+ shr r11, r11, 24 // Shift off junk
+ crc32 r6, r11, r9
+ stw r11, r1[r4] // Store last data
+ LDWSP_ru6 r11, sp[STACK_RXCRC_TAIL1]
+ RETSP_u6 0
+
+// Two Tail Bytes
+.align 32
+OutTail2:
+ shr r11, r11, 16
+ crc32 r6, r11, r9
+ stw r11, r1[r4] // Store last data
+ ldw r11, sp[STACK_RXCRC_TAIL2]
+ RETSP_u6 0
+
+// Three Tail Bytes
+.align 32
+OutTail3:
+ shr r11, r11, 8
+ stw r11, r1[r4] // Store last data
+ crc32 r6, r11, r9
+ LDWSP_ru6 r11, sp[STACK_RXCRC_TAIL3]
+ crc8 r6, r1, r2, r9 // Use the fact the the bottom byte of port id is 0.. saves us an ldc
+ RETSP_u6 0
+
diff --git a/lib_xud/src/core/included/XUD_Token_In.S b/lib_xud/src/core/included/XUD_Token_In.S
deleted file mode 100755
index ef6f981e..00000000
--- a/lib_xud/src/core/included/XUD_Token_In.S
+++ /dev/null
@@ -1,367 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#include
-
-// Ports
-#define RXD r0
-#define RXA r1
-#define TXD r2
-
-//.text
-// On entry:
-// R11: Branch address (now free)
-// R10: EP number (used here)
-// R9 : CRC16 Poly (used here)
-// R8 :
-// R7 :
-// R6 : ep_pid_sequence_table_IN_A
-// R5 : Channel Array
-// R4 :
-// R3 : 0
-// R2 : TXD
-// R1 : Valid Token Port
-// R0 : RXD
-.align 4
-InNotReady:
- ldw r11, sp[SP_EPTYPES_OUT]
- ldw r11, r11[r10] // Load EP Type
- bt r11, XUD_IN_TxNak
- ldc r11, 0xc3 // Create 0-length packet
- outpw res[TXD], r11, 24
-
-#include "XUD_TokenJmp.S"
-
-XUD_IN_TxNak: // Non-Iso
- ldaw r11, dp[handshakeTable_IN] // Load handshake table
- ldw r11, r11[r10] // Load handshake PID
- outpw res[TXD], r11, 8
-
-#include "XUD_TokenJmp.S"
-
-
-
-.align 128
-#ifdef ARCH_L
-.skip 92
-//.skip 98
-#else
-.skip 78
-#endif
-Pid_In:
-#ifdef ARCH_L
- inpw r10, res[RXD], 8; // Read EP Number
- shr r10, r10, 24; // Shift off junk
-
- in r11, res[r1];
- bt r11, InvalidToken; // If VALID_TOKEN not high, ignore token - PORT INVERTED! */
-#else
- #include "XUD_G_Crc.S"
-#endif
- //add r3, r4, r10 // IN channel offset (R10: EP number, E4: Num out Eps)
- ldaw r3, r10[4] // R3 = R10 + 16
- ldw r4, r5[r3] // Load EP structure address
- bf r4, InNotReady // If 0 then not ready...
-
-In_LoadPid:
- ldw r11, r4[4] // Load PID from structure
-
-InReady:
- ldw r8, r4[3] // Load buffer
-
- ldw r6, r4[7] // Load tail length (bytes)
-
- ldw r4, r4[6] // Load buffer index
- bf r4, SmallTxPacket // Check for Short packet
-
-.xtabranch TxTail0, TxTail1, TxTail2, TxTail3
- bru r6 // Branch on tail length
-
-//--------------------------------------------------------------------------
-.align 64
-.skip 0
-TxTail0:
- ldw r6, r8[r4] // Load first data word
- add r4, r4, 1 // Buffer index increment
-XUD_IN_TxPid_Tail0:
- outpw res[TXD], r11, 8 // Output PID to port
- out res[TXD], r6 // Output first data word
- crc32 r7, r6, r9 // Run CRC
- bf r4, TxLoop0End
-TxLoop0:
- ldw r6, r8[r4] // Load last data word
- add r4, r4, 1
-TxLoop0_Out:
- out res[TXD], r6 // Output last data word
- crc32 r7, r6, r9
- bt r4, TxLoop0
-TxLoop0End: // Word aligned data (just output CRC)
- crc32 r7, r4, r9 // R4: 0 (from bt)
- not r7, r7
-
-XUD_IN_TxCrc_Tail0:
- outpw res[TXD], r7, 16 // Output CRC
- bu DoneTail
-
-.align 64
-.skip 0
-TxTail1:
- ldw r6, r8[r4] // Load first data word
- add r4, r4, 1 // Buffer index increment
-XUD_IN_TxPid_Tail1:
- outpw res[TXD], r11, 8 // Out PID
- out res[TXD], r6
- crc32 r7, r6, r9
- bf r4, TxLoop1End
-TxLoop1:
- ldw r6, r8[r4] // Load last data word
- add r4, r4, 1
- out res[TXD], r6
- crc32 r7, r6, r9
- bt r4, TxLoop1
-TxLoop1End:
- ldw r6, r8[r4] // Load last data word
- outpw res[TXD], r6, 8
- crc8 r7, r6, r6, r9
- crc32 r7, r4, r9 // r4: 0 (from bf)
- not r7, r7
-
-XUD_IN_TxCrc_Tail1:
- outpw res[TXD], r7, 16
- bu DoneTail
-
-.scheduling off
-.align 64
-.skip 0
-TxTail2:
- ldw r6, r8[r4] // Load first data word
- crc32 r7, r6, r9
-XUD_IN_TxPid_Tail2:
- outpw res[TXD], r11, 8 // Out PID
- out res[TXD], r6
- add r4, r4, 1
- bf r4, TxLoop2End
-TxLoop2:
- ldw r6, r8[r4] // Load first data word
- add r4, r4, 1
- crc32 r7, r6, r9
- out res[TXD], r6
- bt r4, TxLoop2
-
-TxLoop2End:
- ldw r6, r8[r4] // Load tail
- crc8 r7, r11, r6, r9
- outpw res[TXD], r6, 16
- crc8 r7, r11, r11, r9
- crc32 r7, r4, r9 // r4: 0 (from bf)
- not r7, r7
-
-XUD_IN_TxCrc_Tail2:
- outpw res[TXD], r7, 16
- bu DoneTail
-
-.align 64
-.skip 0
-TxTail3:
- ldw r6, r8[r4] // Load first data word
- add r4, r4, 1
-XUD_IN_TxPid_Tail3:
- outpw res[TXD], r11, 8 // Out PID
- out res[TXD], r6
- crc32 r7, r6, r9
- bf r4, TxLoop3End
-TxLoop3:
- ldw r6, r8[r4] // Load first data word
- add r4, r4, 1
- crc32 r7, r6, r9
- out res[TXD], r6
- bt r4, TxLoop3
-TxLoop3End:
- ldw r6, r8[r4] // Load tail
- crc8 r7, r11, r6, r9
- outpw res[TXD], r6, 24
- crc8 r7, r11, r11, r9
- crc8 r7, r11, r11, r9
- crc32 r7, r4, r9 // r4: 0 (from bf)
- not r7, r7
-XUD_IN_TxCrc_Tail3:
- outpw res[TXD], r7, 16
-
-.scheduling default
-// Wait for handshake... or timeout
-DoneTail:
- ldw r11, sp[SP_EPTYPES_OUT]
- ldw r11, r11[r10] // Load EP Type
- bt r11, SetupReceiveHandShake
-
-InISO:
- ldc r9, 0 //TODO
- bu DoneTx
-
-InNonISO:
-SetupReceiveHandShake:
- ldc r11, 8
- setpsc res[RXD], r11 // Set port shift count (expect 8 bit handshake)
- //ldap r11, TxHandShakeReceived
- //setv res[RXD], r11
- eeu res[RXD] // Events on RXD always enabled - Can;t be any more due to using events on channels
-
-SetupTimeout: // Timeout done using another port off same clock block we dont happen to already be using events on. Cunning.
- ldw r1, sp[STACK_FLAG0_PORT] // Load saved ValidToken port. Event vector already set.
- in r11, res[r1] // Do input and get port time/timestamps
- getts r11, res[r1]
- ldw r9, dp[g_txHandshakeTimeout]
- add r11, r11, r9
- setpt res[r1], r11 // Set port time and enable events
- eeu res[r1]
-
-WaitForHandshake: // Wait for timeout or handshake
- .xtabranch TxHandshakeTimeOut, TxHandShakeReceived
- waiteu
-
-
-// We sent some data but the host didn't handshake in time. Needs a re-send.
-.align 4
-TxHandshakeTimeOut:
- in r11, res[r1] // This will clear port time
- edu res[r1]
- edu res[RXD]
- bu BadHandShake
-
- //ldc r11, 1
- //out res[r5], r11
- //bu NextToken
-
-// Transmitted data, and got something back within the timeout. Check for valid handshake...
-.align 4
-TxHandShakeReceived:
-XUD_IN_RxAck:
- in r11, res[RXD] // Input data from RXD port
- clrpt res[r1] // Clear port time on valid token port
- edu res[RXD]
- shr r11, r11, 24 // Shift off junk data to leave ACK
-#ifdef ARCH_L
- ldc r9, USB_PID_ACK // Check for good ACK (L series strips of negated bits from PID)
-#else
- ldc r9, USB_PIDn_ACK
-#endif
- xor r9, r11, r9
- edu res[r1] // Disable events on ValidToken port
- bt r9, BadHandShake // Invalid handshake received from host. we need to resend...
-
-DoneTx:
- //ldap r11, NextRxWord // Restore RXD event vector
- //setv res[RXD], r11
-
-ClearInEpReady: // TODO Tidy this up
- //ldw r4, sp[(STACK_EXTEND+8)] / Load num out EPs
- //add r11, r4, r10 // IN channel offset (R10: EP number)
-
- ldw r10, r5[r3] // Load the EP struct
- stw r9, r5[r3] // Clear the ready
- ldw r11, r10[1] // Load channel
- out res[r11], r11 // Output word to signal packet sent okay
-
- bu NextToken
-
-BadHandShake: // Received a bad (or no)handshake
- //ldap r11, NextRxWord // Restore RXD event vector
- //setv res[RXD], r11
- bu NextToken
-
-.align 32
-.skip 28
-SmallTxPacket:
- ldw r8, r8[r4] // Load first data word
-// inct r8, res[r5] // Input tail length + 10
- //inct r6, res[r5] // get end of packet token
- //sub r8, r8, 10
- //in r6, res[r5] // Input tail data
- //shl r8, r8, 4 // Tail length bytes to bits *2
-
-// shr r8, r8, 1
-
- .xtabranch TxTail0s, TxTail1s, TxTail2s, TxTail3s
- bru r6 // branch taillength
-
-//--------------------------------------------------------------------------
-.align 64
-.skip 0
-TxTail0s: // We know this is a < 4 byte packet, so is 0 length packet
- // So crc = 0. Note our normal crc calculation works for this, it is
- //not a special CRC case, but helps with timing.
- ldc r8, 0
-XUD_IN_TxPid_TailS0:
- outpw res[TXD], r11, 8 // PID
- //crc32 r7, r11, r9 // r11: 0
- //not r7, r7
-
-XUD_IN_TxCrc_TailS0:
- outpw res[TXD], r8, 16 // r5: 0
- bu DoneTail
-
-.align 64
-.skip 0
-TxTail1s:
- ldc r6, 0
- // One tail byte
- shl r8, r8, 8 // Concat PID and Data
- or r11, r11, r8
- shr r8, r8, 8
- crc8 r7, r4, r8, r9
- crc32 r7, r6, r9 // r5: 0
- not r7, r7
-
-XUD_IN_TxPid_TailS1:
- outpw res[TXD], r11, 16 // PID
- ///outpw res[TXD], r6, 16
-XUD_IN_TxCrc_TailS1:
- outpw res[TXD], r7, 16
- bu DoneTail
-
-.align 64
-.skip 0
-TxTail2s:
- ldc r6, 0
- // Two tail byte
- shl r8, r8, 8
- or r11, r11, r8
- shr r8, r8, 8
- //outpw res[TXD], r11, 8 // PID
- //outpw res[TXD], r6, 16
-
- crc8 r7, r8, r8, r9
- crc8 r7, r8, r8, r9
- crc32 r7, r6, r9 // r5: 0
- not r7, r7
- shr r6, r7, 8
-
- shl r7, r7, 24
- zext r11, 24
- or r11, r11, r7
-XUD_IN_TxPid_TailS2:
- out res[TXD], r11
-// outpw res[TXD], r7, 16
-
-XUD_IN_TxCrc_TailS2:
- outpw res[TXD], r6, 8
- bu DoneTail
-
-.align 64
-.skip 0
-TxTail3s:
- ldc r6, 0
- // Two tail byte
-XUD_IN_TxPid_TailS3:
- outpw res[TXD], r11, 8 // PID
- outpw res[TXD], r8, 24
- crc8 r7, r8, r8, r9
- crc8 r7, r8, r8, r9
- crc8 r7, r8, r8, r9
-
- crc32 r7, r6, r9 // r5: 0
- not r7, r7
-
-XUD_IN_TxCrc_TailS3:
- outpw res[TXD], r7, 16
- bu DoneTail
-
diff --git a/lib_xud/src/core/included/XUD_Token_In_DI.S b/lib_xud/src/core/included/XUD_Token_In_DI.S
new file mode 100755
index 00000000..846ceda6
--- /dev/null
+++ b/lib_xud/src/core/included/XUD_Token_In_DI.S
@@ -0,0 +1,223 @@
+// Copyright 2011-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include
+#include "XUD_AlignmentDefines.h"
+
+// Ports
+#define RXD r0
+#define RXA r1
+#define TXD r2
+
+// On entry:
+// R11: Branch address (now free)
+// R10: EP number (used here)
+// R9 : CRC16 Poly (used here)
+// R8 :
+// R7 :
+// R6 : ep_pid_sequence_table_IN_A
+// R5 : Channel Array
+// R4 :
+// R3 : 0
+// R2 : TXD
+// R1 : Valid Token Port (XS2 only)
+// R0 : RXD
+.align FUNCTION_ALIGNMENT
+XUD_IN_NotReady:
+ ldw r11, sp[STACK_EPTYPES_IN]
+ ldw r11, r11[r10] // Load EP Type
+ bt r11, XUD_IN_TxNak
+ ldc r11, 0xc3 // Create 0-length packet
+ outpw res[TXD], r11, 24
+ #include "XUD_TokenJmp.S"
+
+XUD_IN_TxNak: // Non-Iso
+ ldaw r11, dp[handshakeTable_IN] // Load handshake table
+ ldw r11, r11[r10] // Load handshake PID
+ outpw res[TXD], r11, 8
+ #include "XUD_TokenJmp.S"
+
+.align FUNCTION_ALIGNMENT
+Pid_In:
+ #include "XUD_CrcAddrCheck.S"
+ ldaw r3, r10[4] // R3 = R10 + 16
+ ldw r4, r5[r3] // Load EP structure address
+ bf r4, XUD_IN_NotReady
+
+ ldaw r1, dp[g_stallTable_IN]
+ ldw r11, r1[r10]
+ bt r11, XUD_IN_NotReady // Note, user could potentially stall an ISO EP.
+
+ ldw r11, r4[4] // Load PID from structure
+
+XUD_IN_Ready:
+ ldw r8, r4[3] // Load buffer
+ ldw r6, r4[7] // Load tail length (bytes)
+ ldw r4, r4[6] // Load data length (words)
+ bf r4, XUD_IN_SmallTxPacket // Check for Short packet
+
+XUD_IN_Tx:
+ outpw res[TXD], r11, 8 // Out PID
+ ldw r11, r8[r4] // Load first data word
+
+XUD_IN_TxPid:
+ out res[TXD], r11
+ crc32_inc r7, r11, r9, r4, 1
+ bf r4, XUD_IN_TxLoopEnd
+
+XUD_IN_TxLoop:
+ ldw r11, r8[r4] // Load first data word
+ crc32_inc r7, r11, r9, r4, 1
+ {out res[TXD], r11; bt r4, XUD_IN_TxLoop}
+
+XUD_IN_TxLoopEnd:
+ ldw r11, r8[r4] // Load tail
+ crcn r7, r11, r9, r6
+
+XUD_IN_TxLoopEnd_CrcCalc:
+ crc32 r7, r4, r9 // r4: 0 (from bf)
+ outpw res[TXD], r11, r6
+ not r7, r7
+XUD_IN_TxCrc:
+ outpw res[TXD], r7, 16 // Output 16-bit CRC
+
+.scheduling default
+
+// Wait for handshake... or timeout
+DoneTail:
+ ldw r11, sp[STACK_EPTYPES_IN]
+ ldw r11, r11[r10] // Load EP Type
+ bt r11, SetupReceiveHandShake
+ bu XUD_IN_DoneTx
+
+SetupReceiveHandShake:
+ ldc r11, 8
+ setpsc res[RXD], r11 // Set port shift count (expect 8 bit handshake)
+ eeu res[RXD] // Events on RXD always enabled - Can;t be any more due to using events on channels
+
+SetupTimeout: // Timeout done using another port we dont happen to already be using events on. Cunning.
+#ifdef __XS2A__
+ ldw r1, sp[STACK_VTOK_PORT] // Load saved ValidToken port. Event vector already set.
+#else
+ ldw r1, dp[rx_rdy] // TODO load from stack
+#endif
+ in r11, res[r1] // Do input and get port time/timestamps
+ getts r11, res[r1]
+ ldw r9, dp[g_txHandshakeTimeout]
+ add r11, r11, r9
+ setpt res[r1], r11 // Set port time and enable events
+ eeu res[r1]
+
+WaitForHandshake: // Wait for timeout or handshake
+ .xtabranch TxHandshakeTimeOut, TxHandShakeReceived
+ waiteu
+
+// We sent some data but the host didn't handshake in time. Needs a re-send.
+.align FUNCTION_ALIGNMENT
+TxHandshakeTimeOut:
+ in r11, res[r1] // This will clear port time
+ edu res[r1]
+ {edu res[RXD]; bu BadHandshake}
+
+// Transmitted data, and got something back within the timeout. Check for valid handshake...
+.align FUNCTION_ALIGNMENT
+TxHandShakeReceived:
+XUD_IN_RxAck:
+ in r11, res[RXD] // Input data from RXD port
+ clrpt res[r1] // Clear port time on valid token port
+
+ {edu res[RXD]; shr r11, r11, 24} // Shift off junk data to leave ACK
+#if defined(__XS2A__)
+ ldc r9, USB_PID_ACK // Check for good ACK (L series strips of negated bits from PID)
+#else
+ ldc r9, USB_PIDn_ACK
+#endif
+ xor r9, r11, r9
+#ifdef __XS2A__
+ {edu res[r1]; bt r9, BadHandshake} // Disable events on ValidToken port
+#else
+ {bt r9, BadHandshake}
+#endif
+
+XUD_IN_DoneTx:
+
+ClearInEpReady: // TODO Tidy this up
+ ldc r9, 0 // TODO
+ ldw r10, r5[r3] // Load the EP struct
+ stw r9, r5[r3] // Clear the ready
+ ldw r11, r10[1] // Load channel
+ out res[r11], r11 // Output word to signal packet sent okay
+ bu NextToken
+
+BadHandshake:
+ bu NextToken
+
+.align 64
+.skip 56
+XUD_IN_SmallTxPacket:
+ ldw r8, r8[r4] // Load first data word
+ bru r6 // Branch on tail-length
+
+//--------------------------------------------------------------------------
+.align 32
+.skip 0
+TxTail0s: // We know this is a < 4 byte packet, so is 0 length packet
+ // So crc = 0. Note our normal crc calculation works for this, it is
+ // Not a special CRC case, but helps with timing.
+XUD_IN_TxPid_TailS0:
+ outpw res[TXD], r11, 8 // PID
+XUD_IN_TxCrc_TailS0:
+ outpw res[TXD], r4, 16 // Output CRC
+ bu DoneTail
+
+.align 32
+.skip 0
+TxTail1s: // One tail byte
+ shl r6, r8, 8 // Concat PID and Data
+ or r11, r11, r6
+ crc8 r7, r8, r8, r9
+ crc32 r7, r4, r9 // r4: 0
+ not r7, r7
+XUD_IN_TxPid_TailS1:
+ outpw res[TXD], r11, 16 // PID
+XUD_IN_TxCrc_TailS1:
+ outpw res[TXD], r7, 16
+ bu DoneTail
+
+.align 32
+.skip 0
+TxTail2s: // Two tail byte
+ crcn r7, r8, r9, r6
+ shl r6, r8, 8
+ crc32 r7, r4, r9 // r4: 0
+ {not r7, r7; or r11, r11, r6}
+XUD_IN_TxPid_TailS2:
+ outpw res[TXD], r11, 24 // Output PID and 2 bytes of data
+XUD_IN_TxCrc_TailS2:
+ outpw res[TXD], r7, 16 // Output CRC16
+ bu DoneTail
+
+.align 32
+.skip 0
+TxTail3s: // Three tail byte
+XUD_IN_TxPid_TailS3:
+ outpw res[TXD], r11, 8 // PID
+ outpw res[TXD], r8, 24
+ crcn r7, r8, r9, r6
+ crc32 r7, r4, r9 // r4: 0
+ not r7, r7
+XUD_IN_TxCrc_TailS3:
+ outpw res[TXD], r7, 16
+ bu DoneTail
+
+.align 32
+.skip 0
+TxTail4s: // Four tail byte
+XUD_IN_TxPid_TailS4:
+ outpw res[TXD], r11, 8 // PID
+ out res[TXD], r8
+ crc32 r7, r8, r9
+ crc32 r7, r4, r9 // r4: 0
+ not r7, r7
+XUD_IN_TxCrc_TailS4:
+ outpw res[TXD], r7, 16
+ bu DoneTail
diff --git a/lib_xud/src/core/included/XUD_Token_Out.S b/lib_xud/src/core/included/XUD_Token_Out.S
deleted file mode 100755
index 85d38dde..00000000
--- a/lib_xud/src/core/included/XUD_Token_Out.S
+++ /dev/null
@@ -1,162 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-// r10: EP number
-// OUT Token Packet -----------------------------------------------------------------------------
-// Ports
-#define RXD r0
-#define TXD r2
-
-.align 4
-.skip 0
-//.cc_top Pid_Out.func, Pid_Out
-Pid_Out:
-#ifdef ARCH_L
- inpw r10, res[RXD], 8; // Read EP Number */
- shr r10, r10, 24; // Shift off junk */
-
- in r4, res[r1];
- bt r4, InvalidToken; // If VALID_TOKEN not high, ignore token */
-#else
- // ARCH_G
- #include "XUD_G_Crc.S"
-#endif
- ldw r3, r5[r10] // Load relevant EP pointer
- bf r3, XUD_TokenOut_BufferFull
- ldw r1, r3[3] // Load buffer from EP structure
-
-CheckEpTypeOut:
- ldw r11, r3[5] // Load EP type
- bt r11, DoOutNonIso // ISO endpoint
-
-OutReady:
- bl doRXData
- clre
- ldc r11, 0
- stw r11, r5[r10] // Clear ready after receiving packet - avoids EP getting stuck in not-ready state if interrupted
-
-InformEP_Iso: // Iso EP - no handshake
- ldw r11, r3[1] // Load EP chanend
- out res[r11], r4 // Output datalength (words)
- outt res[r11], r8 // Send tail length
-
- ldc r6, 0x3334 // CRC16 init (out) - Needs reseting after an out
-#ifndef ARCH_G
- ldw r1, sp[STACK_FLAG0_PORT]
-#endif
- //ldc r4, XUD_MAX_NUM_EP_OUT // This could be shaved if XUD_MAX_NUM_EP's < 12. Now use an LDAW to at 16.
-
-//------------------------------------------------------------------------------------------------
-#ifdef ARCH_L
- ldaw r10, dp[PidJumpTable]
- // Original USB Token: | CRC | EP | ADDR | PID | junk
- // Received token is address and CRC checked.
- // We receive: | 0000 4-bit EP | 0000 4-bit PID |
-XUD_TokenRx_Pid_:
- inpw r11, res[RXD], 8 // Read 8 bit PID
- shr r11, r11, 24 // Shift off junk
-
- ldw r10, r10[r11] // Load relevant branch address
-
-BranchOnTokenPid_:
-.xtabranch Pid_Out, Pid_Sof, Pid_In, Pid_Setup, Pid_Sof_NoChan
- bau r10
-#else
- ldc r4, 16
-
-ReadToken_:
- inpw r11, res[RXD], 8 // Read 3 byte token from data port | CRC[5] | EP[4] | ADDR[7] | PID[8] | junk
- ldaw r10, dp[PidJumpTable]
- setpsc res[RXD], r4
- shr r11, r11, 24
-
-JumpOnPid_:
- ldw r11, r10[r11]
- .xtabranch Pid_Out, Pid_Sof, Pid_In, Pid_Setup
- bau r11
-#endif
-
-.align 4
-.skip 0
-DoOutNonIso:
- bl doRXData
- clre
-
- eq r1, r6, r11 // Check for good CRC16
-
-doRXDataReturn_NonIso:
- bf r1, NextTokenAfterOut // Check for bad crc
- ldc r11, USB_PIDn_ACK // Data CRC good and EP not Iso: Send Ack
- outpw res[TXD], r11, 8
- syncr res[TXD]
-
-StoreTailDataOut:
- //shr r8, r8, 3 // r8: number of tail bits, convert to bytes
- // This is now done on the other side
- ldc r11, 0
- stw r11, r5[r10] // Clear ready
- ldw r11, r3[1] // Load EP chanend
-
- out res[r11], r4 // Output datalength (words)
- outt res[r11], r8 // Send tail length
-
- bu NextTokenAfterOut
-
-// Various Error handling functions -------------------------------------------------------------------
-Err_RxErr: // RxError signal high during data packet receive:
- clrsr 3
- clre
- ldw r10, sp[15] // Read out data from RxE port
- in r11, res[r10]
- eeu res[r10]
- ldw r10, sp[10]
- in r11, res[r10] // Wait for rxa low and ignore packet (let transaction timout)
- setsr 3 // Re-enable thread interrupts
- bu NextToken
-
-Err_EndpointProblem:
- // TODO:Endpoint in trouble (send STALL) or disabled (ignore?)...
- bu NextToken
-
-//Err_BadDataCrc: // Data packet received with bad crc: Ignore; wait for timeout (host will re-send)
- //bu NextToken
-
-Err_BadPidSeq: // Bad pid sequencing (already ACKed good data). Ignore data
- bu NextToken
-
-XUD_TokenOut_BufferFull:
- ldw r9, dp[flag1_port]
- setc res[r9], XS1_SETC_RUN_CLRBUF
- setc res[r9], XS1_SETC_COND_NEQ
-XUD_TokenOut_WaitForPacketEnd: // Wait for end of data then send NAK
- in r11, res[r9]
- setc res[r9], XS1_SETC_COND_EQ
- in r11, res[r9]
- // TODO: Observe interpacket delay
-#ifndef XUD_NAK_ISO_OUT
- ldw r4, sp[(STACK_EXTEND+5)] // Load ep type table
- ldw r4, r4[r10] // load EP type
- bf r4, PrimaryBufferFull_NoNak
-#endif
-
- // LOAD HANDSHAKE PID or STALL
- ldaw r5, dp[handshakeTable_OUT] // Load handshake table
- ldw r11, r5[r10]
- //ldc r11, 0x5a
- outpw res[TXD], r11, 8
- syncr res[TXD]
-
-PrimaryBufferFull_NoNak:
- //endin r11, res[RXD]
- //in r11, res[RXD]
- setc res[RXD], XS1_SETC_RUN_CLRBUF
- bu NextToken
-
-// Timedout waiting for data after OUT... go back to waiting for tokens
-OutDataTimeOut:
- //clre
- //bl ERR_OutDataTimeout
- bu NextToken
-
-
-
-//.cc_bottom Pid_Out.func
diff --git a/lib_xud/src/core/included/XUD_Token_Out_DI.S b/lib_xud/src/core/included/XUD_Token_Out_DI.S
new file mode 100755
index 00000000..04b842ef
--- /dev/null
+++ b/lib_xud/src/core/included/XUD_Token_Out_DI.S
@@ -0,0 +1,114 @@
+// Copyright 2011-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+// r10: EP number
+// OUT Token Packet -----------------------------------------------------------------------------
+#include "XUD_AlignmentDefines.h"
+
+.align FUNCTION_ALIGNMENT
+.skip 0
+Pid_Out:
+ #include "XUD_CrcAddrCheck.S"
+ ldw r3, r5[r10] // Load relevant EP pointer
+ bf r3, XUD_TokenOut_BufferFull
+ ldw r1, r3[3] // Load buffer from EP structure
+
+CheckEpTypeOut:
+ ldw r11, r3[5] // Load EP type
+ BRFT_ru6 r11, DoOutNonIso // ISO endpoint
+
+OutReady:
+ stw r11, r5[r10] // Clear ready straight away - we don't to CRC checking on Iso - else we would have to wait for end of packet
+ bl doRXData
+ clre
+
+InformEP_Iso: // Iso EP - no handshake
+ ldw r11, r3[1] // Load EP chanend
+ {out res[r11], r4; ldw r7, sp[STACK_TXCRC_INIT]} // Output datalength (words) & CRC 16 Init (IN)
+ {outt res[r11], r8; ldw r6, sp[STACK_RXCRC_INIT]} // CRC16 init (out) - Needs reseting after an out & Send tail length
+#ifndef __XS3A__
+ ldw r1, sp[STACK_VTOK_PORT]
+#endif
+ #include "XUD_TokenJmp.S"
+
+.align FUNCTION_ALIGNMENT
+.skip 0
+DoOutNonIso:
+ bl doRXData
+ {clre; eq r1, r6, r11} // Check for good CRC16
+
+doRXDataReturn_NonIso:
+ bf r1, NextTokenAfterOut // Check for bad crc
+
+ ldaw r6, dp[handshakeTable_OUT] // Load the handshake table.
+ {ldw r11, r6[r10] // Get the handshake PID for this EP
+ ldc r1, USB_PIDn_STALL} // as well as the STALL PID
+ eq r1, r11, r1 // and compare them.
+ nop // NOP to ensure minimum interpacket delay.
+ bt r1, XUD_TokenOut_Handshake // If the handshake PID for this EP is STALL, then
+ // go and send the handshake without clearing ready
+ // or communicating back to the application that
+ // the packet has been received.
+
+ ldc r11, USB_PIDn_ACK // Data CRC good, EP not Iso, and EP not halted: Send Ack
+ outpw res[TXD], r11, 8
+ syncr res[TXD]
+
+StoreTailDataOut:
+ ldc r11, 0
+ stw r11, r5[r10] // Clear ready
+ ldw r11, r3[1] // Load EP chanend
+
+ out res[r11], r4 // Output datalength (words)
+ outt res[r11], r8 // Send tail length
+
+ bu NextTokenAfterOut
+
+// Various Error handling functions -------------------------------------------------------------------
+.align FUNCTION_ALIGNMENT
+Err_RxErr: // RxError signal high during data packet receive:
+ DUALENTSP_lu6 0
+ clrsr 3
+ clre
+ ldw r10, sp[STACK_RXE_PORT] // Read out data from RxE port
+ in r11, res[r10]
+ eeu res[r10]
+ ldw r10, sp[STACK_RXA_PORT]
+ in r11, res[r10] // Wait for rxa low and ignore packet (let transaction timout)
+ setsr 3 // Re-enable thread interrupts
+ bu NextToken
+
+XUD_TokenOut_BufferFull:
+ ldw r9, sp[STACK_RXA_PORT]
+ setc res[r9], XS1_SETC_RUN_CLRBUF
+ setc res[r9], XS1_SETC_COND_NEQ
+
+XUD_TokenOut_WaitForPacketEnd: // Wait for end of data then send NAK
+ in r11, res[r9]
+ setc res[r9], XS1_SETC_COND_EQ
+ in r11, res[r9]
+ // TODO: Observe interpacket delay
+#ifndef XUD_NAK_ISO_OUT
+ ldw r4, sp[STACK_EPTYPES_OUT] // Load ep type table
+ ldw r4, r4[r10] // load EP type
+ bf r4, PrimaryBufferFull_NoNak
+#endif
+
+ // Load handshake (ACK or STALL)
+ ldaw r6, dp[handshakeTable_OUT] // Load handshake table
+XUD_TokenOut_Handshake:
+ ldw r11, r6[r10]
+ outpw res[TXD], r11, 8
+ syncr res[TXD]
+
+PrimaryBufferFull_NoNak:
+ setc res[RXD], XS1_SETC_RUN_CLRBUF
+ bu NextToken
+
+// Timedout waiting for data after OUT... go back to waiting for tokens
+//OutDataTimeOut:
+ //clre
+ //bl ERR_OutDataTimeout
+ //bu NextToken
+
+
+
diff --git a/lib_xud/src/core/included/XUD_Token_Ping.S b/lib_xud/src/core/included/XUD_Token_Ping.S
index d09ba17c..142096af 100755
--- a/lib_xud/src/core/included/XUD_Token_Ping.S
+++ b/lib_xud/src/core/included/XUD_Token_Ping.S
@@ -1,16 +1,10 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-.align 4
-Pid_Ping:
-#ifdef ARCH_L
- inpw r10, res[RXD], 8; // Read EP Number
- shr r10, r10, 24; // Shift off junk
+#include "XUD_AlignmentDefines.h"
- in r11, res[r1];
- bt r11, InvalidToken; // VALID_TOKEN not high, ignore token
-#else
- #include "XUD_G_Crc.S"
-#endif
+.align FUNCTION_ALIGNMENT
+Pid_Ping:
+ #include "XUD_CrcAddrCheck.S"
LoadStatTablePing:
ldw r11, r5[r10] // Load relevant EP chanend
@@ -18,9 +12,11 @@ LoadStatTablePing:
.scheduling off
PrimaryBufferEmpty_PING: // Send ACK
+#if (XUD_CORE_CLOCK > 400)
nop
nop
nop
+#endif
nop
nop
nop
@@ -30,14 +26,18 @@ PrimaryBufferEmpty_PING: // Send ACK
bu NextTokenAfterPing
PrimaryBufferFull_PING: // Send NAK
+#if (XUD_CORE_CLOCK > 400)
nop
nop
nop
+#endif
nop
nop
nop
- nop
- ldc r11, USB_PIDn_NAK
+ // ldc r11, USB_PIDn_NA
+ // Load handshake (ACK or STALL)
+ ldaw r11, dp[handshakeTable_OUT] // Load handshake table
+ ldw r11, r11[r10]
outpw res[TXD], r11, 8
bu NextTokenAfterPing
.scheduling default
diff --git a/lib_xud/src/core/included/XUD_Token_SOF.S b/lib_xud/src/core/included/XUD_Token_SOF.S
index 734cc43d..e708d04d 100644
--- a/lib_xud/src/core/included/XUD_Token_SOF.S
+++ b/lib_xud/src/core/included/XUD_Token_SOF.S
@@ -1,30 +1,34 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-//.cc_top Pid_Sof.func, Pid_Sof
-// Received SOF token: Reset suspend/reset detection timer
+#include "XUD_AlignmentDefines.h"
-.align 4
+// Received SOF token: Reset suspend/reset detection timer
+.align FUNCTION_ALIGNMENT
Pid_Sof:
-#ifdef ARCH_L
+#ifdef __XS2A__
inpw r10, res[RXD], 8 // Read EP Number
shr r10, r10, 24; // Shift off junk
in r11, res[r1];
- bt r11, InvalidToken; // If VALID_TOKEN not high, ignore token
+ bt r11, XUD_InvalidToken; // If VALID_TOKEN not high, ignore token
#else
-//#include "XUD_G_Crc.S"
+ // NOTE: we are not CRC checking SOF's
in r10, res[RXD] // Input Frame number
+ shr r10 , r10, 16 // Shift off port junk
+ ldc r11, 0x7ff // Remove CRC5
+ and r10, r10, r11
+
#endif
clrsr 0x3
- ldw r11, sp[(STACK_EXTEND+9)]
+ ldw r11, sp[STACK_SOFCHAN]
out res[r11], r10
- ldw r10, sp[14] // Load timer from stack
+ ldw r10, sp[STACK_SUSPEND_TIMER] // Load timer from stack
setc res[r10], XS1_SETC_COND_NONE // Read current time
- ldw r8, sp[13] // Add suspend timeout to current time
+ ldw r8, sp[STACK_SUSPEND_TIMEOUT] // Add suspend timeout to current time
in r11, res[r10]
add r11, r11, r8
setd res[r10], r11
@@ -32,42 +36,34 @@ Pid_Sof:
setc res[r10], XS1_SETC_COND_AFTER // Re-enable thread interrupts
setsr 0x3
- bu Loop_BadPid
-
-//.cc_bottom Pid_Sof.func
-
-
-//.cc_top Pid_Sof_NoChan.func, Pid_Sof_NoChan
+ bu Loop_BadPid
// Received SOF token: Reset suspend/reset detection timer
-.align 4
+.align FUNCTION_ALIGNMENT
Pid_Sof_NoChan:
-#ifdef ARCH_L
+#ifdef __XS2A__
inpw r10, res[RXD], 8; /* Read EP Number */
shr r10, r10, 24; /* Shift off junk */
in r11, res[r1];
- bt r11, InvalidToken; /* If VALID_TOKEN not high, ignore token */
+ bt r11, XUD_InvalidToken; /* If VALID_TOKEN not high, ignore token */
-//bl printintln
#else
-//#include "XUD_G_Crc.S"
in r10, res[RXD] // Input Frame number
#endif
clrsr 0x3
- ldw r10, sp[14] // Load timer from stack
+ ldw r10, sp[STACK_SUSPEND_TIMER] // Load timer from stack
setc res[r10], XS1_SETC_COND_NONE // Read current time
- ldw r8, sp[13]
+ ldw r8, sp[STACK_SUSPEND_TIMEOUT]
in r11, res[r10]
add r11, r11, r8
setd res[r10], r11
- ldw r8, sp[13]
+ ldw r8, sp[STACK_SUSPEND_TIMEOUT]
setc res[r10], XS1_SETC_COND_AFTER // Re-enable thread interrupts
setsr 0x3
- bu Loop_BadPid
+ bu Loop_BadPid
-//.cc_bottom Pid_Sof_NoChan.func
diff --git a/lib_xud/src/core/included/XUD_Token_Setup.S b/lib_xud/src/core/included/XUD_Token_Setup.S
deleted file mode 100644
index a5b520d2..00000000
--- a/lib_xud/src/core/included/XUD_Token_Setup.S
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2011-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-.text
-
-#if 0
-WaitForEndDataPacket:
- ldw r10, sp[10] // Load RxA Port ID (r1)
- in r11, res[r10]
- bt r11, waitforRXALow
- setc res[RXD], XS1_SETC_RUN_CLRBUF
- bu NextTokenAfterOut
-#endif
-
-// Expects
-// r5: buffer address
-// RXD: Rx Data port
-// r4: zero
-// r7: crc init
-// r9: crc poly
-.align 4
-.skip 0
-doRXData:
- ldw r11, sp[10] // Load RxA Port ID (r1)
- in r8, res[r11] // Doing an IN to clear any previous event data
- // - saves us havin to reload the port ID later...
- inpw r8, res[r0], 8 // Input PID
-GotRxPid:
- stw r8, r3[6] // Store (NON-SHIFTED) PID into EP structure
- eeu res[r11]
-.syntax architectural
- SETSR_lu6 1 // Enable thread events. Note long inst to align loop
-.syntax default
-
-NextRxWord: // RXD port has event vector here
- in r11, res[r0]
- crc32 r6, r11, r9
- stw r11, r1[r4]
- add r4, r4, 1
-.xtabranch NextRxWord, RxALow
- bu NextRxWord
-
-/////////////////////////////////////////////////////////////////////////////
-.align 16
-.skip 10
-RxALow:
- endin r8, res[r0]
-XUD_OUT_RxTail:
- in r11, res[r0]
-
-.xtabranch OutTail0, OutTail1, OutTail2, OutTail3, OutTail4, OutTail5
- bru r8
-
-// Word aligned data (0 byte tail)
-.align 16
-OutTail0:
- crc32 r6, r8, r9 // CRC zero step
- ldc r11, 0x7000 // Load relevant CRC magic number
- retsp 0
-
-// 1 Tail Byte
-.align 16
-OutTail1:
- shr r11, r11, 24 // Shift off junk
- crc32 r6, r11, r9
- stw r11, r1[r4] // Store last data
- ldc r11, 0x80be // Load CRC magic number
- retsp 0
-
-// Two Tail Bytes
-.align 16
-OutTail2:
- shr r11, r11, 16
- crc32 r6, r11, r9
- stw r11, r1[r4] // Store last data
- ldc r11, 0x3ffe
- retsp 0
-
-// Three Tail Bytes
-.align 16
-OutTail3:
- shr r11, r11, 8
- stw r11, r1[r4] // Store last data
- crc32 r6, r11, r9
- ldw r11, sp[12]
- crc8 r6, r1, r2, r9 // Use the fact the the bottom byte of port id is 0.. saves us an ldc
- retsp 0
-
-// Four Tail Bytes
-OutTail4:
- bu ERR_EndIn4
-
-
-// Five Tail Bytes
-.align 16
-OutTail5:
- bu ERR_EndIn5
-
-
-// We received a setup token. This is much the same as out token, apart from:
-// - Can't NAK a setup
-// - Data PID will always be DATA0
-// - Payload will always be 8 bytes
-
-.align 4
-Pid_Setup:
-#ifdef ARCH_L
- inpw r10, res[RXD], 8; // Read EP Number
- shr r10, r10, 24; // Shift off junk
-
- in r4, res[r1];
- bt r4, InvalidToken; // If VALID_TOKEN not high, ignore token - PORT INVERTED
-#else
- #include "XUD_G_Crc.S"
-#endif
- ldw r3, r5[r10] // Load relevant EP pointer
- bf r3, SBuffFull
- ldw r1, r3[3] // Load buffer
-
-
-SetupReady:
- //ldw r10, sp[10] // Load RxA Port ID (r1)
- // TODO Do a timeout here?
-
-LoadSetupBuffer:
- bl doRXData // RXData writes available data to buffer and does crc check.
- // r8: Data tail size (bytes)
- clre
- eq r1, r6, r11 // Check for good CRC16
- bf r1, NextTokenAfterOut // Check for bad crc
-
-ClearStall: // CRC OK
- // Have received a SETUP so clear any STALL condition on IN/OUT endpoint.
- ldaw r11, dp[handshakeTable_OUT]
- ldc r6, USB_PIDn_NAK
- stw r6, r11[r10]
- ldaw r11, dp[handshakeTable_IN]
- stw r6, r11[r10]
-
-SendSetupAck:
- ldc r11, USB_PIDn_ACK
- outpw res[TXD], r11, 8
-
-StoreTailData: // TODO: don't assume setups are 8 bytes + crc
- ldc r11, 0
- stw r11, r5[r10] // Clear ready
- ldw r11, r3[1] // Load chanend
-
- out res[r11], r4
- outct res[r11], 0 // Send zero control token for SETUP. Tail ignored since always expect 8 bytes
- bu NextTokenAfterOut // Go to next wait for next token
-
-
-SBuffFull:
- ldc r11, 0
- ldw r10, sp[10] // Load RxA Port ID (r1)
- in r11, res[r10] // RXA event cond = 0 TODO: Wait for RXA high first?
- endin r11, res[RXD]
- in r11, res[RXD]
-
- bu NextTokenAfterOut
-
-BadDataCrcSetup:
- mov r0, r1
- bl ERR_BadCrc
- outct res[r5], 9
- in r11, res[r5] // TODO should only need CT
- bu NextToken
diff --git a/lib_xud/src/core/included/XUD_Token_Setup_DI.S b/lib_xud/src/core/included/XUD_Token_Setup_DI.S
new file mode 100644
index 00000000..fbd72316
--- /dev/null
+++ b/lib_xud/src/core/included/XUD_Token_Setup_DI.S
@@ -0,0 +1,50 @@
+// Copyright 2011-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "XUD_AlignmentDefines.h"
+
+// We received a setup token. This is much the same as out token, apart from:
+// - Can't NAK a setup
+// - Data PID will always be DATA0
+// - Payload will always be 8 bytes
+.align FUNCTION_ALIGNMENT
+Pid_Setup:
+ #include "XUD_CrcAddrCheck.S"
+ ldw r3, r5[r10] // Load relevant EP pointer
+ bf r3, SBuffFull
+ ldw r1, r3[3] // Load buffer
+
+LoadSetupBuffer:
+ bl doRXData // RXData writes available data to buffer and does crc check.
+ // r8: Data tail size (bytes)
+ {clre; eq r1, r6, r11} // Check for good CRC16
+ bf r1, NextTokenAfterOut // Check for bad crc
+
+ClearStall: // CRC OK
+ // Have received a SETUP so clear any STALL condition on IN/OUT endpoint.
+ ldaw r11, dp[handshakeTable_OUT] // Note, we can speed this up by assuming SETUP only received on EP 0
+ ldc r6, USB_PIDn_NAK
+ stw r6, r11[r10]
+ {ldw r11, sp[STACK_HANDSHAKETABLEIN]
+ ldc r1, 0}
+ stw r6, r11[r10]
+ ldaw r11, dp[g_stallTable_IN]
+ stw r1, r11[r10]
+
+SendSetupAck:
+ ldc r11, USB_PIDn_ACK
+ outpw res[TXD], r11, 8
+
+StoreTailData: // TODO: don't assume setups are 8 bytes + crc
+ stw r1, r5[r10] // Clear ready
+ ldw r11, r3[1] // Load chanend
+
+ out res[r11], r4
+ outct res[r11], 0 // Send zero control token for SETUP. Tail ignored since always expect 8 bytes
+ bu NextTokenAfterOut // Go to next wait for next token
+
+SBuffFull:
+ ldw r10, sp[STACK_RXA_PORT] // Load RxA Port ID (r1)
+ in r11, res[r10] // RXA event cond = 0 TODO: Wait for RXA high first?
+ endin r11, res[RXD]
+ in r11, res[RXD]
+ bu NextTokenAfterOut
diff --git a/lib_xud/src/user/XUD_USB_Defines.h b/lib_xud/src/user/XUD_USB_Defines.h
index 53327598..6f0082ef 100644
--- a/lib_xud/src/user/XUD_USB_Defines.h
+++ b/lib_xud/src/user/XUD_USB_Defines.h
@@ -7,8 +7,6 @@
#ifndef _USB_DEFS_H_
#define _USB_DEFS_H_
-#define USB_TILE_REF usb_tile
-
/* Table 8-1. PID Types */
#define USB_PID_OUT 0x1 /* Tokens */
#define USB_PID_IN 0x9
diff --git a/lib_xud/src/user/client/XUD_EpFuncs.S b/lib_xud/src/user/client/XUD_EpFuncs.S
index 582e7178..95c0e1b6 100644
--- a/lib_xud/src/user/client/XUD_EpFuncs.S
+++ b/lib_xud/src/user/client/XUD_EpFuncs.S
@@ -1,29 +1,37 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
/** XUD_EpFuncs.S
- * @brief Functions for data transfer to/from XUD
+ * @brief ASM functions for data transfer to/from XUD
* @author Ross Owen, XMOS Limited
*/
#include "XUD_USB_Defines.h"
+#include "XUD_AlignmentDefines.h"
-#if !defined __XS2A__
+#if defined __XS2A__
.set too_many_cores, main.maxcores > 6
.assert 0, too_many_cores, "Warning: More than 6 cores used on a tile. Ensure this is not the case on tile running XUD."
#endif
+.section .cp.rodata,"ac", @progbits
+.cc_top ep_info_address.data,ep_info_address
+.align FUNCTION_ALIGNMENT
+.type ep_info_address,@object
+.size ep_info_address, 4
+ep_info_address:
+.long ep_info
+.cc_bottom ep_info_address.data
+
+
//int XUD_GetSetupData(XUD_ep e_out, unsigned buffer[], unsigned &length);
// r0 r1 r2
+.text
.globl XUD_GetSetupData
.type XUD_GetSetupData, @function
.cc_top XUD_GetSetupData.func
-.align 4
-XUD_GetSetupData:
-#if defined(__XS2A__)
.issue_mode single
- ENTSP_lu6 4
-#else
- entsp 4
-#endif
+.align FUNCTION_ALIGNMENT
+XUD_GetSetupData:
+ ENTSP_lu6 4
stw r4, sp[1]
stw r10, sp[2]
@@ -52,7 +60,7 @@ XUD_GetSetupData_NoReq: // Entry for _NoReq
// TODO..
XUD_GetSetupData_ResetPid: // We must reset PID toggling on SETUP (both IN AND OUT)
-#if (XUD_SERIES_SUPPORT==3)
+#ifdef __XS3A__
ldc r11, USB_PIDn_DATA1
#else
ldc r11, USB_PID_DATA1
@@ -135,13 +143,13 @@ XUD_GetSetupData_Reset:
.globl XUD_GetData
.type XUD_GetData, @function
.cc_top XUD_GetData.func
-.align 4
+.align FUNCTION_ALIGNMENT
XUD_GetData:
-#if defined(__XS2A__)
+#if defined(__XS2A__) || defined(__XS3A__)
.issue_mode single
- ENTSP_lu6 4
+ ENTSP_lu6 4
#else
- entsp 4
+ entsp 4
#endif
stw r10, sp[1]
mov r11, r1
@@ -188,7 +196,7 @@ XUD_GetData_PidOkay:
bf r11, XUD_GetData_ReturnOk // Jump over PID toggle for ISO
XUD_GetData_PidToggle:
-#if (XUD_SERIES_SUPPORT==3)
+#ifdef __XS3A__
ldc r11, 0x88
#else
ldc r11, 8
@@ -220,8 +228,8 @@ XUD_GetData_GotSetup:
// We expect data0 else something gone wrong...
// TODO..
-XUD_GetDataSetupData_ResetPid: // We must reset PID toggling on SETUP (both IN AND OUT)
-#if (XUD_SERIES_SUPPORT==3)
+XUD_GetDataSetupData_ResetPid: // We must reset PID toggling on SETUP (both IN AND OUT)
+#ifdef __XS3A__
ldc r11, USB_PIDn_DATA1
#else
ldc r11, USB_PID_DATA1
@@ -272,13 +280,13 @@ XUD_GetDataSetupData_ResetPid: // We must reset PID togglin
.globl XUD_SetData
.type XUD_SetData, @function
.cc_top XUD_SetData.func
-.align 4
+.align FUNCTION_ALIGNMENT
XUD_SetData:
-#if defined(__XS2A__)
+#if defined(__XS2A__) || defined(__XS3A__)
.issue_mode single
- ENTSP_lu6 8
+ ENTSP_lu6 8
#else
- entsp 8
+ entsp 8
#endif
stw r5, sp[5]
stw r10, sp[6]
@@ -293,15 +301,24 @@ XUD_SetData_NoReq:
add r1, r1, r3 // Add start index to buffer address
CalcTailLength:
- shl r3, r2, 5 // Taillength: bytes to bits * 2
- zext r3, 7
+ shl r3, r2, 3 // Tail length: bytes to bits
+ zext r3, 5
SetupLoopTerm:
shr r2, r2, 2 // r2: datalength (bytes) ---> r2: datalength (words)
+ // TODO do this a bit more effciently..
+ // If tail is 0 and word-length not 0. Make tail-length 32 and word-length--
+ bt r3, AdjustBufferPointer
+ bf r2, AdjustBufferPointer
+
+ sub r2, r2, 1
+ ldc r3, 32
+
AdjustBufferPointer:
shl r5, r2, 2 // Get end off buffer address
add r1, r1, r5
+
NegativeIndex: // Produce negtive offset from end of buffer
neg r2, r2
@@ -370,9 +387,9 @@ XUD_SetData_Reset:
.globl XUD_GetData_Select
.type XUD_GetData_Select, @function
.cc_top XUD_GetData_Select.func
-.align 4
+.align FUNCTION_ALIGNMENT
XUD_GetData_Select:
-#if defined(__XS2A__)
+#if defined(__XS2A__) || defined(__XS3A__)
.issue_mode single
ENTSP_lu6 0
#endif
@@ -408,7 +425,7 @@ XUD_GetData_Select_CheckPid: // Check PID
bt r11, XUD_GetData_Select_BadPkt
XUD_GetData_Select_PidToggle:
-#if (XUD_SERIES_SUPPORT==3)
+#ifdef __XS3A__
ldc r2, 0x88
#else
ldc r2, 8
@@ -461,9 +478,9 @@ XUD_GetData_Select_Return_Reset:
.globl XUD_SetData_Select
.type XUD_SetData_Select, @function
.cc_top XUD_SetData_Select.func
-.align 4
+.align FUNCTION_ALIGNMENT
XUD_SetData_Select:
-#if defined(__XS2A__)
+#if defined(__XS2A__) || defined(__XS3A__)
.issue_mode single
ENTSP_lu6 0
#endif
@@ -519,20 +536,24 @@ XUD_SetData_Select_Reset:
/* R0: ep number */
.cc_top XUD_SetStallByAddr.func
-.align 4
+.align FUNCTION_ALIGNMENT
XUD_SetStallByAddr:
-#if defined(__XS2A__)
+#if defined(__XS2A__) || defined(__XS3A__)
.issue_mode single
ENTSP_lu6 0
#endif
ldc r2, USB_PIDn_STALL
- ldc r11, 0x80 // Check for IN bit
+ ldc r11, 0x80 // Check for IN bit
and r11, r11, r0
bf r11, XUD_SetStallByAddr_OUT
ldaw r1, dp[handshakeTable_IN]
mkmsk r11, 7
and r11, r11, r0
stw r2, r1[r11]
+
+ ldaw r1, dp[g_stallTable_IN] // Mark stall table with non-zero entry
+ stw r2, r1[r11]
+
retsp 0
XUD_SetStallByAddr_OUT:
ldaw r1, dp[handshakeTable_OUT]
@@ -565,22 +586,25 @@ XUD_SetStallByAddr_OUT:
/* R0: ep number */
.cc_top XUD_ClearStallByAddr.func
-.align 4
-XUD_ClearStallByAddr:
-#if defined(__XS2A__)
.issue_mode single
- ENTSP_lu6 0
-#endif
+.align FUNCTION_ALIGNMENT
+XUD_ClearStallByAddr:
+ ENTSP_lu6 0
ldc r2, USB_PIDn_NAK
- ldc r11, 0x80 // Check for IN bit
+ ldc r11, 0x80 // Check for IN bit
and r11, r11, r0
bf r11, XUD_ClearStallByAddr_OUT
- ldaw r1, dp[handshakeTable_IN] // Reset Handshake
+ ldaw r1, dp[handshakeTable_IN] // Reset Handshake
mkmsk r11, 7
and r11, r11, r0
stw r2, r1[r11]
- // Calc offset for data pid
- ldaw r0, r11[4] // Assume MAX_NUM_EP_OUT is 16 here! (r0 = r0 + 4 * 4)
+
+ ldaw r1, dp[g_stallTable_IN]
+ ldc r2, 0
+ stw r2, r1[r11] // Mark stall with zero entry
+
+ // Calc offset for data pid
+ ldaw r0, r11[4] // Assume MAX_NUM_EP_OUT is 16 here! (r0 = r0 + 4 * 4)
ldc r1, USB_PIDn_DATA0
bu XUD_ClearStallByAddr_ResetDataPid
@@ -588,7 +612,7 @@ XUD_ClearStallByAddr_OUT:
ldaw r1, dp[handshakeTable_OUT]
stw r2, r1[r0]
-#if(XUD_SERIES_SUPPORT==3)
+#ifdef __XS3A__
ldc r1, USB_PIDn_DATA0
#else
ldc r1, USB_PID_DATA0
@@ -598,7 +622,7 @@ XUD_ClearStallByAddr_ResetDataPid: // Reset DATA PID to DATA0
ldc r2, 40 // Size of XUD_ep_info struct TODO use sizeof() -
mul r0, r0, r2 // Be careful with packing
- ldaw r2, dp[ep_info]
+ ldw r2, cp[ep_info_address]
add r0, r2, r0
stw r1, r0[4]
@@ -631,9 +655,9 @@ XUD_ClearStallByAddr_ResetDataPid: // Reset DATA PID to DATA0
/* R0: ep number */
.cc_top XUD_ResetEpStateByAddr.func
-.align 4
+.align FUNCTION_ALIGNMENT
XUD_ResetEpStateByAddr:
-#if defined(__XS2A__)
+#if defined(__XS2A__) || defined(__XS3A__)
.issue_mode single
ENTSP_lu6 0
#endif
@@ -643,7 +667,7 @@ XUD_ResetEpStateByAddr:
ldc r1, USB_PIDn_DATA0
bu XUD_ResetEpStateByAddr_
XUD_ResetEpStateByAddr_OUT:
-#if(XUD_SERIES_SUPPORT==3)
+#if defined(__XS3A__)
ldc r1, USB_PIDn_DATA0
#else
ldc r1, USB_PID_DATA0
@@ -655,7 +679,7 @@ XUD_ResetEpStateByAddr_:
NoOffset:
ldc r2, 40 // Size of XUD_ep_info struct TODO. FIXME!
mul r0, r0, r2
- ldaw r2, dp[ep_info]
+ ldw r2, cp[ep_info_address]
add r0, r2, r0
stw r1, r0[4]
retsp 0
@@ -686,11 +710,11 @@ NoOffset:
.type XUD_SetTestMode, @function
.cc_top XUD_SetTestMode.func
-.align 4
+.align FUNCTION_ALIGNMENT
XUD_SetTestMode:
-#if defined(__XS2A__)
+#if defined(__XS2A__) || defined(__XS3A__)
.issue_mode single
- ENTSP_lu6 0
+ ENTSP_lu6 0
#endif
ldw r0, r0[2] // Load our chanend ID to use
outct res[r0], 1
diff --git a/lib_xud/src/user/client/XUD_EpFunctions.xc b/lib_xud/src/user/client/XUD_EpFunctions.xc
index 30917907..051f21fd 100644
--- a/lib_xud/src/user/client/XUD_EpFunctions.xc
+++ b/lib_xud/src/user/client/XUD_EpFunctions.xc
@@ -33,6 +33,11 @@ XUD_Result_t XUD_SetBuffer(XUD_ep c, unsigned char buffer[], unsigned datalength
return XUD_SetData(c, buffer, datalength, 0, 0);
}
+void XUD_Kill(XUD_ep ep)
+{
+ XUD_SetTestMode(ep, 0);
+}
+
XUD_Result_t XUD_SetBuffer_EpMax(XUD_ep ep_in, unsigned char buffer[], unsigned datalength, unsigned epMax)
{
int i = 0;
@@ -132,6 +137,16 @@ void XUD_ClearStall(XUD_ep ep)
XUD_ClearStallByAddr(epAddress);
}
+void XUD_CloseEndpoint(XUD_ep one)
+{
+ unsigned c1;
+
+ /* Input rst control token */
+ asm volatile("ldw %0, %1[2]":"=r"(c1):"r"(one)); // Load our chanend
+ asm volatile ("outct res[%0], 1":: "r"(c1)); // Close channel to other side
+ asm volatile ("chkct res[%0], 1":: "r"(c1)); // Close channel to this side
+}
+
XUD_BusSpeed_t XUD_ResetEndpoint(XUD_ep one, XUD_ep &?two)
{
int busStateCt;
diff --git a/lib_xud/src/user/client/XUD_SetDevAddr.xc b/lib_xud/src/user/client/XUD_SetDevAddr.xc
index d48435a9..7c4605c8 100644
--- a/lib_xud/src/user/client/XUD_SetDevAddr.xc
+++ b/lib_xud/src/user/client/XUD_SetDevAddr.xc
@@ -1,25 +1,8 @@
// Copyright 2011-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#include "XUD_UIFM_Functions.h"
-#include "XUD_USB_Defines.h"
-#include "XUD_UIFM_Defines.h"
#include "xud.h"
-
-#ifdef ARCH_S
-#include
-#endif
-
-#ifdef ARCH_X200
-#include "xs2_su_registers.h"
-#endif
-
-#if defined(ARCH_S) || defined(ARCH_X200)
-#include "XUD_USBTile_Support.h"
-extern unsigned get_tile_id(tileref ref);
-extern tileref USB_TILE_REF;
-#endif
-
+#include "XUD_HAL.h"
void XUD_SetCrcTableAddr(unsigned addr);
@@ -28,24 +11,12 @@ void XUD_SetCrcTableAddr(unsigned addr);
*/
XUD_Result_t XUD_SetDevAddr(unsigned addr)
{
-#ifdef ARCH_L
- /* Set device address in UIFM */
-#if defined(ARCH_X200)
- write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_GLX_PER_UIFM_DEVICE_ADDRESS_NUM, addr);
-#elif defined(ARCH_S)
- write_periph_word(USB_TILE_REF, XS1_SU_PER_UIFM_CHANEND_NUM, XS1_SU_PER_UIFM_DEVICE_ADDRESS_NUM, addr);
-#else
- /* RegWrite_ loads write port from dp to avoid parallel usage checks */
- /* TODO this should really be locked for mutual exclusion */
- XUD_UIFM_RegWrite_(UIFM_REG_ADDRESS, addr);
-#endif
-
-#elif ARCH_G
- /* Modify CRC table for current address */
+#ifdef __XS3A__
+ /* XS3: Modify CRC table for current address */
XUD_SetCrcTableAddr(addr);
#else
-#error ARCH_L or ARCH_G MUST be defined
+ /* Set device address in UIFM */
+ write_periph_word(USB_TILE_REF, XS1_GLX_PER_UIFM_CHANEND_NUM, XS1_GLX_PER_UIFM_DEVICE_ADDRESS_NUM, addr);
#endif
-
return XUD_RES_OKAY;
}
diff --git a/lib_xud/src/user/control/xud_device.xc b/lib_xud/src/user/control/xud_device.xc
index 4020b924..32525dbc 100644
--- a/lib_xud/src/user/control/xud_device.xc
+++ b/lib_xud/src/user/control/xud_device.xc
@@ -191,6 +191,7 @@ XUD_Result_t USB_StandardRequests(XUD_ep ep_out, XUD_ep ep_in,
break;
/* Standard Device Request: SetFeature (USB Spec 9.4.9) */
+ /* TODO only accept these requests in HS? */
case USB_SET_FEATURE:
if((sp.wValue == USB_TEST_MODE) && (sp.wLength == 0))
@@ -202,7 +203,6 @@ XUD_Result_t USB_StandardRequests(XUD_ep ep_out, XUD_ep ep_in,
case USB_WINDEX_TEST_K:
case USB_WINDEX_TEST_SE0_NAK:
case USB_WINDEX_TEST_PACKET:
- case USB_WINDEX_TEST_FORCE_ENABLE:
{
XUD_Result_t result;
if((result = XUD_DoSetRequestStatus(ep_in)) != XUD_RES_OKAY)
diff --git a/python/setup.py b/python/setup.py
index 9ed8aa32..f75dc662 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -10,11 +10,12 @@
# least the same minor version as specified in the requirements.txt file.
# The same modules should appear in the requirements.txt file as given below.
setuptools.setup(
- name='lib_xud',
+ name="lib_xud",
packages=setuptools.find_packages(),
install_requires=[
- 'flake8~=3.8',
- ],
- dependency_links=[
+ "black~=21.5b1",
+ "pytest~=6.2",
+ "pytest-xdist~=2.3",
],
+ dependency_links=[],
)
diff --git a/requirements.txt b/requirements.txt
index 99e7dd7b..c60167e7 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -17,7 +17,9 @@
# pip-install this one as editable using this repository's setup.py file. The
# same modules should appear in the setup.py list as given below.
-flake8==3.8.3
+black==21.5b1
+pytest==6.2.4
+pytest-xdist==2.3.0
# Development dependencies
#
diff --git a/tests/Pyxsim/__init__.py b/tests/Pyxsim/__init__.py
new file mode 100644
index 00000000..ceff7eeb
--- /dev/null
+++ b/tests/Pyxsim/__init__.py
@@ -0,0 +1,135 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+"""
+Pyxsim pytest framework
+
+This module provides functions to run tests for XMOS applications and libraries.
+"""
+import sys
+import Pyxsim.pyxsim
+from Pyxsim.xmostest_subprocess import call_get_output
+import platform
+import multiprocessing
+import tempfile
+import re
+import os
+
+clean_only = False
+
+# This function is called automatically by the runners
+def _build(xe_path, build_config=None, env={}, do_clean=False, build_options=[]):
+
+ # Work out the Makefile path
+ path = None
+ m = re.match("(.*)/bin/(.*)", xe_path)
+ if m:
+ path = m.groups(0)[0]
+ binpath = m.groups(0)[1]
+ m = re.match("(.*)/(.*)", binpath)
+ if m:
+ build_config = m.groups(0)[0]
+
+ if not path:
+ msg = "ERROR: Cannot determine path to build: %s\n" % xe_path
+ sys.stderr.write(msg)
+ return (False, msg)
+
+ # Copy the environment, to avoid modifying the env of the current shell
+ my_env = os.environ.copy()
+ for key in env:
+ my_env[key] = str(env[key])
+
+ if clean_only:
+ cmd = ["xmake", "clean"]
+ do_clean = False
+ else:
+ cmd = ["xmake", "all"]
+
+ if do_clean:
+ clean_output = call_get_output(["xmake", "clean"], cwd=path, env=my_env)
+
+ if build_config is not None:
+ cmd += ["CONFIG=%s" % build_config]
+
+ cmd += build_options
+
+ output = call_get_output(cmd, cwd=path, env=my_env, merge_out_and_err=True)
+
+ success = True
+ for x in output:
+ s = str(x)
+ if s.find("Error") != -1:
+ success = False
+ # if re.match('xmake: \*\*\* .* Stop.', x) != None:
+ if re.match(r"xmake: \*\*\* .* Stop.", s) != None:
+ success = False
+
+ if not success:
+ sys.stderr.write("ERROR: build failed.\n")
+ for x in output:
+ s = str(x)
+ sys.stderr.write(s + "\n")
+
+ return (success, output)
+
+
+def do_run_pyxsim(xe, simargs, appargs, simthreads):
+ xsi = pyxsim.Xsi(xe_path=xe, simargs=simargs, appargs=appargs)
+ for x in simthreads:
+ xsi.register_simthread(x)
+ xsi.run()
+ xsi.terminate()
+
+
+def run_with_pyxsim(
+ xe,
+ simthreads,
+ xscope_io=False,
+ loopback=[],
+ simargs=[],
+ appargs=[],
+ suppress_multidrive_messages=False,
+ tester=None,
+ timeout=600,
+ initial_delay=None,
+ start_after_started=[],
+ start_after_completed=[],
+):
+
+ p = multiprocessing.Process(
+ target=do_run_pyxsim, args=(xe, simargs, appargs, simthreads)
+ )
+ p.start()
+ p.join(timeout=timeout)
+ if p.is_alive():
+ sys.stderr.write("Simulator timed out\n")
+ p.terminate()
+ return None
+
+
+def run_tester(caps, tester_list):
+ result = []
+ for i, ele in enumerate(caps):
+ ele.remove("")
+ if tester_list[i] != "Build Failed":
+ result.append(tester_list[i].run(ele))
+ else:
+ result.append(False)
+ return result
+
+
+class SimThread(object):
+ def run(self, xsi):
+ pass
+
+ def wait(self, f):
+ self.xsi._user_wait(f)
+
+ def wait_for_port_pins_change(self, ps):
+ self.xsi._wait_for_port_pins_change(ps)
+
+ def wait_for_next_cycle(self):
+ self.xsi._wait_for_next_cycle()
+
+ def wait_until(self, t):
+ self.xsi._wait_until(t)
diff --git a/tests/Pyxsim/pyxsim.py b/tests/Pyxsim/pyxsim.py
new file mode 100644
index 00000000..e8a15a40
--- /dev/null
+++ b/tests/Pyxsim/pyxsim.py
@@ -0,0 +1,466 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+import os, re, struct
+from ctypes import cdll, byref, c_void_p, c_char_p, c_int, create_string_buffer
+from Pyxsim.xe import Xe
+from Pyxsim.testers import TestError
+import threading
+import traceback
+import Pyxsim
+import sys
+from Pyxsim.xmostest_subprocess import platform_is_windows
+
+ALL_BITS = 0xFFFFFF
+
+if platform_is_windows():
+ xsi_lib_path = os.path.abspath(
+ os.environ["XCC_EXEC_PREFIX"] + "../lib/xsidevice.dll"
+ )
+else:
+ xsi_lib_path = os.path.abspath(
+ os.environ["XCC_EXEC_PREFIX"] + "../lib/libxsidevice.so"
+ )
+
+xsi_lib = cdll.LoadLibrary(xsi_lib_path)
+
+
+def xsi_is_valid_port(port):
+ return re.match(r"XS1_PORT_\d+\w", port) != None
+
+
+def xsi_get_port_width(port):
+ if not xsi_is_valid_port(port):
+ return None
+ else:
+ return int(re.match(r"^XS1_PORT_(\d+)\w", port).groups(0)[0])
+
+
+class EnumExceptionSet:
+ def __init__(self, enum_list, valid_list=[]):
+ self.enum_list = enum_list
+ self.valid_list = valid_list
+
+ def __getattr__(self, name):
+ if name in self.enum_list:
+ return self.enum_list.index(name)
+ raise AttributeErr
+
+ def is_valid(self, value):
+ if value < len(self.enum_list):
+ enum = self.enum_list[value]
+ return enum in self.valid_list
+
+ def error_if_not_valid(self, value):
+ if value < len(self.enum_list):
+ enum = self.enum_list[value]
+ if not enum in self.valid_list:
+ raise type("XSI_ERROR_" + enum, (Exception,), {})
+
+ def error(self, value):
+ if value < len(self.enum_list):
+ enum = self.enum_list[value]
+ raise type("XSI_ERROR_" + enum, (Exception,), {})
+
+
+XsiStatus = EnumExceptionSet(
+ [
+ "OK",
+ "DONE",
+ "TIMEOUT",
+ "INVALID_FILE",
+ "INVALID_INSTANCE",
+ "INVALID_TILE",
+ "INVALID_PACKAGE",
+ "INVALID_PIN",
+ "INVALID_PORT",
+ "MEMORY_ERROR",
+ "PSWITCH_ERROR",
+ "INVALID_ARGS",
+ "NULL_ARG",
+ "INCOMPATIBLE_VERSION",
+ ],
+ valid_list=["OK", "DONE"],
+)
+
+
+def parse_port(p):
+ m = re.match(r"(tile.*)\:([^\.]*)\.?(\d*)", p)
+ if m:
+ tile = m.groups(0)[0]
+ port = m.groups(0)[1]
+ bit = m.groups(0)[2]
+ if bit == "":
+ bit = None
+ if bit != None:
+ bit = int(bit)
+ else:
+ raise TestError("Cannot parse port: %s" % p)
+ if bit != None:
+ mask = 1 << bit
+ else:
+ mask = ALL_BITS
+ return (tile, port, bit, mask)
+
+
+def parse_periph_pin(p):
+ m = re.match("^[^_]+_([^_]+)_([^_]+)", p)
+ if m:
+ perif = m.groups(0)[0]
+ pin = m.groups(0)[1]
+ else:
+ raise TestError("Cannot parse periph pin: %s" % p)
+ mask = ALL_BITS
+ return (perif, pin, mask)
+
+
+class SimThreadImpl(threading.Thread):
+ def __init__(self, xsi, st, args):
+ def _fn(*args):
+ st.run(*args)
+
+ super(SimThreadImpl, self).__init__()
+ self._fn = _fn
+ self._args = args
+ self.get_time = xsi.get_time
+ self.resume_event = threading.Event()
+ self.complete_event = threading.Event()
+ self._xsi = xsi
+ self.had_exception = False
+ self.terminate_flag = False
+ st.xsi = self
+
+ def _wait(self, resume_check):
+ self.resume_condition = resume_check
+ self.complete_event.set()
+ self.resume_event.wait()
+ self.resume_event.clear()
+
+ def _user_wait(self, resume_check):
+ def _resume(xsi):
+ return resume_check(self)
+
+ self._wait(_resume)
+
+ def _wait_until(self, time):
+ def _resume(xsi):
+ return xsi.get_time() >= time
+
+ self._wait(_resume)
+
+ def _wait_for_port_pins_change(self, ps):
+ is_driving = []
+ vals = []
+ ps = [(self._xsi.xe.get_port_pins(p)[0], parse_port(p)) for p in ps]
+ for ((package, pin, _), (tile, p, bit, mask)) in ps:
+ d = self._xsi.is_pin_driving(package, pin)
+ is_driving.append(d)
+ if d:
+ v = self._xsi.sample_port_pins(tile, p, mask)
+ if bit:
+ v = v >> bit
+ vals.append(v)
+ else:
+ vals.append(0)
+
+ def _resume(xsi):
+ for i, psval in enumerate(ps):
+ (package, pin, _), (tile, p, bit, mask) = psval
+ d = xsi.is_pin_driving(package, pin)
+ if d != is_driving[i]:
+ return True
+ if d:
+ v = xsi.sample_port_pins(tile, p, mask)
+ if bit:
+ v = v >> bit
+ else:
+ v = 0
+ if v != vals[i]:
+ return True
+ return False
+
+ self._wait(_resume)
+
+ def _wait_for_next_cycle(self):
+ self._wait(lambda x: True)
+
+ def is_port_driving(self, port):
+ (package, pin, _) = self._xsi.xe.get_port_pins(port)[0]
+ return self._xsi.is_pin_driving(package, pin)
+
+ def drive_port_pins(self, port, val):
+ (tile, p, bit, mask) = parse_port(port)
+ if bit:
+ val <<= bit
+ self._xsi.drive_port_pins(tile, p, mask, val)
+
+ def sample_port_pins(self, port):
+ (tile, p, bit, mask) = parse_port(port)
+ val = self._xsi.sample_port_pins(tile, p, mask)
+ if bit:
+ val >>= bit
+ return val
+
+ # TODO make this pin*s*
+ def drive_periph_pin(self, pin, val):
+ (periph, pin, mask) = parse_periph_pin(pin)
+ self._xsi.drive_periph_pin(periph, pin, mask, val)
+
+ # TODO make this pin*s*
+ def sample_periph_pin(self, pin):
+ (periph, pin, mask) = parse_periph_pin(pin)
+ return self._xsi.sample_periph_pin(periph, pin, mask)
+
+ def terminate(self):
+ self.terminate_flag = True
+ self._wait(lambda x: False)
+
+ def run(self):
+ args = self._args
+ try:
+ self._fn(*args)
+ except:
+ self.had_exception = True
+ sys.stderr.write("---------Exception in simthread--------------\n")
+ traceback.print_exc()
+ sys.stderr.write("---------------------------------------------\n")
+ self.resume_condition = lambda x: False
+ self.complete_event.set()
+
+
+class Xsi(object):
+ def __init__(self, xe_path=None, simargs=[], appargs=[]):
+ self.xsim = c_void_p()
+ self.xe_path = xe_path
+ args = " ".join(
+ ['"{}"'.format(x) for x in (simargs + [self.xe_path] + appargs)]
+ )
+ if platform_is_windows:
+ args = args.replace("\\", "/")
+ c_args = c_char_p(args.encode("utf-8"))
+ status = xsi_lib.xsi_create(byref(self.xsim), c_args)
+ self._plugins = []
+ self._simthreads = []
+ self._time = 0
+
+ def register_plugin(self, plugin):
+ self._plugins.append(plugin)
+
+ def register_simthread(self, fn):
+ if isinstance(fn, tuple):
+ xs = list(fn)
+ fn = xs[0]
+ args = xs[1:]
+ else:
+ args = []
+
+ simthread = SimThreadImpl(self, fn, args)
+ simthread.daemon = True
+ self._simthreads.append(simthread)
+
+ def wait_for_simthread(self, simthread):
+ simthread.complete_event.wait()
+ simthread.complete_event.clear()
+ if simthread.had_exception:
+ raise TestError("Simthread encoutered an exception")
+
+ def clock(self):
+ status = xsi_lib.xsi_clock(self.xsim)
+ self._time += self._time_step
+ if XsiStatus.is_valid(status):
+ for plugin in self._plugins:
+ plugin.clock(self)
+ for simthread in self._simthreads:
+ if simthread.resume_condition(self):
+ simthread.resume_event.set()
+ self.wait_for_simthread(simthread)
+ if simthread.terminate_flag:
+ return XsiStatus.DONE
+
+ return status
+
+ def get_time(self):
+ return self._time
+
+ def run(self):
+ self.xe = Xe(self.xe_path)
+ self._time_step = 1000.0 / self.xe.freq
+ status = XsiStatus.OK
+ for simthread in self._simthreads:
+ simthread.start()
+ self.wait_for_simthread(simthread)
+
+ while status != XsiStatus.DONE:
+ status = self.clock()
+ XsiStatus.error_if_not_valid(status)
+
+ def terminate(self):
+ status = xsi_lib.xsi_terminate(self.xsim)
+ XsiStatus.error_if_not_valid(status)
+
+ def sample_pin(self, package, pin):
+ c_package = c_char_p(package)
+ c_pin = c_char_p(pin)
+ c_value = c_int()
+ status = xsi_lib.xsi_sample_pin(self.xsim, c_package, c_pin, byref(c_value))
+ XsiStatus.error_if_not_valid(status)
+ return c_value.value
+
+ def sample_port_pins(self, tile, port, mask):
+ c_tile = c_char_p(tile.encode("utf-8"))
+ c_port = c_char_p(port.encode("utf-8"))
+ c_mask = c_int(mask)
+ c_value = c_int()
+ status = xsi_lib.xsi_sample_port_pins(
+ self.xsim, c_tile, c_port, c_mask, byref(c_value)
+ )
+ XsiStatus.error_if_not_valid(status)
+ return c_value.value
+
+ def drive_pin(self, package, pin, value):
+ c_package = c_char_p(package)
+ c_pin = c_char_p(pin)
+ c_value = c_int(value)
+ status = xsi_lib.xsi_drive_pin(self.xsim, c_package, c_pin, c_value)
+ XsiStatus.error_if_not_valid(status)
+
+ def drive_port_pins(self, tile, port, mask, value):
+ c_tile = c_char_p(tile.encode("utf-8"))
+ c_port = c_char_p(port.encode("utf-8"))
+ c_mask = c_int(mask)
+ c_value = c_int(value)
+ status = xsi_lib.xsi_drive_port_pins(self.xsim, c_tile, c_port, c_mask, c_value)
+ XsiStatus.error_if_not_valid(status)
+
+ # TOOD make this pin*s*
+ def drive_periph_pin(self, periph, pin, mask, value):
+ c_periph = c_char_p(periph.encode("utf-8"))
+ c_pin = c_char_p(pin.encode("utf-8"))
+ c_mask = c_int(mask)
+ c_value = c_int(value)
+ status = xsi_lib.xsi_drive_periph_pin(
+ self.xsim, c_periph, c_pin, c_mask, c_value
+ )
+ XsiStatus.error_if_not_valid(status)
+
+ # TOOD make this pin*s*
+ def sample_periph_pin(self, periph, pin, mask):
+ c_periph = c_char_p(periph.encode("utf-8"))
+ c_pin = c_char_p(pin.encode("utf-8"))
+ c_mask = c_int(mask)
+ c_value = c_int()
+ status = xsi_lib.xsi_sample_periph_pin(
+ self.xsim, c_periph, c_pin, c_mask, byref(c_value)
+ )
+ XsiStatus.error_if_not_valid(status)
+ return c_value.value
+
+ def is_pin_driving(self, package, pin):
+ c_package = c_char_p(package)
+ c_pin = c_char_p(pin)
+ c_value = c_int()
+ status = xsi_lib.xsi_is_pin_driving(self.xsim, c_package, c_pin, byref(c_value))
+ XsiStatus.error_if_not_valid(status)
+ return c_value.value
+
+ def is_port_pins_driving(self, tile, port):
+ c_tile = c_char_p(tile)
+ c_port = c_char_p(port)
+ c_value = c_int()
+ status = xsi_lib.xsi_is_port_pins_driving(
+ self.xsim, c_tile, c_port, byref(c_value)
+ )
+ XsiStatus.error_if_not_valid(status)
+ return c_value.value
+
+ def read_mem(self, tile, address, num_bytes, return_ctype=False):
+ c_tile = c_char_p(tile)
+ c_address = c_int(address)
+ c_num_bytes = c_int(num_bytes)
+ buf = create_string_buffer(num_bytes)
+ status = xsi_lib.xsi_read_mem(self.xsim, c_tile, c_address, c_num_bytes, buf)
+ XsiStatus.error_if_not_valid(status)
+ if return_ctype:
+ return buf
+ else:
+ return list(buf)
+
+ def read_symbol_word(self, tile, symbol, offset=0):
+ address = self.xe.symtab[tile, symbol]
+ address += offset
+ buf = self.read_mem(tile, address, 4, return_ctype=True)
+ return struct.unpack("= num_expected:
+ self.record_failure("Length of expected output less than output")
+ break
+
+ if self._ordered:
+ if regexp:
+ match = re.match(expected[line_num] + "$", output[i].strip())
+ else:
+ match = expected[line_num] == output[i].strip()
+
+ if not match:
+ self.record_failure(
+ (
+ "Line %d of output does not match expected\n"
+ + " Expected: %s\n"
+ + " Actual : %s"
+ )
+ % (line_num, expected[line_num].strip(), output[i].strip())
+ )
+ else: # Unordered testing
+ stripped = output[i].strip()
+ if regexp:
+ match = any(re.match(e + "$", stripped) for e in expected)
+ else:
+ match = any(e == stripped for e in expected)
+
+ if not match:
+ self.record_failure(
+ ("Line %d of output not found in expected\n" + " Actual : %s")
+ % (line_num, output[i].strip())
+ )
+
+ if num_expected > line_num + 1:
+ self.record_failure(
+ "Length of expected output greater than output\nMissing:\n"
+ + "\n".join(expected[line_num + 1 :])
+ )
+ output = {"output": "".join(output)}
+
+ if not self.result:
+ output["failures"] = "".join(self.failures)
+
+ if self.result:
+ sys.stdout.write(
+ "%-30s %-6s %-6s Pass\n"
+ % (test, config.get("arch"), config.get("speed"))
+ )
+ else:
+ sys.stderr.write(
+ "%-30s %-6s %-6s Fail\n"
+ % (test, config.get("arch"), config.get("speed"))
+ )
+
+ return self.result
diff --git a/tests/Pyxsim/xe.py b/tests/Pyxsim/xe.py
new file mode 100644
index 00000000..1a3dc866
--- /dev/null
+++ b/tests/Pyxsim/xe.py
@@ -0,0 +1,101 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from Pyxsim.xmostest_subprocess import call, call_get_output
+from Pyxsim.testers import TestError
+import os, tempfile
+from xml.dom.minidom import parse
+import re
+from fractions import gcd
+
+
+def lcm(a, b):
+ return (a * b) // gcd(a, b)
+
+
+class Xe:
+ def _get_platform_info(self):
+ call(["xobjdump", "--split", self.path], silent=True, cwd=self._tempdir)
+ xn = parse("%s/platform_def.xn" % self._tempdir)
+ self._tile_map = {}
+ self.tiles = []
+ lcm_freq = 1
+ for node in xn.getElementsByTagName("Node"):
+ freq = node.getAttribute("SystemFrequency")
+ if freq:
+ freq = int(freq.replace("MHz", ""))
+ lcm_freq = lcm(lcm_freq, freq)
+ cm = {}
+ for tile in node.getElementsByTagName("Tile"):
+ self._tile_map[
+ node.getAttribute("Id"), tile.getAttribute("Number")
+ ] = tile.getAttribute("Reference")
+ self.tiles.append(tile.getAttribute("Reference"))
+ self.freq = lcm_freq
+
+ config = parse("%s/config.xml" % self._tempdir)
+ self._port_map = {}
+ for pin_node in config.getElementsByTagName("Pin"):
+ name = pin_node.getAttribute("name")
+ (package, pin) = name.split(":")
+ for port_node in pin_node.getElementsByTagName("Port"):
+ port = "tile[%s]:%s" % (
+ port_node.getAttribute("core"),
+ port_node.getAttribute("name"),
+ )
+ bitnum = int(port_node.getAttribute("bitNum"))
+ if not port in self._port_map:
+ self._port_map[port] = []
+ self._port_map[port].append((package, pin, bitnum))
+
+ def get_port_pins(self, port):
+ m = re.match(r"([^\.]*)\.(\d*)", port)
+ if m:
+ port = m.groups(0)[0]
+ bit = int(m.groups(0)[1])
+ pins = self._port_map[port]
+ for (package, pin, bitnum) in pins:
+ if bitnum == bit:
+ return [(package, pin, bitnum)]
+ raise TestError("Cannot find port pins")
+ else:
+ return self._port_map[port]
+
+ def _get_symtab(self):
+ stdout, stderr = call_get_output(["xobjdump", "-t", self.path])
+ current_tile = None
+ symtab = {}
+ for line in stdout:
+ line = str(line)
+ if line == "":
+ break
+ m = re.match(r"Loadable.*for (.*) \(node \"(\d*)\", tile (\d*)", line)
+
+ if m:
+ current_tile = m.groups(0)[0]
+ m = re.match(r"(0x[0-9a-fA-F]*).....([^ ]*) *(0x[0-9a-fA-F]*) (.*)$", line)
+ if m and current_tile != None:
+ (address, section, size, name) = m.groups(0)
+ if section != "*ABS*":
+ address = int(address, 0)
+ symtab[current_tile, name] = address
+ self.symtab = symtab
+
+ def __init__(self, path):
+ if not os.path.isfile(path):
+ raise IOError("Cannot find file: %s" % path)
+ self.path = os.path.abspath(path)
+ self._symtab = {}
+ self._tempdir = tempfile.mkdtemp()
+ self._get_platform_info()
+ self._get_symtab()
+
+ def __del__(self):
+ if self._tempdir != None:
+ for root, dirs, files in os.walk(self._tempdir, topdown=False):
+ for f in files:
+ p = os.path.join(root, f)
+ os.remove(p)
+ for d in dirs:
+ p = os.path.join(root, d)
+ os.rmdir(p)
+ os.rmdir(self._tempdir)
diff --git a/tests/Pyxsim/xmostest_subprocess.py b/tests/Pyxsim/xmostest_subprocess.py
new file mode 100644
index 00000000..110b3981
--- /dev/null
+++ b/tests/Pyxsim/xmostest_subprocess.py
@@ -0,0 +1,273 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+import platform
+import re
+import subprocess
+import sys
+import tempfile
+import multiprocessing
+import time
+import os
+import signal
+import errno
+from Pyxsim.testers import TestError
+
+
+def pstreekill(process):
+ pid = process.pid
+ if platform_is_windows():
+ # Try allowing a clean shutdown first
+ subprocess.call(["taskkill", "/t", "/pid", str(pid)])
+ confirmed_termination = False
+ timeout = time.time() + 10 # Timeout in seconds
+ while time.time() < timeout:
+ # Check the current status of the process
+ status = subprocess.call(["tasklist", "/nh", "/fi", '"PID eq %s"' % pid])
+ if status.startswith(
+ "INFO: No tasks are running which match the specified criteria"
+ ):
+ # Process has shutdown
+ confirmed_termination = True
+ break
+ time.sleep(0.1) # Avoid spinning too fast while in the timeout loop
+ if not confirmed_termination:
+ # If the process hasn't shutdown politely yet kill it
+ sys.stdout.write("Force kill PID %d that hasn't responded to kill\n" % pid)
+ subprocess.call(["taskkill", "/t", "/f", "/pid", str(pid)])
+ else:
+ # Send SIGINT to the process group to notify all processes that we
+ # are going down now
+ os.killpg(os.getpgid(pid), signal.SIGINT)
+
+ # Now terminate and join the main process. If the join has not returned
+ # within 10 seconds then we will have to forcibly kill the process group
+ process.terminate()
+ process.join(timeout=10)
+
+ if process.is_alive():
+ # If the process hasn't shutdown politely yet kill it
+ try:
+ sys.stderr.write(
+ "Sending SIGKILL to PID %d that hasn't responded to SIGINT\n" % pid
+ )
+ os.killpg(os.getpgid(pid), signal.SIGKILL)
+ except OSError as err:
+ # ESRCH == No such process - presumably exited since timeout...
+ if err.errno != errno.ESRCH:
+ raise
+
+
+## Annoying OS incompatability, not sure why this is needed
+
+
+def log_debug(msg):
+ pass
+
+
+def platform_is_osx():
+ ostype = platform.system()
+ if re.match(".*Darwin.*", ostype):
+ return True
+ else:
+ return False
+
+
+def platform_is_windows():
+ ostype = platform.system()
+ if not re.match(".*Darwin.*", ostype) and re.match(".*[W|w]in.*", ostype):
+ return True
+ else:
+ return False
+
+
+if platform_is_windows():
+ concat_args = True
+ use_shell = True
+ # Windows version of Python 2.7 doesn't support SIGINT
+ if sys.version_info < (3, 0):
+ raise TestError(
+ "Doesn't support Python version < 3, please upgrade to Python 3 or higher."
+ )
+ SIGINT = signal.SIGTERM
+else:
+ concat_args = False
+ use_shell = False
+ SIGINT = signal.SIGINT
+
+
+def quote_string(s):
+ """For Windows need to put quotes around arguments with spaces in them"""
+ if re.search(r"\s", s):
+ return '"%s"' % s
+ else:
+ return s
+
+
+def Popen(*args, **kwargs):
+ kwargs["shell"] = use_shell
+ if concat_args:
+ args = (" ".join([quote_string(arg) for arg in args[0]]),) + args[1:]
+ cmd = args[0]
+ else:
+ cmd = " ".join(args[0])
+
+ log_debug("Run '%s' in %s" % (cmd, kwargs.get("cwd", ".")))
+ return subprocess.Popen(*args, **kwargs)
+
+
+def wait_with_timeout(p_and_sig, timeout):
+ (ev, pidv, process) = p_and_sig
+ process.start()
+ try:
+ if timeout:
+ finished = ev.wait(timeout)
+ if not finished:
+ pstreekill(process)
+ return (not finished, 0)
+ else:
+ ev.wait()
+ return (False, 0)
+ except KeyboardInterrupt:
+ pstreekill(process)
+
+ return (False, 0)
+
+
+def do_cmd(ev, pidv, *args, **kwargs):
+ if not platform_is_windows():
+ os.setpgid(os.getpid(), 0)
+ if "stdout_fname" in kwargs:
+ fname = kwargs.pop("stdout_fname")
+ kwargs["stdout"] = open(fname, "w")
+ if "stderr_fname" in kwargs:
+ fname = kwargs.pop("stderr_fname")
+ kwargs["stderr"] = open(fname, "w")
+ process = Popen(*args, **kwargs)
+ pidv.value = process.pid
+ try:
+ process.wait()
+ except KeyboardInterrupt:
+ # Catch the KeyboardInterrupt raised due to the SIGINT signal
+ # sent by pstreekill()
+ pass
+ ev.set()
+
+
+def create_cmd_process(*args, **kwargs):
+ ev = multiprocessing.Event()
+ pidv = multiprocessing.Value("d", 0)
+ args = tuple([ev, pidv] + list(args))
+ process = multiprocessing.Process(target=do_cmd, args=args, kwargs=kwargs)
+
+ return (ev, pidv, process)
+
+
+def remove(name):
+ """On windows, OS.remove() will cause an exception if the file is still in use.
+ It is assumed there is a release race, hence the multiple attempts here.
+ """
+ attempt = 0
+ while attempt < 3:
+ try:
+ os.remove(name)
+ return
+ except OSError:
+ attempt = attempt + 1
+ time.sleep(0.1 * attempt)
+ sys.stdout.write("ERROR: Unable to remove file `%s`\n" % name)
+
+
+def call(*args, **kwargs):
+ """If silent, then create temporary files to pass stdout and stderr to since
+ on Windows the less/more-like behaviour waits for a keypress if it goes to stdout.
+ """
+ silent = kwargs.pop("silent", False)
+ retval = 0
+ timeout = None
+ if "timeout" in kwargs:
+ timeout = kwargs["timeout"]
+ kwargs.pop("timeout")
+
+ if silent:
+ out = tempfile.NamedTemporaryFile(delete=False)
+ kwargs["stdout_fname"] = out.name
+ kwargs["stderr"] = subprocess.STDOUT
+
+ process = create_cmd_process(*args, **kwargs)
+ (timed_out, retval) = wait_with_timeout(process, timeout)
+ out.seek(0)
+ stdout_lines = out.readlines()
+ out.close()
+ remove(out.name)
+ for line in stdout_lines:
+ line = line.decode("utf-8")
+ log_debug(" " + line.rstrip())
+ else:
+ process = create_cmd_process(*args, **kwargs)
+ (timed_out, retval) = wait_with_timeout(process, timeout)
+ # Ensure spawned processes are not left running past this point
+ # There should be no children running now (as they would be orphaned)
+ process[2].terminate()
+ process[2].join(timeout=0.1) # Avoid always printing wait message
+ while process[2].is_alive():
+ sys.stdout.write("Waiting for PID %d to terminate\n" % process[2].pid)
+ process[2].join(timeout=1.0)
+
+ if timeout:
+ return (timed_out, retval)
+ else:
+ return retval
+
+
+def call_get_output(*args, **kwargs):
+ """Create temporary files to pass stdout and stderr to since on Windows the
+ less/more-like behaviour waits for a keypress if it goes to stdout.
+ """
+ merge = kwargs.pop("merge_out_and_err", False)
+
+ out = tempfile.NamedTemporaryFile(delete=False)
+ kwargs["stdout_fname"] = out.name
+ timeout = None
+ if "timeout" in kwargs:
+ timeout = kwargs["timeout"]
+ kwargs.pop("timeout")
+
+ if merge:
+ kwargs["stderr"] = subprocess.STDOUT
+ else:
+ err = tempfile.NamedTemporaryFile(delete=False)
+ stderr_fname = err.name
+ kwargs["stderr_fname"] = stderr_fname
+ err.close()
+
+ process = create_cmd_process(*args, **kwargs)
+ (timed_out, retval) = wait_with_timeout(process, timeout)
+ out.seek(0)
+ stdout_lines = out.readlines()
+ out.close()
+ remove(out.name)
+
+ for line in stdout_lines:
+ line = line.decode("utf-8")
+ log_debug(" " + line.rstrip())
+
+ if not merge:
+ err = open(stderr_fname, "r")
+ stderr_lines = err.readlines()
+ err.close()
+ remove(stderr_fname)
+ for line in stderr_lines:
+ line = line.decode("utf-8")
+ log_debug(" err:" + line.rstrip())
+
+ if merge:
+ if timeout:
+ return (timed_out, stdout_lines)
+ else:
+ return stdout_lines
+
+ else:
+ if timeout:
+ return (timed_out, stdout_lines, stderr_lines)
+ else:
+ return (stdout_lines, stderr_lines)
diff --git a/tests/README.rst b/tests/README.rst
new file mode 100644
index 00000000..969a35b6
--- /dev/null
+++ b/tests/README.rst
@@ -0,0 +1,12 @@
+
+Lib_xud Tests
+=============
+
+Installation and prerequiste for running pytest
+pip install pytest
+
+To run all tests, simply type:
+pytest -s
+
+To run specific test, type:
+pytest .py
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 00000000..b573ee52
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,225 @@
+# Copyright 2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+import pytest
+import os
+import random
+import sys
+import Pyxsim
+from Pyxsim import testers
+from helpers import get_usb_clk_phy, do_usb_test
+from pathlib import Path
+import shutil
+
+# Note, no current support for XS2 so don't copy XS2 xn files
+XN_FILES = ["test_xs3_600.xn", "test_xs3_800.xn"]
+
+PARAMS = {
+ "extended": {
+ "arch": ["xs3"],
+ "ep": [1, 2, 4],
+ "address": [0, 1, 127],
+ "bus_speed": ["HS", "FS"],
+ "dummy_threads": [0, 5, 6],
+ "core_freq": [600, 800],
+ },
+ "default": {
+ "arch": ["xs3"],
+ "ep": [1, 2],
+ "address": [0, 1],
+ "bus_speed": ["HS", "FS"],
+ "dummy_threads": [0, 6],
+ "core_freq": [600],
+ },
+ "smoke": {
+ "arch": ["xs3"],
+ "ep": [1],
+ "address": [1],
+ "bus_speed": ["HS"],
+ "dummy_threads": [6],
+ "core_freq": [600],
+ },
+}
+
+
+def pytest_addoption(parser):
+ parser.addoption("--smoke", action="store_true", help="Smoke test")
+ parser.addoption("--extended", action="store_true", help="Extended test")
+ parser.addoption(
+ "--enabletracing",
+ action="store_true",
+ default=False,
+ help="Run tests with tracing",
+ )
+
+
+def pytest_configure(config):
+ os.environ["enabletracing"] = str(config.getoption("enabletracing"))
+
+
+# TODO: this is deprecated, find a better way
+def pytest_cmdline_preparse(config, args):
+ if "--smoke" in args and "--extended" in args:
+ raise pytest.UsageError('Only one of "--smoke" and "--extended" can be used')
+
+
+def pytest_generate_tests(metafunc):
+ try:
+ PARAMS = metafunc.module.PARAMS
+ if metafunc.config.getoption("smoke"):
+ params = PARAMS.get("smoke", PARAMS["default"])
+ elif metafunc.config.getoption("extended"):
+ params = PARAMS.get("extended", PARAMS["default"])
+ else:
+ params = PARAMS["default"]
+ except AttributeError:
+ params = {}
+
+ for name, values in params.items():
+ if name in metafunc.fixturenames:
+ metafunc.parametrize(name, values)
+
+
+@pytest.fixture()
+def test_ep(ep: int) -> int:
+ return ep
+
+
+@pytest.fixture()
+def test_address(address: int) -> int:
+ return address
+
+
+@pytest.fixture()
+def test_bus_speed(bus_speed: str) -> str:
+ return bus_speed
+
+
+@pytest.fixture()
+def test_arch(arch: str) -> str:
+ return arch
+
+
+@pytest.fixture
+def test_file(request):
+ return str(request.node.fspath)
+
+
+@pytest.fixture()
+def test_dummy_threads(dummy_threads: int) -> int:
+ return dummy_threads
+
+
+def test_RunUsbSession(
+ test_session,
+ arch,
+ ep,
+ address,
+ bus_speed,
+ dummy_threads,
+ core_freq,
+ test_file,
+ capfd,
+):
+
+ tester_list = []
+ output = []
+ testname, extension = os.path.splitext(os.path.basename(__file__))
+ seed = random.randint(0, sys.maxsize)
+
+ # TODO it would be good to sanity check core_freq == xe.freq
+ (clk_60, usb_phy) = get_usb_clk_phy(core_freq, verbose=False, arch=arch)
+ tester_list.extend(
+ do_usb_test(
+ arch,
+ ep,
+ address,
+ bus_speed,
+ dummy_threads,
+ core_freq,
+ clk_60,
+ usb_phy,
+ [test_session],
+ test_file,
+ seed,
+ )
+ )
+ cap_output, err = capfd.readouterr()
+ output.append(cap_output.split("\n"))
+
+ sys.stdout.write("\n")
+ results = Pyxsim.run_tester(output, tester_list)
+
+ # TODO only one result
+ for result in results:
+ if not result:
+ print(cap_output)
+ sys.stderr.write(err)
+ assert result
+
+
+def copy_common_xn_files(
+ test_dir, path=".", common_dir="shared_src", source_dir="src", xn_files=XN_FILES
+):
+ src_dir = os.path.join(test_dir, source_dir)
+ for xn_file in xn_files:
+ xn = os.path.join(common_dir, xn_file)
+ shutil.copy(xn, src_dir)
+
+
+def delete_test_specific_xn_files(
+ test_dir, path=".", source_dir="src", xn_files=XN_FILES
+):
+ src_dir = os.path.join(test_dir, source_dir)
+ for xn_file in xn_files:
+ xn = os.path.join(src_dir, xn_file)
+
+ try:
+ os.remove(xn)
+ except OSError:
+ pass
+
+
+@pytest.fixture(scope="session", autouse=True)
+def worker_id(request):
+ if hasattr(request.config, "slaveinput"):
+ return request.config.slaveinput["slaveid"]
+ else:
+ # Master means not executing with multiple workers
+ return "master"
+
+
+# Runs after all tests are collected, but before all tests are run
+# Note, there is one session per process, so this runs once per process...
+@pytest.fixture(scope="session", autouse=True)
+def copy_xn_files(worker_id, request):
+
+ # Attempt to only run copy/delete once..
+ if worker_id == "master" or worker_id == "gw0":
+
+ session = request.node
+
+ # There will be duplicates (same test name with different params) so treat as set
+ test_dirs = set([])
+
+ # Go through collected tests and copy over XN files
+ for item in session.items:
+ full_path = item.fspath
+ test_dir = Path(full_path).with_suffix("") # Strip suffix
+ test_dir = os.path.basename(test_dir) # Strip path leaving filename
+ test_dirs.add(test_dir)
+
+ for test_dir in test_dirs:
+ copy_common_xn_files(test_dir)
+
+ def delete_xn_files():
+
+ # Run deletion on one process only
+ if worker_id == "master" or worker_id == "gw0":
+
+ # Go through collected tests deleting XN files
+ for test_dir in test_dirs:
+ delete_test_specific_xn_files(test_dir)
+
+ # Setup tear down
+ # Deletion removed for now - doesn't seem important
+ # request.addfinalizer(delete_xn_files)
diff --git a/tests/helpers.py b/tests/helpers.py
index dddd0794..501a371a 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -1,193 +1,253 @@
#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-import xmostest
+import Pyxsim
+from Pyxsim import testers
import os
import random
import sys
from usb_clock import Clock
from usb_phy import UsbPhy
-from usb_packet import RxPacket
+from usb_phy_shim import UsbPhyShim
+from usb_phy_utmi import UsbPhyUtmi
+from usb_packet import RxPacket, USB_DATA_VALID_COUNT
+
+ARCHITECTURE_CHOICES = ["xs2", "xs3"]
+BUSSPEED_CHOICES = ["FS", "HS"]
+args = {"arch": "xs3"}
+clean_only = False
-args = None
def create_if_needed(folder):
if not os.path.exists(folder):
os.makedirs(folder)
return folder
-def get_usb_clk_phy(verbose=True, test_ctrl=None, do_timeout=True,
- complete_fn=None, expect_loopback=False,
- dut_exit_time=350000, initial_del=40000, arch='xs2'):
-
- if arch=='xs2':
- clk = Clock('tile[0]:XS1_PORT_1J', Clock.CLK_60MHz)
- phy = UsbPhy('tile[0]:XS1_PORT_8B',
- 'tile[0]:XS1_PORT_1F', #rxa
- 'tile[0]:XS1_PORT_1I', #rxv
- 'tile[0]:XS1_PORT_1G', #rxe
- 'tile[0]:XS1_PORT_1E', #vld
- 'tile[0]:XS1_PORT_8A', #txd
- 'tile[0]:XS1_PORT_1K', #txv
- 'tile[0]:XS1_PORT_1H', #txrdy
- clk,
- verbose=verbose, test_ctrl=test_ctrl,
- do_timeout=do_timeout, complete_fn=complete_fn,
- expect_loopback=expect_loopback,
- dut_exit_time=dut_exit_time, initial_delay=initial_del)
-
- if arch=='xs1':
- clk = Clock('tile[0]:XS1_PORT_1J', Clock.CLK_60MHz)
- phy = UsbPhy('tile[0]:XS1_PORT_8C',
- 'tile[0]:XS1_PORT_1O', #rxa
- 'tile[0]:XS1_PORT_1M', #rxv
- 'tile[0]:XS1_PORT_1P', #rxe
- 'tile[0]:XS1_PORT_1N', #vld
- 'tile[0]:XS1_PORT_8A', #txd
- 'tile[0]:XS1_PORT_1K', #txv
- 'tile[0]:XS1_PORT_1H', #txrdy
- clk,
- verbose=verbose, test_ctrl=test_ctrl,
- do_timeout=do_timeout, complete_fn=complete_fn,
- expect_loopback=expect_loopback,
- dut_exit_time=dut_exit_time, initial_delay=initial_del)
-
+
+def get_usb_clk_phy(
+ coreFreqMhz,
+ verbose=True,
+ do_timeout=True,
+ complete_fn=None,
+ dut_exit_time=350000,
+ arch="xs2",
+):
+
+ if arch == "xs2":
+ clk = Clock("XS1_USB_CLK", Clock.CLK_60MHz, coreFreqMhz)
+ phy = UsbPhyUtmi(
+ "XS1_USB_RXD",
+ "XS1_USB_RXA", # rxa
+ "XS1_USB_RXV", # rxv
+ "XS1_USB_RXE", # rxe
+ "tile[0]:XS1_PORT_8A", # txd
+ "tile[0]:XS1_PORT_1K", # txv
+ "tile[0]:XS1_PORT_1H", # txrdy
+ "XS1_USB_LS",
+ "XS1_USB_XCVRSEL",
+ "XS1_USB_TERMSEL",
+ clk,
+ verbose=verbose,
+ do_timeout=do_timeout,
+ complete_fn=complete_fn,
+ dut_exit_time=dut_exit_time,
+ )
+
+ elif arch == "xs3":
+ clk = Clock("XS1_USB_CLK", Clock.CLK_60MHz, coreFreqMhz)
+ phy = UsbPhyUtmi(
+ "XS1_USB_RXD",
+ "XS1_USB_RXA", # rxa
+ "XS1_USB_RXV", # rxv
+ "XS1_USB_RXE", # rxe
+ "tile[0]:XS1_PORT_8A", # txd
+ "tile[0]:XS1_PORT_1K", # txv
+ "tile[0]:XS1_PORT_1H", # txrdy
+ "XS1_USB_LS",
+ "XS1_USB_XCVRSEL",
+ "XS1_USB_TERMSEL",
+ clk,
+ verbose=verbose,
+ do_timeout=do_timeout,
+ complete_fn=complete_fn,
+ dut_exit_time=dut_exit_time,
+ )
+
+ else:
+ raise ValueError("Invalid architecture: " + arch)
+
return (clk, phy)
+
+def run_on_simulator(xe, simthreads, **kwargs):
+ for k in ["do_xe_prebuild", "build_env", "clean_before_build"]:
+ if k in kwargs:
+ kwargs.pop(k)
+ return Pyxsim.run_with_pyxsim(xe, simthreads, **kwargs)
+
+
def run_on(**kwargs):
- if not args:
- return True
- for name,value in kwargs.iteritems():
- arg_value = getattr(args,name)
+ for name, value in kwargs.items():
+ arg_value = args.get(name)
if arg_value is not None and value != arg_value:
return False
return True
-def runall_rx(test_fn):
-
-
- if run_on(arch='xs1'):
- (tx_clk_60, usb_phy) = get_usb_clk_phy(verbose=False, arch='xs1')
- seed = args.seed if args.seed else random.randint(0, sys.maxint)
- test_fn('xs1', tx_clk_60, usb_phy, seed)
-
- if run_on(arch='xs2'):
- (tx_clk_60, usb_phy) = get_usb_clk_phy(verbose=False, arch='xs2')
- seed = args.seed if args.seed else random.randint(0, sys.maxint)
- test_fn('xs2', tx_clk_60, usb_phy, seed)
-
-def do_rx_test(arch, tx_clk, tx_phy, packets, test_file, seed,
- level='nightly', extra_tasks=[]):
+FIXTURE_TO_DEFINE = {
+ "core_freq": "TEST_FREQ",
+ "arch": "TEST_ARCH",
+ "dummy_threads": "TEST_DTHREADS",
+ "ep": "TEST_EP_NUM",
+ "address": "XUD_STARTUP_ADDRESS",
+}
+
+
+def do_usb_test(
+ arch,
+ ep,
+ address,
+ bus_speed,
+ dummy_threads,
+ core_freq,
+ clk,
+ phy,
+ sessions,
+ test_file,
+ seed,
+ level="nightly",
+ extra_tasks=[],
+ verbose=False,
+):
+ build_options = []
+
+ # Flags for makefile
+ for k, v in FIXTURE_TO_DEFINE.items():
+ build_options += [str(v) + "=" + str(locals()[k])]
+
+ # Defines for DUT code
+ # TODO shoud the makefile set thease based on the above?
+ build_options_str = "CFLAGS="
+ for k, v in FIXTURE_TO_DEFINE.items():
+ build_options_str += "-D" + str(v) + "=" + str(locals()[k]) + " "
+
+ build_options = build_options + [build_options_str]
+
+ """Shared test code for all RX tests using the test_rx application."""
+ testname, extension = os.path.splitext(os.path.basename(test_file))
+ tester_list = []
+
+ binary = "{testname}/bin/{arch}_{core_freq}_{dummy_threads}_{ep}_{address}/{testname}_{arch}_{core_freq}_{dummy_threads}_{ep}_{address}.xe".format(
+ testname=testname,
+ arch=arch,
+ core_freq=core_freq,
+ dummy_threads=dummy_threads,
+ ep=ep,
+ address=address,
+ )
+
+ # Do not need to clean since different build will different params go to separate binaries
+ build_success, build_output = Pyxsim._build(
+ binary, do_clean=False, build_options=build_options
+ )
+
+ assert len(sessions) == 1, "Multiple sessions not yet supported"
+ if build_success:
+ for session in sessions:
+
+ phy.session = session
+
+ expect_folder = create_if_needed("expect")
+ expect_filename = "{folder}/{test}_{arch}_{usb_speed}.expect".format(
+ folder=expect_folder,
+ test=testname,
+ phy=phy.name,
+ clk=clk.get_name(),
+ arch=arch,
+ usb_speed=bus_speed,
+ )
+
+ create_expect(arch, session, expect_filename, verbose=verbose)
+
+ tester = testers.ComparisonTester(
+ open(expect_filename),
+ "lib_xud",
+ "xud_sim_tests",
+ testname,
+ {"clk": clk.get_name(), "arch": arch, "speed": bus_speed},
+ )
+
+ tester_list.append(tester)
+ simargs = get_sim_args(testname, clk, phy, arch)
+ simthreads = [clk, phy] + extra_tasks
+ run_on_simulator(binary, simthreads, simargs=simargs)
+ else:
+ tester_list.append("Build Failed")
- """ Shared test code for all RX tests using the test_rx application.
- """
- testname,extension = os.path.splitext(os.path.basename(test_file))
+ return tester_list
- resources = xmostest.request_resource("xsim")
- binary = '{testname}/bin/{arch}/{testname}_{arch}.xe'.format(testname=testname, arch=arch)
+def create_expect(arch, session, filename, verbose=False):
- print binary
+ events = session.events
- if xmostest.testlevel_is_at_least(xmostest.get_testlevel(), level):
- print "Running {test}: {arch} arch sending {n} packets at {clk} (seed {seed})".format(
- test=testname, n=len(packets),
- arch=arch, clk=tx_clk.get_name(), seed=seed)
+ """ Create the expect file for what packets should be reported by the DUT
+ """
+ with open(filename, "w") as f:
- tx_phy.set_packets(packets)
- #rx_phy.set_expected_packets(packets)
+ packet_offset = 0
- expect_folder = create_if_needed("expect")
- expect_filename = '{folder}/{test}_{arch}.expect'.format(
- folder=expect_folder, test=testname, phy=tx_phy.get_name(), clk=tx_clk.get_name(), arch=arch)
- create_expect(packets, expect_filename)
+ if verbose:
+ print("EXPECTED OUTPUT:")
+ for i, event in enumerate(events):
- tester = xmostest.ComparisonTester(open(expect_filename),
- 'lib_xud', 'xud_sim_tests', testname,
- {'clk':tx_clk.get_name(), 'arch':arch})
+ expect_str = event.expected_output(session.bus_speed, offset=packet_offset)
+ packet_offset += event.event_count
- tester.set_min_testlevel(level)
+ if verbose:
+ print(str(expect_str), end=" ")
- simargs = get_sim_args(testname, tx_clk, tx_phy, arch)
- xmostest.run_on_simulator(resources['xsim'], binary,
- simthreads=[tx_clk, tx_phy] + extra_tasks,
- tester=tester,
- simargs=simargs)
+ f.write(str(expect_str))
-def create_expect(packets, filename):
- """ Create the expect file for what packets should be reported by the DUT
- """
- with open(filename, 'w') as f:
- for i,packet in enumerate(packets):
- #if not packet.dropped:
- if isinstance(packet, RxPacket):
- f.write("Receiving packet {}\n".format(i))
-
- for (i, byte) in enumerate(packet.get_bytes()):
- f.write("Received byte: {0:#x}\n".format(byte))
-
- else:
- f.write("Sending packet {}\n".format(i))
-
f.write("Test done\n")
-def get_sim_args(testname, clk, phy, arch='xs2'):
+ if verbose:
+ print("Test done\n")
+
+
+def get_sim_args(testname, clk, phy, arch="xs2"):
sim_args = []
- if args and args.trace:
+ if eval(os.getenv("enabletracing")):
log_folder = create_if_needed("logs")
- #if phy.get_name() == 'rgmii':
- #arch = 'xs2'
- filename = "{log}/xsim_trace_{test}_{clk}_{arch}".format(
- log=log_folder, test=testname,
- clk=clk.get_name(), phy=phy.get_name(), arch=arch)
-
- sim_args += ['--trace-to', '{0}.txt'.format(filename), '--enable-fnop-tracing']
- vcd_args = '-o {0}.vcd'.format(filename)
- vcd_args += (' -tile tile[0] -ports -ports-detailed -instructions'
- ' -functions -cycles -clock-blocks -pads -cores')
+ filename = "{log}/xsim_trace_{test}_{clk}_{arch}".format(
+ log=log_folder, test=testname, clk=clk.get_name(), phy=phy.name, arch=arch
+ )
- # The RGMII pins are on tile[1]
- #if phy.get_name() == 'rgmii':
- # vcd_args += (' -tile tile[0] -ports -ports-detailed -instructions'
- # ' -functions -cycles -clock-blocks -cores')
+ sim_args += ["--trace-to", "{0}.txt".format(filename), "--enable-fnop-tracing"]
- sim_args += ['--vcd-tracing', vcd_args]
+ vcd_args = "-o {0}.vcd".format(filename)
+ vcd_args += (
+ " -tile tile[0] -ports -ports-detailed -instructions"
+ " -functions -cycles -clock-blocks -pads -cores -usb"
+ )
-# sim_args += ['--xscope', '-offline logs/xscope.xmt']
+ sim_args += ["--vcd-tracing", vcd_args]
return sim_args
-def packet_processing_time(phy, data_bytes):
- """ Returns the time it takes the DUT to process a given frame
- """
- #if mac == 'standard':
- # return 4000 * phy.get_clock().get_bit_time()
- #elif phy.get_name() == 'rgmii' and mac == 'rt':
- return 6000 * phy.get_clock().get_bit_time()
- ##else:
- # return 2000 * phy.get_clock().get_bit_time()
-
-def get_dut_address():
- """ Returns the busaddress of the DUT
- """
- #todo, we need the ability to config this
- return 1
-
-def choose_small_frame_size(rand):
- """ Choose the size of a frame near the minimum size frame (46 data bytes)
- """
- return rand.randint(46, 54)
def move_to_next_valid_packet(phy):
- while (phy.expect_packet_index < phy.num_expected_packets and
- phy.expected_packets[phy.expect_packet_index].dropped):
+ while (
+ phy.expect_packet_index < phy.num_expected_packets
+ and phy.expected_packets[phy.expect_packet_index].dropped
+ ):
phy.expect_packet_index += 1
+
def check_received_packet(packet, phy):
if phy.expected_packets is None:
return
@@ -197,15 +257,18 @@ def check_received_packet(packet, phy):
if phy.expect_packet_index < phy.num_expected_packets:
expected = phy.expected_packets[phy.expect_packet_index]
if packet != expected:
- print "ERROR: packet {n} does not match expected packet".format(
- n=phy.expect_packet_index)
+ print(
+ "ERROR: packet {n} does not match expected packet".format(
+ n=phy.expect_packet_index
+ )
+ )
- print "Received:"
+ print("Received:")
sys.stdout.write(packet.dump())
- print "Expected:"
+ print("Expected:")
sys.stdout.write(expected.dump())
- print "Received packet {} ok".format(phy.expect_packet_index)
+ print("Received packet {} ok".format(phy.expect_packet_index))
# Skip this packet
phy.expect_packet_index += 1
@@ -213,11 +276,10 @@ def check_received_packet(packet, phy):
move_to_next_valid_packet(phy)
else:
- print "ERROR: received unexpected packet from DUT"
- print "Received:"
+ print("ERROR: received unexpected packet from DUT")
+ print("Received:")
sys.stdout.write(packet.dump())
if phy.expect_packet_index >= phy.num_expected_packets:
- print "Test done"
+ print("Test done")
phy.xsi.terminate()
-
diff --git a/tests/runtests.py b/tests/runtests.py
deleted file mode 100755
index fa8e8ef5..00000000
--- a/tests/runtests.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016-2021 XMOS LIMITED.
-# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-import xmostest
-import argparse
-
-import helpers
-
-if __name__ == "__main__":
- global trace
- argparser = argparse.ArgumentParser(description="XMOS lib_xud tests")
- argparser.add_argument('--trace', action='store_true', help='Run tests with simulator and VCD traces')
- argparser.add_argument('--arch', choices=['xs1', 'xs2'], type=str, help='Run tests only on specified xcore architecture')
- argparser.add_argument('--clk', choices=['25Mhz', '125Mhz'], type=str, help='Run tests only at specified clock speed')
- argparser.add_argument('--mac', choices=['rt', 'rt_hp', 'standard'], type=str, help='Run tests only on specified MAC')
- argparser.add_argument('--seed', type=int, help='The seed', default=None)
- argparser.add_argument('--verbose', action='store_true', help='Enable verbose tracing in the phys')
-
- argparser.add_argument('--num-packets', type=int, help='Number of packets in the test', default='100')
- argparser.add_argument('--data-len-min', type=int, help='Minimum packet data bytes', default='46')
- argparser.add_argument('--data-len-max', type=int, help='Maximum packet data bytes', default='500')
-
- helpers.args = xmostest.init(argparser)
-
- # xmostest.register_group("lib_xud",
- # "xud_sim_tests",
- # "XUD simulator tests",
- # """
-#Tests are performed by running the GPIO library connected to a simulator model
-#(written as a python plugin to xsim). The simulator model checks that the pins
-#are driven and read by the ports as expected. Tests are run to test the
-#following features:
-#
-# * Inputting on a multibit port with multiple clients using the default pin map
-# * Inputting on a multibit port with multiple clients using a specified pin map
-# * Inputting on a 1bit port
-# * Inputting with timestamps
-# * Eventing on a multibit input port
-# * Eventing on a 1bit input port
-# * Outputting on a multibit port with multiple clients using the default pin map
-# * Outputting on a multibit port with multiple clients using a specified pin map
-# * Outputting with timestamps
-#""")
-#'''
- # xmostest.runtests()
-
- xmostest.finish()
diff --git a/tests/shared_src/shared.h b/tests/shared_src/shared.h
index 2f820cfc..eda08a01 100644
--- a/tests/shared_src/shared.h
+++ b/tests/shared_src/shared.h
@@ -1,66 +1,118 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-unsigned char g_rxDataCheck[7] = {0, 0, 0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
+#ifndef _SHARED_H_
+#define _SHARED_H_
+#include
+#include
+#include
+#include
+#include
+#include "xud.h"
+
+unsigned char g_rxDataCheck_[16] = {0};
+unsigned char g_txDataCheck_[16] = {0};
+unsigned g_txLength[16] = {0};
unsafe
{
- unsigned char volatile * unsafe g_rxDataCheck_ = g_rxDataCheck;
- unsigned char volatile * unsafe g_txDataCheck_ = g_txDataCheck;
+ unsigned char volatile * unsafe g_rxDataCheck = g_rxDataCheck_;
+ unsigned char volatile * unsafe g_txDataCheck = g_txDataCheck_;
}
void exit(int);
-#ifndef PKT_COUNT
-#define PKT_COUNT 10
+#define FAIL_RX_DATAERROR 1
+#define FAIL_RX_LENERROR 2
+#define FAIL_RX_EXPECTED_CTL 3
+#define FAIL_RX_BAD_RETURN_CODE 4
+#define FAIL_RX_FRAMENUMBER 5
+
+#ifdef XUD_SIM_XSIM
+/* Alternatives to the RTL sim testbench functions */
+void TerminateFail(unsigned x)
+{
+ switch(x)
+ {
+ case FAIL_RX_DATAERROR:
+ printstr("\nXCORE: ### FAIL ### : XCORE RX Data Error\n");
+ break;
+
+ case FAIL_RX_LENERROR:
+ printstr("\nXCORE: ### FAIL ### : XCORE RX Length Error\n");
+ break;
+
+ case FAIL_RX_EXPECTED_CTL:
+ printstr("\nXCORE: ### FAIL ### : Expected a setup\n");
+ break;
+
+ case FAIL_RX_BAD_RETURN_CODE:
+ printstr("\nXCORE: ### FAIL ### : Unexpected return code\n");
+ break;
+
+ case FAIL_RX_FRAMENUMBER:
+ printstr("\nXCORE: ### FAIL ### : Received bad frame number\n");
+ break;
+ }
+ exit(x);
+}
+void TerminatePass(unsigned x)
+{
+ exit(0);
+}
#endif
-#ifndef INITIAL_PKT_LENGTH
-#define INITIAL_PKT_LENGTH 10
+#ifndef PKT_LEN_START
+#define PKT_LEN_START (10)
#endif
+#ifndef PKT_LEN_END
+#define PKT_LEN_END (21)
+#endif
-#pragma unsafe arrays
-XUD_Result_t SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
+#ifndef MAX_PKT_COUNT
+#define MAX_PKT_COUNT (50)
+#endif
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
- }
+#ifndef TEST_EP_NUM
+#warning TEST_EP_NUM not defined, using default value
+#define TEST_EP_NUM (1)
+#endif
+
+typedef enum t_runMode
+{
+ RUNMODE_LOOP,
+ RUNMODE_DIE
+} t_runMode;
- return XUD_SetBuffer(ep, buffer, length);
-}
#pragma unsafe arrays
-XUD_Result_t SendControlPacket(XUD_ep ep, int length, int epNum)
+XUD_Result_t SendTxPacket(XUD_ep ep, int length, int epNum)
{
unsigned char buffer[1024];
+
for (int i = 0; i < length; i++)
- {
+ unsafe {
buffer[i] = g_txDataCheck[epNum]++;
}
- return XUD_SetControlBuffer(ep, buffer, length);
+ return XUD_SetBuffer(ep, buffer, length);
}
-
-
#pragma unsafe arrays
-int TestEp_Bulk_Tx(chanend c_in1, int epNum1, int die)
+int TestEp_Tx(chanend c_in, int epNum1, unsigned start, unsigned end, t_runMode runMode)
{
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
+ XUD_ep ep_in = XUD_InitEp(c_in);
- unsigned char buffer[PKT_COUNT][1024];
+ unsigned char buffer[MAX_PKT_COUNT][1024];
int counter = 0;
- int length = INITIAL_PKT_LENGTH;
+ int length = start;
+
+ set_core_fast_mode_on();
- for(int i = 0; i< PKT_COUNT; i++)
+ /* Prepare packets */
+ for(int i = 0; i <= (end-start); i++)
{
for(int j = 0; j < length; j++)
{
@@ -69,106 +121,149 @@ int TestEp_Bulk_Tx(chanend c_in1, int epNum1, int die)
length++;
}
- length = INITIAL_PKT_LENGTH;
-
#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
+ length = start;
+ for(int i = 0; i <= (end - start); i++)
{
- XUD_SetBuffer(ep_in1, buffer[i], length++);
+ XUD_SetBuffer(ep_in, buffer[i], length++);
}
-
- if(die)
- exit(0);
+ if(runMode == RUNMODE_DIE)
+ return 0;
else
while(1);
}
-
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-#define FAIL_RX_EXPECTED_CTL 2
-#define FAIL_RX_BAD_RETURN_CODE 3
-
-unsigned fail(int x)
+#pragma unsafe arrays
+int RxDataCheck(unsigned char b[], int l, int epNum, unsigned expectedLength)
{
- switch(x)
+ if (l != expectedLength)
{
- case FAIL_RX_DATAERROR:
- printstr("\nXCORE: ### FAIL ### : XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("\nXCORE: ### FAIL ### : XCORE RX Length Error\n");
- break;
-
- case FAIL_RX_EXPECTED_CTL:
- printstr("\nXCORE: ### FAIL ### : Expected a setup\n");
- break;
-
- case FAIL_RX_BAD_RETURN_CODE:
- printstr("\nXCORE: ### FAIL ### : Unexpcected return code\n");
- break;
-
+ printf("%d %d", (unsigned) l, expectedLength);
+ return FAIL_RX_LENERROR;
}
- exit(1);
-}
-
-#pragma unsafe arrays
-unsafe int RxDataCheck(unsigned char b[], int l, int epNum)
-{
for (int i = 0; i < l; i++)
{
unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck_[epNum])
+
+ unsafe
{
- printstr("#### Mismatch on EP.. \n");
- //printint(epNum);
- //printstr(". Got:");
- //printhex(b[i]);
- //printstr(" Expected:");
- //printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- printf("### Mismatch on EP: %d. Got %d, Expected %d\n", epNum, b[i], g_rxDataCheck[epNum]);
- return 1;
-
- }
+ if(b[i] != g_rxDataCheck[epNum])
+ {
+#ifdef XUD_SIM_XSIM
+ printstr("#### Mismatch on EP: ");
+ printint(epNum);
+ printstr(". Got:");
+ printhex(b[i]);
+ printstr(" Expected:");
+ printhex(g_rxDataCheck[epNum]);
+ printstr(" Pkt len: ");
+ printintln(l); // Packet length
+#endif
+ return 1;
+ }
- g_rxDataCheck_[epNum]++;
+ g_rxDataCheck[epNum]++;
+ }
}
return 0;
}
#pragma unsafe arrays
-int TestEp_Bulk_Rx(chanend c_out1, int epNum1)
+int TestEp_Rx(chanend c_out, int epNum, int start, int end)
{
- // TODO check rx lengths
- unsigned int length[PKT_COUNT];
- //XUD_Result_t res;
+ unsigned int length[MAX_PKT_COUNT];
- XUD_ep ep_out1 = XUD_InitEp(c_out1);
+ XUD_ep ep_out1 = XUD_InitEp(c_out);
/* Buffer for Setup data */
- unsigned char buffer[PKT_COUNT][1024];
+ unsigned char buffer[MAX_PKT_COUNT][1024];
+
+ set_core_fast_mode_on();
/* Receive a bunch of packets quickly, then check them */
#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
+ for(int i = 0; i <= (end-start); i++)
{
XUD_GetBuffer(ep_out1, buffer[i], length[i]);
}
#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
+ for(int i = 0; i <= (end-start); i++)
{
unsafe
{
- RxDataCheck(buffer[i], length[i], epNum1);
+ unsigned expectedLength = start+i;
+ unsigned fail = RxDataCheck(buffer[i], length[i], epNum, expectedLength);
+ if (fail)
+ return fail;
+
}
}
- exit(0);
+ return 0;
}
+
+/* Loopback packets forever */
+#pragma unsafe arrays
+int TestEp_Loopback(chanend c_out1, chanend c_in1, t_runMode runMode)
+{
+ unsigned int length;
+ XUD_Result_t res;
+
+ set_core_fast_mode_on();
+
+ XUD_ep ep_out1 = XUD_InitEp(c_out1);
+ XUD_ep ep_in1 = XUD_InitEp(c_in1);
+
+ /* Buffer for Setup data */
+ unsigned char buffer[1024];
+
+ while(1)
+ {
+ XUD_GetBuffer(ep_out1, buffer, length);
+ XUD_SetBuffer(ep_in1, buffer, length);
+
+ /* Loop back once and return */
+ if(runMode == RUNMODE_DIE)
+ break;
+
+ /* Partial un-roll */
+ XUD_GetBuffer(ep_out1, buffer, length);
+ XUD_SetBuffer(ep_in1, buffer, length);
+ }
+}
+
+#ifndef TEST_DTHREADS
+#warning TEST_DTHREADS not defined
+#define TEST_DTHREADS (0)
+#endif
+
+#if (TEST_DTHREADS > 6)
+#error TEST_DTHREADS too high
+#endif
+
+size_t g_dummyThreadCount = TEST_DTHREADS;
+
+void dummyThread()
+{
+ unsigned x = 0;
+ set_core_fast_mode_on();
+
+ while(g_dummyThreadCount)
+ {
+ x++;
+ }
+}
+
+void dummyThreads()
+{
+#if (TEST_DTHREADS > 0)
+ par(size_t i = 0; i < TEST_DTHREADS; i++)
+ {
+ dummyThread();
+ }
+#endif
+}
+#endif
diff --git a/tests/shared_src/test_main.xc b/tests/shared_src/test_main.xc
new file mode 100644
index 00000000..32d13a0b
--- /dev/null
+++ b/tests/shared_src/test_main.xc
@@ -0,0 +1,52 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#ifdef XUD_SIM_RTL
+int testmain()
+#else
+int main()
+#endif
+{
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
+
+ par
+ {
+ {
+#if defined(XUD_TEST_SPEED_FS)
+ const unsigned speed = XUD_SPEED_FS;
+#elif defined(XUD_TEST_SPEED_HS)
+ const unsigned speed = XUD_SPEED_HS;
+#endif
+
+ XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
+ null, epTypeTableOut, epTypeTableIn,
+ speed, XUD_PWR_BUS);
+ }
+
+ {
+ unsigned fail = test_func(c_ep_out, c_ep_in);
+
+#ifdef XUD_SIM_RTL
+ /* Note, this test relies on checking at the host side */
+ if(fail)
+ TerminateFail(fail);
+ else
+ TerminatePass(fail);
+#endif
+ unsafe{
+ unsigned * unsafe p = &g_dummyThreadCount;
+ *p = 0;
+ }
+ if(TEST_EP_NUM != 0)
+ {
+ XUD_ep ep_out_0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep_out_0);
+ }
+ exit(0);
+ }
+
+ dummyThreads();
+ }
+
+ return 0;
+}
diff --git a/tests/test_bulk_rx_basic_badpid/src/test.xn b/tests/shared_src/test_xs2.xn
similarity index 91%
rename from tests/test_bulk_rx_basic_badpid/src/test.xn
rename to tests/shared_src/test_xs2.xn
index d0ee86b8..fb2bd70a 100644
--- a/tests/test_bulk_rx_basic_badpid/src/test.xn
+++ b/tests/shared_src/test_xs2.xn
@@ -17,7 +17,7 @@
-
+
@@ -27,9 +27,6 @@
-
-
-
@@ -59,10 +56,12 @@
-
+
+
+
diff --git a/tests/shared_src/test_xs3_600.xn b/tests/shared_src/test_xs3_600.xn
new file mode 100644
index 00000000..20e8eeb6
--- /dev/null
+++ b/tests/shared_src/test_xs3_600.xn
@@ -0,0 +1,24 @@
+
+
+
+ tileref tile[2]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/shared_src/test_xs3_800.xn b/tests/shared_src/test_xs3_800.xn
new file mode 100644
index 00000000..15ab41a6
--- /dev/null
+++ b/tests/shared_src/test_xs3_800.xn
@@ -0,0 +1,24 @@
+
+
+
+ tileref tile[2]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/test_bulk_loopback.py b/tests/test_bulk_loopback.py
index 4a04620a..9f8b9d1e 100644
--- a/tests/test_bulk_loopback.py
+++ b/tests/test_bulk_loopback.py
@@ -1,58 +1,75 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
-
- rand = random.Random()
- rand.seed(seed)
-
- ep_loopback = 3
- ep_loopback_kill = 2
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(0, 20):
-
- AppendOutToken(packets, ep_loopback)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=pkt_length, pid=data_pid)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- # 357 was min IPG supported on bulk loopback to not nak
- # For move from sc_xud to lib_xud (14.1.2 tools) had to increase this to 377
- # Increased again due to setup/out checking
- AppendInToken(packets, ep_loopback, inter_pkt_gap=417)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=pkt_length, pid=data_pid, timeout=9)) #DATA0
- packets.append(TxHandshakePacket())
-
- data_pid = data_pid ^ 8
-
- pkt_length = 10
-
- #Loopback and die..
- AppendOutToken(packets, ep_loopback_kill)
- packets.append(TxDataPacket(rand, length=pkt_length, pid=3)) #DATA0
- packets.append(RxHandshakePacket())
-
- AppendInToken(packets, ep_loopback_kill, inter_pkt_gap=400)
- packets.append(RxDataPacket(rand, length=pkt_length, pid=3)) #DATA0
- packets.append(TxHandshakePacket())
-
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
+
+PARAMS = deepcopy(PARAMS)
+for k in PARAMS:
+ PARAMS[k].update({"dummy_threads": [4]})
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ ep_loopback = ep
+ ep_loopback_kill = ep + 1
+
+ start_length = 10
+ end_length = 20
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # TODO randomise packet lengths and data
+ for pktLength in range(start_length, end_length + 1):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
+
+ pktLength = start_length
+
+ # Loopback and die..
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback_kill,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback_kill,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_loopback/Makefile b/tests/test_bulk_loopback/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_bulk_loopback/Makefile
+++ b/tests/test_bulk_loopback/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_bulk_loopback/src/main.xc b/tests/test_bulk_loopback/src/main.xc
index 1ca8d10e..3ffd79bd 100644
--- a/tests/test_bulk_loopback/src/main.xc
+++ b/tests/test_bulk_loopback/src/main.xc
@@ -1,59 +1,32 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
/* lib_xud simple bulk loopback test */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
+#include "shared.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-void exit(int);
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-/* Loopback packets forever */
-#pragma unsafe arrays
-int TestEp_Bulk(chanend c_out1, chanend c_in1)
-{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out1 = XUD_InitEp(c_out1);
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
- /* Buffer for Setup data */
- unsigned char buffer[1024];
+#define KILL_EP (TEST_EP_NUM + 1)
- while(1)
- {
- XUD_GetBuffer(ep_out1, buffer, length);
- XUD_SetBuffer(ep_in1, buffer, length);
-
- XUD_GetBuffer(ep_out1, buffer, length);
- XUD_SetBuffer(ep_in1, buffer, length);
- }
+#if (KILL_EP >= EP_COUNT_OUT) || (KILL_EP >= EP_COUNT_IN)
+#error KILL EP OUT OF RANGE
+#endif
-}
-/* Loopback packet and terminate */
+/* Loopback packet and terminate program */
#pragma unsafe arrays
-int TestEp_Bulk2(chanend c_out, chanend c_in)
+int TestEp_Bulk2(chanend c_out, chanend c_in, chanend c_out_0)
{
unsigned int length;
XUD_Result_t res;
XUD_ep ep_out = XUD_InitEp(c_out);
+ XUD_ep ep_out_0 = XUD_InitEp(c_out_0);
XUD_ep ep_in = XUD_InitEp(c_in);
/* Buffer for Setup data */
@@ -62,25 +35,24 @@ int TestEp_Bulk2(chanend c_out, chanend c_in)
XUD_GetBuffer(ep_out, buffer, length);
XUD_SetBuffer(ep_in, buffer, length);
+ XUD_Kill(ep_out_0);
exit(0);
}
-#define USB_CORE 0
int main()
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
par
{
-
- XUD_Main( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ XUD_Main( c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
+
+ TestEp_Loopback(c_ep_out[TEST_EP_NUM], c_ep_in[TEST_EP_NUM], RUNMODE_LOOP);
+ TestEp_Bulk2(c_ep_out[KILL_EP], c_ep_in[KILL_EP], c_ep_out[0]);
- TestEp_Bulk(c_ep_out[3], c_ep_in[3]);
- TestEp_Bulk2(c_ep_out[2], c_ep_in[2]);
+ dummyThreads();
}
return 0;
diff --git a/tests/test_bulk_loopback/src/test.xn b/tests/test_bulk_loopback/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_loopback/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_loopback/src/test_xs1.xn b/tests/test_bulk_loopback/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_loopback/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_loopback/src/xc_ptr.h b/tests/test_bulk_loopback/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_loopback/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_rx_basic.py b/tests/test_bulk_rx_basic.py
index e6b74ced..5a06b8c6 100644
--- a/tests/test_bulk_rx_basic.py
+++ b/tests/test_bulk_rx_basic.py
@@ -1,60 +1,31 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-
-# Single, setup transaction to EP 0
-
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- dev_address = get_dut_address()
- ep = 1
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- AppendOutToken(packets, ep)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
- # Note, quite big gap to allow checking.
-
- dataval += 10
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
-
- dataval += 11
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
- dataval += 12
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=13, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket(timeout=9))
-
- dataval += 13
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
-
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ start_length = 10
+ end_length = 19
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, end_length + 1):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_rx_basic/Makefile b/tests/test_bulk_rx_basic/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_bulk_rx_basic/Makefile
+++ b/tests/test_bulk_rx_basic/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_bulk_rx_basic/src/main.xc b/tests/test_bulk_rx_basic/src/main.xc
index d7a17171..2a09c8f2 100644
--- a/tests/test_bulk_rx_basic/src/main.xc
+++ b/tests/test_bulk_rx_basic/src/main.xc
@@ -1,81 +1,28 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "shared.h"
-#include "xc_ptr.h"
-
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
-
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-
-int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
-{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
- /* Buffer for Setup data */
- unsigned char buffer[1024];
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
- for(int i = 10; i <= 14; i++)
- {
- XUD_GetBuffer(ep_out, buffer, length);
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
- if(length != i)
- {
- printintln(length);
- fail(FAIL_RX_LENERROR);
- }
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (19)
+#endif
- unsafe{
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
- }
-
- }
-
- exit(0);
-}
+#include "shared.h"
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-#define USB_CORE 0
-int main()
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ return fail;
+}
- TestEp_Bulk(c_ep_out[1], c_ep_in[1], 1);
- }
+#include "test_main.xc"
- return 0;
-}
diff --git a/tests/test_bulk_rx_basic/src/test.xn b/tests/test_bulk_rx_basic/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_rx_basic/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_basic/src/test_xs1.xn b/tests/test_bulk_rx_basic/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_rx_basic/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_basic/src/xc_ptr.h b/tests/test_bulk_rx_basic/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_rx_basic/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_rx_basic_badcrc32.py b/tests/test_bulk_rx_basic_badcrc32.py
index 87f3cf6b..a29587d4 100644
--- a/tests/test_bulk_rx_basic_badcrc32.py
+++ b/tests/test_bulk_rx_basic_badcrc32.py
@@ -1,63 +1,95 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
+@pytest.fixture
+def test_session(ep, address, bus_speed):
-# Single, setup transaction to EP 0
+ # The large inter-event delays are to give the DUT time to do checking on the fly
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
- dev_address = get_dut_address()
- ep = 1
+ # Valid OUT transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
+ # Another valid OUT transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=6000,
+ )
+ )
- dataval = 0;
+ # OUT transaction with bad data CRC
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=12,
+ interEventDelay=6000,
+ badDataCrc=True,
+ )
+ )
- AppendOutToken(packets, ep)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
+ # Due to bad CRC, XUD will not ACK and expect a resend of the same packet - DATA PID won't be toggled
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=12,
+ interEventDelay=6000,
+ )
+ )
- # Note, quite big gap to allow checking.
-
- dataval += 10
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
+ # PID will be toggled as normal
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=13,
+ interEventDelay=6000,
+ )
+ )
- dataval += 11
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=12, bad_crc=True, pid=0x3)) #DATA0
- # Bad CRC - dont expect ACK
- #packets.append(RxHandshakePacket())
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=14,
+ interEventDelay=6000,
+ )
+ )
- #Due to bad CRC, XUD will not ACK and expect a resend of the same packet - so dont change PID
- dataval += 12
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=13, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- # PID toggle as normal
- dataval += 13
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=14, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
-
-
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ return session
diff --git a/tests/test_bulk_rx_basic_badcrc32/Makefile b/tests/test_bulk_rx_basic_badcrc32/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_bulk_rx_basic_badcrc32/Makefile
+++ b/tests/test_bulk_rx_basic_badcrc32/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_bulk_rx_basic_badcrc32/src/main.xc b/tests/test_bulk_rx_basic_badcrc32/src/main.xc
index b788d3f9..6d75c0e3 100644
--- a/tests/test_bulk_rx_basic_badcrc32/src/main.xc
+++ b/tests/test_bulk_rx_basic_badcrc32/src/main.xc
@@ -1,177 +1,27 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-//#include "test.h"
-#include "xc_ptr.h"
-//#error
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
-//extern xc_ptr char_array_to_xc_ptr(const unsigned char a[]);
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (14)
+#endif
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+#include "shared.h"
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
-
- g_rxDataCheck[epNum]++;
- }
-
- return 0;
-}
-
-int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
- unsigned char buffer[1024];
-
- for(int i = 10; i <= 14; i++)
- {
- /* Expect bad CRC */
- if(i == 12)
- {
- g_rxDataCheck[epNum]+=12;
- continue;
- }
-
- XUD_GetBuffer(ep_out, buffer, length);
-
- if(length != i)
- {
- printintln(length);
- printintln(i);
- fail(FAIL_RX_LENERROR);
- }
-
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
- }
-
- exit(0);
+ return fail;
}
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- //p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- //p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- //p_txLength = array_to_xc_ptr(g_txLength);
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- //TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
-
- TestEp_Bulk(c_ep_out[1], c_ep_in[1], 1);
- }
-
- return 0;
-}
+#include "test_main.xc"
diff --git a/tests/test_bulk_rx_basic_badcrc32/src/test.xn b/tests/test_bulk_rx_basic_badcrc32/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_rx_basic_badcrc32/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_basic_badcrc32/src/test_xs1.xn b/tests/test_bulk_rx_basic_badcrc32/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_rx_basic_badcrc32/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_basic_badpid.py b/tests/test_bulk_rx_basic_badpid.py
index 5ec9c6ea..ac43b9f6 100644
--- a/tests/test_bulk_rx_basic_badpid.py
+++ b/tests/test_bulk_rx_basic_badpid.py
@@ -1,67 +1,82 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-# Rx out of seq (but valid.. ) data PID
-
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-
-# Single, setup transaction to EP 0
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- dev_address = get_dut_address()
- ep = 1
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- AppendOutToken(packets, ep)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
- # Note, quite big gap to allow checking.
-
- dataval += 10
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
-
- #Pretend the ACK went missing. Re-send same packet. xCORE should ACK but throw pkt away
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
-
- dataval += 11
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
- dataval += 12
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=13, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket(timeout=9))
-
- dataval += 13
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # The large inter-frame gap is to give the DUT time to print its output
+ interEventDelay = 500
+
+ # Valid OUT transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ interEventDelay=interEventDelay,
+ )
+ )
+
+ # Pretend the ACK went missing on the way to host. Re-send same packet. xCORE should ACK but throw pkt away
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=interEventDelay,
+ resend=True,
+ )
+ )
+
+ # Send some valid OUT transactions
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=12,
+ interEventDelay=interEventDelay,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=13,
+ interEventDelay=interEventDelay,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=14,
+ interEventDelay=interEventDelay,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_rx_basic_badpid/Makefile b/tests/test_bulk_rx_basic_badpid/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_bulk_rx_basic_badpid/Makefile
+++ b/tests/test_bulk_rx_basic_badpid/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_bulk_rx_basic_badpid/src/main.xc b/tests/test_bulk_rx_basic_badpid/src/main.xc
index fbc71f2d..dd6a888d 100644
--- a/tests/test_bulk_rx_basic_badpid/src/main.xc
+++ b/tests/test_bulk_rx_basic_badpid/src/main.xc
@@ -1,180 +1,29 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-//#include "test.h"
-#include "xc_ptr.h"
+#include "shared.h"
-//#error
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
-//extern xc_ptr char_array_to_xc_ptr(const unsigned char a[]);
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (14)
+#endif
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+#include "shared.h"
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-
-
-
-
-//xc_ptr p_rxDataCheck;
-//xc_ptr p_txDataCheck;
-//xc_ptr p_txLength;
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
- g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
-
- return 0;
+ return fail;
}
-int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
-{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
- unsigned char buffer[1024];
-
- for(int i = 10; i <= 14; i++)
- {
- XUD_GetBuffer(ep_out, buffer, length);
-
- if(length != i)
- {
- printintln(length);
- fail(FAIL_RX_LENERROR);
- }
-
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
- }
+#include "test_main.xc"
- exit(0);
-}
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- //p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- //p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- //p_txLength = array_to_xc_ptr(g_txLength);
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- //TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
-
- TestEp_Bulk(c_ep_out[1], c_ep_in[1], 1);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_rx_basic_badpid/src/test_xs1.xn b/tests/test_bulk_rx_basic_badpid/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_rx_basic_badpid/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_basic_badpid/src/xc_ptr.h b/tests/test_bulk_rx_basic_badpid/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_rx_basic_badpid/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_rx_basic_nodata.py b/tests/test_bulk_rx_basic_nodata.py
new file mode 100644
index 00000000..679acfaf
--- /dev/null
+++ b/tests/test_bulk_rx_basic_nodata.py
@@ -0,0 +1,47 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+from usb_packet import TokenPacket, USB_PID
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+# Rx out of seq (but valid.. ) data PID
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ # The large inter-event delay is to give the DUT time to perform checking
+ ied = 500
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for length in range(10, 15):
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=length,
+ interEventDelay=ied,
+ )
+ )
+
+ # Simulate missing data payload
+ if length == 11:
+ session.add_event(
+ TokenPacket(
+ endpoint=ep,
+ address=address,
+ pid=USB_PID["OUT"],
+ interEventDelay=ied,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_rx_basic_nodata/Makefile b/tests/test_bulk_rx_basic_nodata/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_bulk_rx_basic_nodata/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_bulk_rx_basic_nodata/src/main.xc b/tests/test_bulk_rx_basic_nodata/src/main.xc
new file mode 100644
index 00000000..6d75c0e3
--- /dev/null
+++ b/tests/test_bulk_rx_basic_nodata/src/main.xc
@@ -0,0 +1,27 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (14)
+#endif
+
+#include "shared.h"
+
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
+
+ return fail;
+}
+
+#include "test_main.xc"
diff --git a/tests/test_bulk_rx_basic_rxerror.py b/tests/test_bulk_rx_basic_rxerror.py
index 9efa09f2..4385d537 100644
--- a/tests/test_bulk_rx_basic_rxerror.py
+++ b/tests/test_bulk_rx_basic_rxerror.py
@@ -1,72 +1,111 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
-# Single, setup transaction to EP 0
+@pytest.fixture
+def test_session(ep, address, bus_speed):
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
+ # Large inter-event delay is to give the DUT time to perform checking
+ ied = 6000
- dev_address = get_dut_address()
- ep = 1
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- AppendOutToken(packets, ep)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
+ # Valid OUT transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
# Assert RxError during packet
- dataval += 10
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb, rxe_assert_time=5)) #DATA1
-
# xCORE should ignore the packet and not handshake...
- #packets.append(RxHandshakePacket())
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=ied,
+ rxeAssertDelay_data=5,
+ )
+ )
# Re-send..
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb, rxe_assert_time=0)) #DATA1
- packets.append(RxHandshakePacket())
-
- dataval += 11
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- dataval += 12
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=13, pid=0xb, rxe_assert_time=1)) #DATA1
- #packets.append(RxHandshakePacket())
-
- #resend
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=13, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
-
-
- dataval += 13
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
-
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=ied,
+ )
+ )
+
+ # Valid OUT transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=12,
+ interEventDelay=ied,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=13,
+ interEventDelay=ied,
+ rxeAssertDelay_data=1,
+ )
+ )
+
+ # Re-send
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=13,
+ interEventDelay=ied,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=14,
+ interEventDelay=ied,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_rx_basic_rxerror/Makefile b/tests/test_bulk_rx_basic_rxerror/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_bulk_rx_basic_rxerror/Makefile
+++ b/tests/test_bulk_rx_basic_rxerror/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_bulk_rx_basic_rxerror/src/main.xc b/tests/test_bulk_rx_basic_rxerror/src/main.xc
index fbc71f2d..3a5d6326 100644
--- a/tests/test_bulk_rx_basic_rxerror/src/main.xc
+++ b/tests/test_bulk_rx_basic_rxerror/src/main.xc
@@ -1,180 +1,30 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-//#include "test.h"
-#include "xc_ptr.h"
-//#error
+#include "shared.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
-//extern xc_ptr char_array_to_xc_ptr(const unsigned char a[]);
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (14)
+#endif
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
+#include "shared.h"
-void exit(int);
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-unsigned fail(int x)
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
+ return fail;
}
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-
-
-
-
-//xc_ptr p_rxDataCheck;
-//xc_ptr p_txDataCheck;
-//xc_ptr p_txLength;
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
-
- g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
+#include "test_main.xc"
- return 0;
-}
-
-int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
-{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
- unsigned char buffer[1024];
-
- for(int i = 10; i <= 14; i++)
- {
- XUD_GetBuffer(ep_out, buffer, length);
-
- if(length != i)
- {
- printintln(length);
- fail(FAIL_RX_LENERROR);
- }
-
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
- }
-
- exit(0);
-}
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- //p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- //p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- //p_txLength = array_to_xc_ptr(g_txLength);
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- //TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
-
- TestEp_Bulk(c_ep_out[1], c_ep_in[1], 1);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_rx_basic_rxerror/src/test.xn b/tests/test_bulk_rx_basic_rxerror/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_rx_basic_rxerror/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_basic_rxerror/src/test_xs1.xn b/tests/test_bulk_rx_basic_rxerror/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_rx_basic_rxerror/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_basic_rxerror/src/xc_ptr.h b/tests/test_bulk_rx_basic_rxerror/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_rx_basic_rxerror/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_rx_fastpacket.py b/tests/test_bulk_rx_fastpacket.py
deleted file mode 100644
index e3583e6e..00000000
--- a/tests/test_bulk_rx_fastpacket.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016-2021 XMOS LIMITED.
-# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- dev_address = get_dut_address()
- ep_loopback = 3
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- data_val = 0;
- pkt_length = 20
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(10, 20):
-
- # min 237
- # increased to 277 when SETUP/OUT checking added
- AppendOutToken(packets, ep_loopback, inter_pkt_gap=277)
- packets.append(TxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- data_val = data_val + pkt_length
- data_pid = data_pid ^ 8
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
diff --git a/tests/test_bulk_rx_fastpacket/src/main.xc b/tests/test_bulk_rx_fastpacket/src/main.xc
deleted file mode 100644
index 9e24c69c..00000000
--- a/tests/test_bulk_rx_fastpacket/src/main.xc
+++ /dev/null
@@ -1,182 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
-
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
-
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-#define PKT_COUNT 10
-#define INITIAL_PKT_LENGTH 10
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
-
- g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
-
- return 0;
-}
-
-
-#pragma unsafe arrays
-int TestEp_Bulk_Tx(chanend c_in1, int epNum1)
-{
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
-
- unsigned char buffer[PKT_COUNT][1024];
-
- int counter = 0;
-
- for(int i = 0; i< PKT_COUNT; i++)
- {
- //for(int j = 0; j < lengths[i]; j++)
- {
- // buffer[i] = counter++;
- }
- }
-
-}
-
-
-#pragma unsafe arrays
-int TestEp_Bulk_Rx(chanend c_out1, int epNum1)
-{
- // TODO check rx lengths
-
-
- unsigned int length[PKT_COUNT];
- XUD_Result_t res;
-
- XUD_ep ep_out1 = XUD_InitEp(c_out1);
-
- /* Buffer for Setup data */
- unsigned char buffer[PKT_COUNT][1024];
-
- /* Receive a bunch of packets quickly, then check them */
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- XUD_GetBuffer(ep_out1, buffer[i], length[i]);
- }
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- RxDataCheck(buffer[i], length[i], epNum1);
- }
-
- exit(0);
-}
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- TestEp_Bulk_Rx(c_ep_out[3], 3);
- //TestEp_Bulk_Tx(c_ep_in[3], 3);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_rx_fastpacket/src/test.xn b/tests/test_bulk_rx_fastpacket/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_rx_fastpacket/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_fastpacket/src/test_xs1.xn b/tests/test_bulk_rx_fastpacket/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_rx_fastpacket/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_fastpacket/src/xc_ptr.h b/tests/test_bulk_rx_fastpacket/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_rx_fastpacket/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_rx_fastpacket_multiep.py b/tests/test_bulk_rx_fastpacket_multiep.py
deleted file mode 100644
index 8bd918ca..00000000
--- a/tests/test_bulk_rx_fastpacket_multiep.py
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016-2021 XMOS LIMITED.
-# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- data_val = 0;
- pkt_length = 20
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(10, 20):
-
- #min 237
- AppendOutToken(packets, 3, inter_pkt_gap=1)
- packets.append(TxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- AppendOutToken(packets, 4, inter_pkt_gap=1)
- packets.append(TxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- AppendOutToken(packets, 5, inter_pkt_gap=0)
- packets.append(TxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- AppendOutToken(packets, 6, inter_pkt_gap=0)
- packets.append(TxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid)) #DATA0
- packets.append(RxHandshakePacket(timeout=9))
-
- data_val = data_val + pkt_length
- data_pid = data_pid ^ 8
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
diff --git a/tests/test_bulk_rx_fastpacket_multiep/Makefile b/tests/test_bulk_rx_fastpacket_multiep/Makefile
deleted file mode 100644
index 83edfc42..00000000
--- a/tests/test_bulk_rx_fastpacket_multiep/Makefile
+++ /dev/null
@@ -1,50 +0,0 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
diff --git a/tests/test_bulk_rx_fastpacket_multiep/src/main.xc b/tests/test_bulk_rx_fastpacket_multiep/src/main.xc
deleted file mode 100644
index 591080c5..00000000
--- a/tests/test_bulk_rx_fastpacket_multiep/src/main.xc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "shared.h"
-
-
-#define XUD_EP_COUNT_OUT 7
-#define XUD_EP_COUNT_IN 1
-
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL};
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
-
- TestEp_Bulk_Rx(c_ep_out[3], 3);
- TestEp_Bulk_Rx(c_ep_out[4], 4);
- TestEp_Bulk_Rx(c_ep_out[5], 5);
- TestEp_Bulk_Rx(c_ep_out[6], 6);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_rx_fastpacket_multiep/src/test.xn b/tests/test_bulk_rx_fastpacket_multiep/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_rx_fastpacket_multiep/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_fastpacket_multiep/src/test_xs1.xn b/tests/test_bulk_rx_fastpacket_multiep/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_rx_fastpacket_multiep/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rx_fastpacket_multiep/src/xc_ptr.h b/tests/test_bulk_rx_fastpacket_multiep/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_rx_fastpacket_multiep/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_rx_multiep.py b/tests/test_bulk_rx_multiep.py
new file mode 100644
index 00000000..8860b377
--- /dev/null
+++ b/tests/test_bulk_rx_multiep.py
@@ -0,0 +1,65 @@
+# Copyright 2019-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
+
+# EP numbers currently fixed for this test - set in params
+PARAMS = deepcopy(PARAMS)
+for k in PARAMS:
+ PARAMS[k].update({"ep": [3], "dummy_threads": [0]})
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, 20):
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=4,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=5,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=6,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_rx_multiep/Makefile b/tests/test_bulk_rx_multiep/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_bulk_rx_multiep/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_bulk_rx_multiep/src/main.xc b/tests/test_bulk_rx_multiep/src/main.xc
new file mode 100644
index 00000000..4e604acc
--- /dev/null
+++ b/tests/test_bulk_rx_multiep/src/main.xc
@@ -0,0 +1,46 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "shared.h"
+
+#define EP_COUNT_OUT (7)
+#define EP_COUNT_IN (7)
+
+#define PACKET_LEN_START (10)
+#define PACKET_LEN_END (19)
+
+/* Check for clashes with TEST_EP and traffic EP */
+#if TEST_EP_NUM == 4
+#error TEST_EP_NUM clashes with traffic EP
+#endif
+
+#if TEST_EP_NUM == 5
+#error TEST_EP_NUM clashes with traffic EP
+#endif
+
+#if TEST_EP_NUM == 6
+#error TEST_EP_NUM clashes with traffic EP
+#endif
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned fail[4];
+
+ par
+ {
+ fail[0] = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PACKET_LEN_START, PACKET_LEN_END);
+ fail[1] = TestEp_Rx(c_ep_out[4], 4, PACKET_LEN_START, PACKET_LEN_END);
+ fail[2] = TestEp_Rx(c_ep_out[5], 5, PACKET_LEN_START, PACKET_LEN_END);
+ fail[3] = TestEp_Rx(c_ep_out[6], 6, PACKET_LEN_START, PACKET_LEN_END);
+ }
+
+ for(size_t i = 0; i< 4; i++)
+ fail[0] |= fail[i];
+
+ return fail[0];
+}
+
+#include "test_main.xc"
diff --git a/tests/test_bulk_rx_traffic.py b/tests/test_bulk_rx_traffic.py
new file mode 100644
index 00000000..5394c88e
--- /dev/null
+++ b/tests/test_bulk_rx_traffic.py
@@ -0,0 +1,81 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+from usb_phy import USB_MAX_EP_ADDRESS
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ ied = 500
+
+ trafficAddress1 = (address + 1) % 128
+ trafficAddress2 = (address + 127) % 128
+ trafficEp1 = USB_MAX_EP_ADDRESS
+ trafficEp2 = 0
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, 20):
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=trafficAddress1,
+ endpointNumber=trafficEp1,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=trafficAddress2,
+ endpointNumber=trafficEp2,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+
+ trafficEp1 = trafficEp1 - 1
+
+ # Don't clash with test EP
+ if trafficEp1 == ep:
+ trafficEp1 = trafficEp1 - 1
+
+ if trafficEp1 < 0:
+ trafficEp1 = USB_MAX_EP_ADDRESS
+
+ trafficEp2 + trafficEp2 + 1
+
+ # Don't clash with test EP
+ if trafficEp2 == ep:
+ trafficEp2 = trafficEp1 + 1
+
+ if trafficEp2 > USB_MAX_EP_ADDRESS:
+ trafficEp2 = 0
+
+ return session
diff --git a/tests/test_bulk_rx_traffic/Makefile b/tests/test_bulk_rx_traffic/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_bulk_rx_traffic/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_bulk_rx_traffic/src/main.xc b/tests/test_bulk_rx_traffic/src/main.xc
new file mode 100644
index 00000000..609c3f38
--- /dev/null
+++ b/tests/test_bulk_rx_traffic/src/main.xc
@@ -0,0 +1,71 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "shared.h"
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (19)
+#endif
+
+#ifndef TEST_EP_NUM
+#error
+#endif
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+#ifdef XUD_SIM_RTL
+int testmain()
+#else
+int main()
+#endif
+{
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
+
+ par
+ {
+ {
+#if defined(XUD_TEST_SPEED_FS)
+ unsigned speed = XUD_SPEED_FS;
+#elif defined(XUD_TEST_SPEED_HS)
+ unsigned speed = XUD_SPEED_HS;
+#else
+#error XUD_TEST_SPEED_XX not defined
+#endif
+
+ XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
+ null, epTypeTableOut, epTypeTableIn,
+ speed, XUD_PWR_BUS);
+ }
+
+ {
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
+
+ /* Give some time for the traffic EP transactions to be sent */
+ {
+ timer t;
+ unsigned time;
+ t :> time;
+ t when timerafter(time + 10000) :> int _;
+ }
+
+ XUD_ep ep0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep0);
+
+ if(fail)
+ TerminateFail(fail);
+ else
+ TerminatePass(fail);
+
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/test_bulk_rxtx_fastpacket.py b/tests/test_bulk_rxtx_fastpacket.py
deleted file mode 100644
index 78ab560a..00000000
--- a/tests/test_bulk_rxtx_fastpacket.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016-2021 XMOS LIMITED.
-# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- ep = 3
-
- packets = []
-
- data_val = 0;
- pkt_length = 20
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(10, 20):
-
- # < 17 fails for SI
- # < 37 fails for DI
- AppendOutToken(packets, ep, inter_pkt_gap=37)
- packets.append(TxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid)) #DATA0
- # 9 works for SI
- packets.append(RxHandshakePacket(timeout=10))
-
- AppendInToken(packets, ep, inter_pkt_gap=0)
- packets.append(RxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid))
- packets.append(TxHandshakePacket())
-
- data_val = data_val + pkt_length
- data_pid = data_pid ^ 8
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
diff --git a/tests/test_bulk_rxtx_fastpacket/src/main.xc b/tests/test_bulk_rxtx_fastpacket/src/main.xc
deleted file mode 100644
index f4cefde5..00000000
--- a/tests/test_bulk_rxtx_fastpacket/src/main.xc
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
-
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
-
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-#define PKT_COUNT 10
-#define INITIAL_PKT_LENGTH 10
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
-
- g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
-
- return 0;
-}
-
-
-#pragma unsafe arrays
-int TestEp_Bulk_Tx(chanend c_in1, int epNum1)
-{
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
-
- unsigned char buffer[PKT_COUNT][1024];
-
- int counter = 0;
- int length = INITIAL_PKT_LENGTH;
-
- for(int i = 0; i< PKT_COUNT; i++)
- {
- for(int j = 0; j < length; j++)
- {
- buffer[i][j] = counter++;
- }
- length++;
- }
-
- length = INITIAL_PKT_LENGTH;
-
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- XUD_SetBuffer(ep_in1, buffer[i], length++);
- }
-
- exit(0);
-
-}
-#pragma unsafe arrays
-int TestEp_Bulk_Rx(chanend c_out1, int epNum1)
-{
- // TODO check rx lengths
-
- unsigned int length[PKT_COUNT];
- XUD_Result_t res;
-
- XUD_ep ep_out1 = XUD_InitEp(c_out1);
-
- /* Buffer for Setup data */
- unsigned char buffer[PKT_COUNT][1024];
-
- /* Receive a bunch of packets quickly, then check them */
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- XUD_GetBuffer(ep_out1, buffer[i], length[i]);
- }
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- RxDataCheck(buffer[i], length[i], epNum1);
- }
-
- while(1);
-
-}
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- TestEp_Bulk_Tx(c_ep_in[3], 3);
- TestEp_Bulk_Rx(c_ep_out[3], 3);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_rxtx_fastpacket/src/test.xn b/tests/test_bulk_rxtx_fastpacket/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_rxtx_fastpacket/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rxtx_fastpacket/src/test_xs1.xn b/tests/test_bulk_rxtx_fastpacket/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_rxtx_fastpacket/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_rxtx_fastpacket/src/xc_ptr.h b/tests/test_bulk_rxtx_fastpacket/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_rxtx_fastpacket/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_tx_badack.py b/tests/test_bulk_tx_badack.py
new file mode 100644
index 00000000..49173cd1
--- /dev/null
+++ b/tests/test_bulk_tx_badack.py
@@ -0,0 +1,52 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+from usb_packet import TokenPacket, RxDataPacket, TxHandshakePacket, USB_PID
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ pktLength = 10
+ ied = 4000
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, 14):
+
+ if pktLength == 12:
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=ied,
+ )
+ )
+ session.add_event(
+ RxDataPacket(
+ dataPayload=session.getPayload_in(ep, pktLength, resend=True),
+ pid=USB_PID["DATA0"],
+ )
+ )
+ session.add_event(TxHandshakePacket(pid=0xFF))
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_tx_badack/Makefile b/tests/test_bulk_tx_badack/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_bulk_tx_badack/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_bulk_tx_badack/src/main.xc b/tests/test_bulk_tx_badack/src/main.xc
new file mode 100644
index 00000000..7c6c170f
--- /dev/null
+++ b/tests/test_bulk_tx_badack/src/main.xc
@@ -0,0 +1,37 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (13)
+#endif
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#include "shared.h"
+
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL};
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned fail = TestEp_Tx(c_ep_in[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
+
+ return fail;
+}
+
+#include "test_main.xc"
diff --git a/tests/test_bulk_tx_basic.py b/tests/test_bulk_tx_basic.py
index 7058411b..334dbb7b 100644
--- a/tests/test_bulk_tx_basic.py
+++ b/tests/test_bulk_tx_basic.py
@@ -1,58 +1,31 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-
-# Single, setup transaction to EP 0
-
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- dev_address = get_dut_address()
- ep = 2
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- AppendInToken(packets, ep)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(TxHandshakePacket())
-
- dataval += 10
- AppendInToken(packets, ep, inter_pkt_gap=4000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb)) #DATA1
- packets.append(TxHandshakePacket())
-
- dataval += 11
- AppendInToken(packets, ep, inter_pkt_gap=4000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
- packets.append(TxHandshakePacket())
-
- dataval += 12
- AppendInToken(packets, ep, inter_pkt_gap=4000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=13, pid=0xb)) #DATA1
- packets.append(TxHandshakePacket())
-
- dataval += 13
- AppendInToken(packets, ep, inter_pkt_gap=4000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
- packets.append(TxHandshakePacket())
-
- # Note, quite big gap to allow checking.
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ start_length = 10
+ end_length = 19
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, end_length + 1):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_tx_basic/Makefile b/tests/test_bulk_tx_basic/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_bulk_tx_basic/Makefile
+++ b/tests/test_bulk_tx_basic/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_bulk_tx_basic/src/main.xc b/tests/test_bulk_tx_basic/src/main.xc
index 30296044..d273ee68 100644
--- a/tests/test_bulk_tx_basic/src/main.xc
+++ b/tests/test_bulk_tx_basic/src/main.xc
@@ -1,114 +1,39 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
-#define XUD_EP_COUNT_OUT 3
-#define XUD_EP_COUNT_IN 3
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (19)
+#endif
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#include "shared.h"
+
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL,
XUD_EPTYPE_BUL,
XUD_EPTYPE_BUL};
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
-
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
+ unsigned fail = TestEp_Tx(c_ep_in[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
- /* Buffer for Setup data */
- unsigned char buffer[1024];
-
- for(int i = 10; i <= 14; i++)
- {
- SendTxPacket(ep_in, i, epNum);
- }
-
- exit(0);
+ return fail;
}
+#include "test_main.xc"
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- //p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- //p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- //p_txLength = array_to_xc_ptr(g_txLength);
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- //TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
- TestEp_Bulk(c_ep_out[2], c_ep_in[2], 1);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_tx_basic/src/test.xn b/tests/test_bulk_tx_basic/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_tx_basic/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_basic/src/test_xs1.xn b/tests/test_bulk_tx_basic/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_tx_basic/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_basic_noack.py b/tests/test_bulk_tx_basic_noack.py
index d087f257..4fd309fd 100644
--- a/tests/test_bulk_tx_basic_noack.py
+++ b/tests/test_bulk_tx_basic_noack.py
@@ -1,64 +1,50 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-
-# Single, setup transaction to EP 0
-
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- dev_address = get_dut_address()
- ep = 2
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- AppendInToken(packets, ep)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(TxHandshakePacket())
-
- dataval += 10
- AppendInToken(packets, ep, inter_pkt_gap=5000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb)) #DATA1
- packets.append(TxHandshakePacket())
-
- #pretend CRC got broken on way to host and dont send ACK
- dataval += 11
- AppendInToken(packets, ep, inter_pkt_gap=5000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
- #packets.append(TxHandshakePacket())
-
- #xCore should resend same packet again..
- AppendInToken(packets, ep, inter_pkt_gap=5000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
- packets.append(TxHandshakePacket())
-
- dataval += 12
- AppendInToken(packets, ep, inter_pkt_gap=5000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=13, pid=0xb)) #DATA1
- packets.append(TxHandshakePacket())
-
- dataval += 13
- AppendInToken(packets, ep, inter_pkt_gap=5000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
- packets.append(TxHandshakePacket())
-
- # Note, quite big gap to allow checking.
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+from usb_packet import USB_PID, TokenPacket, RxDataPacket
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ # Note, quite big gap to allow checking
+ ied = 4000
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, 15):
+
+ if pktLength == 12:
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=ied,
+ )
+ )
+ session.add_event(
+ RxDataPacket(
+ dataPayload=session.getPayload_in(ep, pktLength, resend=True)
+ )
+ )
+ # Missing ACK - simulate CRC fail at host
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_tx_basic_noack/Makefile b/tests/test_bulk_tx_basic_noack/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_bulk_tx_basic_noack/Makefile
+++ b/tests/test_bulk_tx_basic_noack/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_bulk_tx_basic_noack/src/main.xc b/tests/test_bulk_tx_basic_noack/src/main.xc
index 30296044..36248119 100644
--- a/tests/test_bulk_tx_basic_noack/src/main.xc
+++ b/tests/test_bulk_tx_basic_noack/src/main.xc
@@ -1,114 +1,13 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
+#include "shared.h"
-#define XUD_EP_COUNT_OUT 3
-#define XUD_EP_COUNT_IN 3
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (14)
+#endif
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
-
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
-{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
- unsigned char buffer[1024];
-
- for(int i = 10; i <= 14; i++)
- {
- SendTxPacket(ep_in, i, epNum);
- }
-
- exit(0);
-}
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- //p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- //p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- //p_txLength = array_to_xc_ptr(g_txLength);
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- //TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
-
- TestEp_Bulk(c_ep_out[2], c_ep_in[2], 1);
- }
-
- return 0;
-}
+#include "../../test_bulk_tx_basic/src/main.xc"
diff --git a/tests/test_bulk_tx_basic_noack/src/test.xn b/tests/test_bulk_tx_basic_noack/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_tx_basic_noack/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_basic_noack/src/test_xs1.xn b/tests/test_bulk_tx_basic_noack/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_tx_basic_noack/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_basic_noack/src/xc_ptr.h b/tests/test_bulk_tx_basic_noack/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_tx_basic_noack/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_tx_basic_short.py b/tests/test_bulk_tx_basic_short.py
new file mode 100644
index 00000000..949d302d
--- /dev/null
+++ b/tests/test_bulk_tx_basic_short.py
@@ -0,0 +1,31 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed, dummy_threads):
+
+ start_length = 0
+ end_length = 7
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(start_length, end_length + 1):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_tx_basic_short/Makefile b/tests/test_bulk_tx_basic_short/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_bulk_tx_basic_short/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_bulk_tx_basic_short/src/main.xc b/tests/test_bulk_tx_basic_short/src/main.xc
new file mode 100644
index 00000000..310844bd
--- /dev/null
+++ b/tests/test_bulk_tx_basic_short/src/main.xc
@@ -0,0 +1,27 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (0)
+#endif
+
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (7)
+#endif
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#include "shared.h"
+
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned fail = TestEp_Tx(c_ep_in[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
+ return fail;
+}
+
+#include "test_main.xc"
+
diff --git a/tests/test_bulk_tx_fastpacket.py b/tests/test_bulk_tx_fastpacket.py
deleted file mode 100644
index dd57ba9f..00000000
--- a/tests/test_bulk_tx_fastpacket.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016-2021 XMOS LIMITED.
-# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- ep = 3
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- data_val = 0;
- pkt_length = 20
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(10, 20):
-
- #317 lowest for valid data (non-dual issue version)
- #337 for initial dual-issue version
- AppendInToken(packets, ep, inter_pkt_gap=337)
- packets.append(RxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid))
- packets.append(TxHandshakePacket())
-
- data_val = data_val + pkt_length
- data_pid = data_pid ^ 8
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
diff --git a/tests/test_bulk_tx_fastpacket/Makefile b/tests/test_bulk_tx_fastpacket/Makefile
deleted file mode 100644
index 83edfc42..00000000
--- a/tests/test_bulk_tx_fastpacket/Makefile
+++ /dev/null
@@ -1,50 +0,0 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
diff --git a/tests/test_bulk_tx_fastpacket/src/main.xc b/tests/test_bulk_tx_fastpacket/src/main.xc
deleted file mode 100644
index eed515ad..00000000
--- a/tests/test_bulk_tx_fastpacket/src/main.xc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
-
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
-
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-#define PKT_COUNT 10
-#define INITIAL_PKT_LENGTH 10
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-#pragma unsafe arrays
-int TestEp_Bulk_Tx(chanend c_in1, int epNum1)
-{
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
-
- unsigned char buffer[PKT_COUNT][1024];
-
- int counter = 0;
- int length = INITIAL_PKT_LENGTH;
-
- for(int i = 0; i< PKT_COUNT; i++)
- {
- for(int j = 0; j < length; j++)
- {
- buffer[i][j] = counter++;
- }
- length++;
- }
-
- length = INITIAL_PKT_LENGTH;
-
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- XUD_SetBuffer(ep_in1, buffer[i], length++);
- }
-
- exit(0);
-
-}
-
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- TestEp_Bulk_Tx(c_ep_in[3], 3);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_tx_fastpacket/src/test.xn b/tests/test_bulk_tx_fastpacket/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_tx_fastpacket/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_fastpacket/src/test_xs1.xn b/tests/test_bulk_tx_fastpacket/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_tx_fastpacket/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_fastpacket/src/xc_ptr.h b/tests/test_bulk_tx_fastpacket/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_tx_fastpacket/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_tx_fastpacket_multiep.py b/tests/test_bulk_tx_fastpacket_multiep.py
deleted file mode 100644
index 586736fe..00000000
--- a/tests/test_bulk_tx_fastpacket_multiep.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2016-2021 XMOS LIMITED.
-# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- start_ep = 3
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- data_val = 0;
- pkt_length = 20
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(10, 20):
-
- #Single EP:
- #317 lowest for valid data (SI)
- #337 for initial DI version
-
- #Multi EP:
- #177 lowest for valid data (DI)
- AppendInToken(packets, start_ep, inter_pkt_gap=177)
- packets.append(RxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid))
- packets.append(TxHandshakePacket())
-
- AppendInToken(packets, start_ep+1, inter_pkt_gap=177)
- packets.append(RxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid))
- packets.append(TxHandshakePacket())
-
- AppendInToken(packets, start_ep+2, inter_pkt_gap=177)
- packets.append(RxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid))
- packets.append(TxHandshakePacket())
-
- AppendInToken(packets, start_ep+3, inter_pkt_gap=177)
- packets.append(RxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid))
- packets.append(TxHandshakePacket())
-
- data_val = data_val + pkt_length
- data_pid = data_pid ^ 8
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
diff --git a/tests/test_bulk_tx_fastpacket_multiep/Makefile b/tests/test_bulk_tx_fastpacket_multiep/Makefile
deleted file mode 100644
index 83edfc42..00000000
--- a/tests/test_bulk_tx_fastpacket_multiep/Makefile
+++ /dev/null
@@ -1,50 +0,0 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
diff --git a/tests/test_bulk_tx_fastpacket_multiep/src/main.xc b/tests/test_bulk_tx_fastpacket_multiep/src/main.xc
deleted file mode 100644
index b37e95d8..00000000
--- a/tests/test_bulk_tx_fastpacket_multiep/src/main.xc
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "shared.h"
-
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 7
-
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- TestEp_Bulk_Tx(c_ep_in[3], 3, 0);
- TestEp_Bulk_Tx(c_ep_in[4], 4, 0);
- TestEp_Bulk_Tx(c_ep_in[5], 5, 0);
- TestEp_Bulk_Tx(c_ep_in[6], 6, 1);
- }
-
- return 0;
-}
diff --git a/tests/test_bulk_tx_fastpacket_multiep/src/test.xn b/tests/test_bulk_tx_fastpacket_multiep/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_bulk_tx_fastpacket_multiep/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_fastpacket_multiep/src/test_xs1.xn b/tests/test_bulk_tx_fastpacket_multiep/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_bulk_tx_fastpacket_multiep/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_bulk_tx_fastpacket_multiep/src/xc_ptr.h b/tests/test_bulk_tx_fastpacket_multiep/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_bulk_tx_fastpacket_multiep/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_tx_multiep.py b/tests/test_bulk_tx_multiep.py
new file mode 100644
index 00000000..af36d8e3
--- /dev/null
+++ b/tests/test_bulk_tx_multiep.py
@@ -0,0 +1,70 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
+
+# EP numbers currently fixed for this test - set in params
+PARAMS = deepcopy(PARAMS)
+for k in PARAMS:
+ PARAMS[k].update({"ep": [3], "dummy_threads": [0]})
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ ied = 200
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, 20):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep + 1,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep + 2,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep + 3,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=ied,
+ )
+ )
+
+ return session
diff --git a/tests/test_bulk_tx_multiep/Makefile b/tests/test_bulk_tx_multiep/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_bulk_tx_multiep/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_bulk_tx_multiep/src/main.xc b/tests/test_bulk_tx_multiep/src/main.xc
new file mode 100644
index 00000000..81d5c067
--- /dev/null
+++ b/tests/test_bulk_tx_multiep/src/main.xc
@@ -0,0 +1,46 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#define EP_COUNT_OUT (5)
+#define EP_COUNT_IN (8)
+
+#define PKT_LENGTH_START (10)
+#define PKT_LENGTH_END (19)
+
+#include "shared.h"
+
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL};
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned fail[4];
+
+ par
+ {
+ fail[0] = TestEp_Tx(c_ep_in[3], 3, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
+ fail[1] = TestEp_Tx(c_ep_in[4], 4, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
+ fail[2] = TestEp_Tx(c_ep_in[5], 5, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
+ fail[3] = TestEp_Tx(c_ep_in[6], 6, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
+ }
+
+ for(size_t i = 0; i < 4; i++)
+ fail[0] |= fail[i];
+
+ return fail[0];
+}
+
+#include "test_main.xc"
+
+
diff --git a/tests/test_control_basic_badcrc32.py b/tests/test_control_basic_badcrc32.py_
similarity index 59%
rename from tests/test_control_basic_badcrc32.py
rename to tests/test_control_basic_badcrc32.py_
index 8f9c0b08..8d2779c0 100644
--- a/tests/test_control_basic_badcrc32.py
+++ b/tests/test_control_basic_badcrc32.py_
@@ -12,7 +12,7 @@
# Single, setup transaction to EP 0
-def do_test(arch, tx_clk, tx_phy, seed):
+def do_test(arch, tx_clk, tx_phy, data_valid_count, usb_speed, seed):
rand = random.Random()
rand.seed(seed)
@@ -25,33 +25,33 @@ def do_test(arch, tx_clk, tx_phy, seed):
AppendSetupToken(packets, ep)
# DATA0 data packet with bad CRC
- packets.append(TxDataPacket(rand, length=8, pid=3, bad_crc=True))
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=8, pid=3, bad_crc=True))
# Dont expect an ACK due to bad CRC
#packets.append(RxHandshakePacket())
AppendSetupToken(packets, ep, inter_pkt_gap=400)
- packets.append(TxDataPacket(rand, length=8, pid=3, bad_crc=False ))
- packets.append(RxHandshakePacket(timeout=11))
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=8, pid=3, bad_crc=False ))
+ packets.append(RxHandshakePacket(data_valid_count=data_valid_count, timeout=11))
# Note, quite big gap to allow checking.
AppendOutToken(packets, ep, inter_pkt_gap=2000)
- packets.append(TxDataPacket(rand, length=10, pid=0xb))
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=10, pid=0xb))
- packets.append(RxHandshakePacket())
+ packets.append(RxHandshakePacket(data_valid_count=data_valid_count))
#IN
AppendInToken(packets, ep, inter_pkt_gap=500)
#Expect 0-length
- packets.append(RxDataPacket(rand, length=0, pid=0x4b))
+ packets.append(RxDataPacket(rand, data_valid_count=data_valid_count, length=0, pid=0x4b))
# Send ACK
- packets.append(TxHandshakePacket())
+ packets.append(TxHandshakePacket(data_valid_count=data_valid_count))
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
+ do_rx_test(arch, tx_clk, tx_phy, usb_speed, packets, __file__, seed,
level='smoke', extra_tasks=[])
def runtest():
diff --git a/tests/test_control_basic_badcrc32/Makefile b/tests/test_control_basic_badcrc32/Makefile
index 83edfc42..f0398897 100644
--- a/tests/test_control_basic_badcrc32/Makefile
+++ b/tests/test_control_basic_badcrc32/Makefile
@@ -24,16 +24,8 @@ COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -X
XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
+ TARGET = test_xs2.xn
endif
diff --git a/tests/test_control_basic_badcrc32/src/main.xc b/tests/test_control_basic_badcrc32/src/main.xc
index 3157c062..d57acc45 100644
--- a/tests/test_control_basic_badcrc32/src/main.xc
+++ b/tests/test_control_basic_badcrc32/src/main.xc
@@ -12,15 +12,11 @@
#include
#include "xud.h"
#include "platform.h"
-//#include "test.h"
#include "xc_ptr.h"
-//#error
-
#define XUD_EP_COUNT_OUT 5
#define XUD_EP_COUNT_IN 5
-//extern xc_ptr char_array_to_xc_ptr(const unsigned char a[]);
/* Endpoint type tables */
XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
@@ -30,12 +26,6 @@ XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
XUD_EPTYPE_BUL};
XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-/* USB Port declarations */
-//on stdcore[0]: out port p_usb_rst = XS1_PORT_1A;
-//on stdcore[0]: clock clk = XS1_CLKBLK_3;
-
-//on stdcore[0] : out port p_test = XS1_PORT_1I;
-
void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
void exit(int);
@@ -67,32 +57,15 @@ unsigned g_txLength[5] = {0,0,0,0,0};
void SendTxPacket(XUD_ep ep, int length, int epNum)
{
unsigned char buffer[1024];
- unsigned char x;
for (int i = 0; i < length; i++)
{
buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
}
XUD_SetBuffer(ep, buffer, length);
}
-
-
-
-
-//xc_ptr p_rxDataCheck;
-//xc_ptr p_txDataCheck;
-//xc_ptr p_txLength;
-
#pragma unsafe arrays
int RxDataCheck(unsigned char b[], int l, int epNum)
{
@@ -116,9 +89,6 @@ int RxDataCheck(unsigned char b[], int l, int epNum)
}
g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
}
return 0;
@@ -218,19 +188,13 @@ int TestEp_Control(chanend c_out, chanend c_in, int epNum)
int main()
{
chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- //p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- //p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- //p_txLength = array_to_xc_ptr(g_txLength);
par
{
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
}
diff --git a/tests/test_control_basic_badcrc32/src/test.xn b/tests/test_control_basic_badcrc32/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_control_basic_badcrc32/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_basic_badcrc32/src/test_xs1.xn b/tests/test_control_basic_badcrc32/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_control_basic_badcrc32/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_basic_get.py b/tests/test_control_basic_get.py
index 0beb8897..57f40c2a 100644
--- a/tests/test_control_basic_get.py
+++ b/tests/test_control_basic_get.py
@@ -1,56 +1,75 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import (
+ TokenPacket,
+ TxDataPacket,
+ RxDataPacket,
+ TxHandshakePacket,
+ RxHandshakePacket,
+ USB_PID,
+)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
-import random
-import xmostest
-from usb_packet import AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
+# Only test on EP 0 - Update params
+PARAMS = deepcopy(PARAMS)
+for k in PARAMS:
+ PARAMS[k].update({"ep": [0]})
-# Single, setup transaction to EP 0
+@pytest.fixture
+def test_session(ep, address, bus_speed):
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
+ ied = 500
- ep = 0
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
# SETUP transaction
- AppendSetupToken(packets, ep)
- packets.append(TxDataPacket(rand, length=8, pid=3))
- packets.append(RxHandshakePacket(timeout=11))
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 8),
+ pid=USB_PID["DATA0"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
# IN transaction
- # Note, quite big gap to allow checking.
- packets.append(TokenPacket(
- inter_pkt_gap=2000,
- pid=0x69, #IN
- endpoint=ep))
- packets.append(RxDataPacket(rand, length=10, pid=0x4b))
- packets.append(TxHandshakePacket())
-
- # Send 0 length OUT transaction
- packets.append(TokenPacket(
- inter_pkt_gap=2000,
- pid=0xe1, #OUT
- endpoint=ep))
- packets.append(TxDataPacket(rand, length=0, pid=0xb))
- packets.append(RxHandshakePacket())
-
-
-
- # Send ACK
- packets.append(TxHandshakePacket())
-
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ # Note, quite big gap to avoid nak
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=10000,
+ )
+ )
+ session.add_event(
+ RxDataPacket(
+ dataPayload=session.getPayload_in(ep, 10),
+ pid=USB_PID["DATA1"],
+ )
+ )
+ session.add_event(TxHandshakePacket())
+
+ # Send 0 length OUT transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["OUT"], address=address, endpoint=ep, interEventDelay=ied
+ )
+ )
+ session.add_event(TxDataPacket(length=0, pid=USB_PID["DATA1"]))
+ session.add_event(RxHandshakePacket())
+
+ return session
diff --git a/tests/test_control_basic_get/Makefile b/tests/test_control_basic_get/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_control_basic_get/Makefile
+++ b/tests/test_control_basic_get/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_control_basic_get/src/main.xc b/tests/test_control_basic_get/src/main.xc
index 36f63ebb..e5657420 100644
--- a/tests/test_control_basic_get/src/main.xc
+++ b/tests/test_control_basic_get/src/main.xc
@@ -1,111 +1,68 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
#include "shared.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (5)
+#define EP_COUNT_IN (5)
/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
XUD_EPTYPE_BUL,
XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-/* Out EP Should receive some data, perform some test process (crc or similar) to check okay */
-/* Answers should be responded to in the IN ep */
-int TestEp_Control(chanend c_out, chanend c_in, int epNum)
+int TestEp_Control(XUD_ep c_ep0_out, XUD_ep c_ep0_in, int epNum)
{
unsigned int slength;
unsigned int length;
+ XUD_Result_t sres;
XUD_Result_t res;
- XUD_ep c_ep0_out = XUD_InitEp(c_out);
- XUD_ep c_ep0_in = XUD_InitEp(c_in);
-
/* Buffer for Setup data */
+ unsigned char sbuffer[120];
unsigned char buffer[120];
unsafe
{
/* Wait for Setup data */
- res = XUD_GetControlBuffer(c_ep0_out, buffer, slength);
-
- if(slength != 8)
- {
- printintln(length);
- fail(FAIL_RX_DATAERROR);
- }
-
- if(res != XUD_RES_CTL)
- {
- fail(FAIL_RX_EXPECTED_CTL);
- }
-
- if(RxDataCheck(buffer, slength, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
+ sres = XUD_GetSetupBuffer(c_ep0_out, sbuffer, slength);
- /* Send 0 length back */
- res = SendControlPacket(c_ep0_in, 10, epNum);
+ res = SendTxPacket(c_ep0_in, 10, epNum);
- if(res != XUD_RES_OKAY)
- {
- fail(FAIL_RX_BAD_RETURN_CODE);
- }
+ res = XUD_GetBuffer(c_ep0_out, buffer, length);
- res = XUD_GetControlBuffer(c_ep0_out, buffer, slength);
-
- if(slength != 0)
+ if(length != 0)
{
- fail(FAIL_RX_DATAERROR);
+ return FAIL_RX_DATAERROR;
}
-
- if(RxDataCheck(buffer, length, epNum))
+
+ /* Do some checking */
+ if(res != XUD_RES_OKAY)
{
- fail(FAIL_RX_DATAERROR);
+ return FAIL_RX_BAD_RETURN_CODE;
}
- if(res != XUD_RES_OKAY)
+ if(RxDataCheck(sbuffer, slength, epNum, 8))
{
- fail(FAIL_RX_BAD_RETURN_CODE);
+ return FAIL_RX_DATAERROR;
}
- exit(0);
+ return 0;
}
}
-#define USB_CORE 0
-int main()
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
+ XUD_ep c_ep0_out = XUD_InitEp(c_ep_out[0]);
+ XUD_ep c_ep0_in = XUD_InitEp(c_ep_in[0]);
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ unsigned failed = TestEp_Control(c_ep0_out, c_ep0_in, 0);
- TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
- }
-
- return 0;
+ XUD_Kill(c_ep0_out);
+ return failed;
}
+#include "test_main.xc"
+
diff --git a/tests/test_control_basic_get/src/test.xn b/tests/test_control_basic_get/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_control_basic_get/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_basic_get/src/test_xs1.xn b/tests/test_control_basic_get/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_control_basic_get/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_basic_get/src/xc_ptr.h b/tests/test_control_basic_get/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_control_basic_get/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_control_basic_set.py b/tests/test_control_basic_set.py
index cebbfd9f..b34ae639 100644
--- a/tests/test_control_basic_set.py
+++ b/tests/test_control_basic_set.py
@@ -1,56 +1,78 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import (
+ TokenPacket,
+ TxDataPacket,
+ RxDataPacket,
+ TxHandshakePacket,
+ RxHandshakePacket,
+ USB_PID,
+)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
-import random
-import xmostest
-from usb_packet import AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
+# Only test on EP 0 - Update params
+PARAMS = deepcopy(PARAMS)
+for k in PARAMS:
+ PARAMS[k].update({"ep": [0]})
-# Single, setup transaction to EP 0
+@pytest.fixture
+def test_session(ep, address, bus_speed, dummy_threads):
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
+ ied = 500
- ep = 0
+ # if bus_speed == "HS" and dummy_threads > 4:
+ # pytest.xfail("Known fail when dummy threads > 4")
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
- AppendSetupToken(packets, ep)
+ # SETUP transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 8),
+ pid=USB_PID["DATA0"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
- packets.append(TxDataPacket(rand, length=8, pid=3))
- packets.append(RxHandshakePacket(timeout=11))
+ # OUT transaction
+ # Note, quite big gap to avoid nak
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["OUT"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=10000,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 10),
+ pid=USB_PID["DATA1"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
- # Note, quite big gap to allow checking.
+ # Expect 0 length IN transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"], address=address, endpoint=ep, interEventDelay=ied
+ )
+ )
+ session.add_event(RxDataPacket(dataPayload=[], pid=USB_PID["DATA1"]))
+ session.add_event(TxHandshakePacket())
- packets.append(TokenPacket(
- inter_pkt_gap=2000,
- pid=0xe1, #OUT
- endpoint=ep))
-
- packets.append(TxDataPacket(rand, length=10, pid=0xb))
-
- packets.append(RxHandshakePacket())
-
- packets.append(TokenPacket(
- inter_pkt_gap=2000,
- pid=0x69, #IN
- endpoint=ep))
-
- #Expect 0-length
- packets.append(RxDataPacket(rand, length=0, pid=0x4b))
-
- # Send ACK
- packets.append(TxHandshakePacket())
-
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ return session
diff --git a/tests/test_control_basic_set/Makefile b/tests/test_control_basic_set/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_control_basic_set/Makefile
+++ b/tests/test_control_basic_set/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_control_basic_set/src/main.xc b/tests/test_control_basic_set/src/main.xc
index 6b557037..4ed5b9df 100644
--- a/tests/test_control_basic_set/src/main.xc
+++ b/tests/test_control_basic_set/src/main.xc
@@ -1,111 +1,68 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
#include "shared.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (5)
+#define EP_COUNT_IN (5)
/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-
-/* Out EP Should receive some data, perform some test process (crc or similar) to check okay */
-/* Answers should be responded to in the IN ep */
-
-int TestEp_Control(chanend c_out, chanend c_in, int epNum)
+int TestEp_Control(XUD_ep c_ep0_out, XUD_ep c_ep0_in, int epNum)
{
unsigned int slength;
unsigned int length;
+
+ XUD_Result_t sres;
XUD_Result_t res;
- XUD_ep c_ep0_out = XUD_InitEp(c_out);
- XUD_ep c_ep0_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
+ unsigned char sbuffer[120];
unsigned char buffer[120];
unsafe
{
/* Wait for Setup data */
- res = XUD_GetControlBuffer(c_ep0_out, buffer, slength);
-
- if(slength != 8)
- {
- printintln(length);
- fail(FAIL_RX_DATAERROR);
- }
-
- if(res != XUD_RES_CTL)
- {
- fail(FAIL_RX_EXPECTED_CTL);
- }
+ sres = XUD_GetSetupBuffer(c_ep0_out, sbuffer, slength);
- if(RxDataCheck(buffer, slength, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
+ res = XUD_GetBuffer(c_ep0_out, buffer, length);
- res = XUD_GetControlBuffer(c_ep0_out, buffer, slength);
+ res = SendTxPacket(c_ep0_in, 0, epNum);
- if(slength != 10)
+ /* Checking for the Setup */
+ if(sres != XUD_RES_OKAY)
{
- fail(FAIL_RX_DATAERROR);
+ return 1;
}
- if(RxDataCheck(buffer, length, epNum))
+ if(RxDataCheck(sbuffer, slength, epNum, 8))
{
- fail(FAIL_RX_DATAERROR);
+ return 1;
}
+ /* Checking for the OUT buffer */
if(res != XUD_RES_OKAY)
{
- fail(FAIL_RX_BAD_RETURN_CODE);
+ return 1;
}
-
- /* Send 0 length back */
- res = SendControlPacket(c_ep0_in, 0, epNum);
-
- if(res != XUD_RES_OKAY)
+
+ if(RxDataCheck(buffer, length, epNum, 10))
{
- fail(FAIL_RX_BAD_RETURN_CODE);
+ return 1;
}
- exit(0);
+ return 0;
}
}
-#define USB_CORE 0
-int main()
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_ep c_ep0_out = XUD_InitEp(c_ep_out[0]);
+ XUD_ep c_ep0_in = XUD_InitEp(c_ep_in[0]);
- TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
- }
+ unsigned failed = TestEp_Control(c_ep0_out, c_ep0_in, 0);
- return 0;
+ XUD_Kill(c_ep0_out);
+ return failed;
}
+#include "test_main.xc"
diff --git a/tests/test_control_basic_set/src/test.xn b/tests/test_control_basic_set/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_control_basic_set/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_basic_set/src/test_xs1.xn b/tests/test_control_basic_set/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_control_basic_set/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_basic_short.py b/tests/test_control_basic_short.py_
similarity index 60%
rename from tests/test_control_basic_short.py
rename to tests/test_control_basic_short.py_
index 3e5bcce2..5da143de 100644
--- a/tests/test_control_basic_short.py
+++ b/tests/test_control_basic_short.py_
@@ -15,7 +15,7 @@
# Single, setup transaction to EP 0
-def do_test(arch, tx_clk, tx_phy, seed):
+def do_test(arch, tx_clk, tx_phy, data_valid_count, usb_speed, seed):
rand = random.Random()
rand.seed(seed)
@@ -26,38 +26,40 @@ def do_test(arch, tx_clk, tx_phy, seed):
packets = []
AppendSetupToken(packets, ep)
- packets.append(TxDataPacket(rand, length=3, pid=3, bad_crc=True))
- #packets.append(RxHandshakePacket())
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=3, pid=3, bad_crc=True))
+ #packets.append(RxHandshakePacket(data_valid_count=data_valid_count))
AppendSetupToken(packets, ep)
- packets.append(TxDataPacket(rand, length=8, pid=3, bad_crc=False))
- packets.append(RxHandshakePacket(timeout=11))
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=8, pid=3, bad_crc=False))
+ packets.append(RxHandshakePacket(data_valid_count=data_valid_count, timeout=11))
# Note, quite big gap to allow checking.
packets.append(TokenPacket(
+ data_valid_count=data_valid_count,
inter_pkt_gap=2000,
pid=0xe1, #OUT
address=dev_address,
endpoint=ep))
- packets.append(TxDataPacket(rand, length=10, pid=0xb))
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=10, pid=0xb))
- packets.append(RxHandshakePacket())
+ packets.append(RxHandshakePacket(data_valid_count=data_valid_count))
packets.append(TokenPacket(
+ data_valid_count=data_valid_count,
inter_pkt_gap=2000,
pid=0x69, #OUT
address=dev_address,
endpoint=ep))
#Expect 0-length
- packets.append(RxDataPacket(rand, length=0, pid=0x4b))
+ packets.append(RxDataPacket(rand, data_valid_count=data_valid_count, length=0, pid=0x4b))
# Send ACK
- packets.append(TxHandshakePacket())
+ packets.append(TxHandshakePacket(data_valid_count=data_valid_count))
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
+ do_rx_test(arch, tx_clk, tx_phy, usb_speed, packets, __file__, seed,
level='smoke', extra_tasks=[])
def runtest():
diff --git a/tests/test_control_basic_short/Makefile b/tests/test_control_basic_short/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_control_basic_short/Makefile
+++ b/tests/test_control_basic_short/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_control_basic_short/src/main.xc b/tests/test_control_basic_short/src/main.xc
index 3157c062..cf20ea0f 100644
--- a/tests/test_control_basic_short/src/main.xc
+++ b/tests/test_control_basic_short/src/main.xc
@@ -230,7 +230,7 @@ int main()
XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
}
diff --git a/tests/test_control_basic_short/src/test.xn b/tests/test_control_basic_short/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_control_basic_short/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_basic_short/src/test_xs1.xn b/tests/test_control_basic_short/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_control_basic_short/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_repeatedsetup.py b/tests/test_control_repeatedsetup.py_
similarity index 57%
rename from tests/test_control_repeatedsetup.py
rename to tests/test_control_repeatedsetup.py_
index 5148674f..aec6de1f 100644
--- a/tests/test_control_repeatedsetup.py
+++ b/tests/test_control_repeatedsetup.py_
@@ -12,7 +12,7 @@
# Single, setup transaction to EP 0
-def do_test(arch, tx_clk, tx_phy, seed):
+def do_test(arch, tx_clk, tx_phy, data_valid_count, usb_speed, seed):
rand = random.Random()
rand.seed(seed)
@@ -22,35 +22,37 @@ def do_test(arch, tx_clk, tx_phy, seed):
packets = []
AppendSetupToken(packets, ep)
- packets.append(TxDataPacket(rand, length=8, pid=3))
- packets.append(RxHandshakePacket(timeout=11))
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=8, pid=3))
+ packets.append(RxHandshakePacket(data_valid_count=data_valid_count, timeout=11))
# Note, quite big gap to allow checking.
# Send Setup transaction again (simulated ACK lost on way to host
AppendSetupToken(packets, ep, inter_pkt_gap=2000)
- packets.append(TxDataPacket(rand, length=8, pid=3))
- packets.append(RxHandshakePacket(timeout=11))
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=8, pid=3))
+ packets.append(RxHandshakePacket(data_valid_count=data_valid_count, timeout=11))
packets.append(TokenPacket(
+ data_valid_count=data_valid_count,
inter_pkt_gap=2000,
pid=0xe1, #OUT
endpoint=ep))
- packets.append(TxDataPacket(rand, length=10, pid=0xb))
- packets.append(RxHandshakePacket())
+ packets.append(TxDataPacket(rand, data_valid_count=data_valid_count, length=10, pid=0xb))
+ packets.append(RxHandshakePacket(data_valid_count=data_valid_count))
packets.append(TokenPacket(
+ data_valid_count=data_valid_count,
inter_pkt_gap=2000,
pid=0x69, #IN
endpoint=ep))
#Expect 0-length
- packets.append(RxDataPacket(rand, length=0, pid=0x4b))
+ packets.append(RxDataPacket(rand, data_valid_count=data_valid_count, length=0, pid=0x4b))
# Send ACK
- packets.append(TxHandshakePacket())
+ packets.append(TxHandshakePacket(data_valid_count=data_valid_count))
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
+ do_rx_test(arch, tx_clk, tx_phy, usb_speed, packets, __file__, seed,
level='smoke', extra_tasks=[])
def runtest():
diff --git a/tests/test_control_repeatedsetup/Makefile b/tests/test_control_repeatedsetup/Makefile
index 83edfc42..f0398897 100644
--- a/tests/test_control_repeatedsetup/Makefile
+++ b/tests/test_control_repeatedsetup/Makefile
@@ -24,16 +24,8 @@ COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -X
XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
+ TARGET = test_xs2.xn
endif
diff --git a/tests/test_control_repeatedsetup/src/main.xc b/tests/test_control_repeatedsetup/src/main.xc
index af070c7a..baa95519 100644
--- a/tests/test_control_repeatedsetup/src/main.xc
+++ b/tests/test_control_repeatedsetup/src/main.xc
@@ -128,7 +128,7 @@ int main()
par
{
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ XUD_Main( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
diff --git a/tests/test_control_repeatedsetup/src/test.xn b/tests/test_control_repeatedsetup/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_control_repeatedsetup/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_repeatedsetup/src/test_xs1.xn b/tests/test_control_repeatedsetup/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_control_repeatedsetup/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_control_traffic.py b/tests/test_control_traffic.py
new file mode 100644
index 00000000..37f38ce4
--- /dev/null
+++ b/tests/test_control_traffic.py
@@ -0,0 +1,117 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import (
+ TokenPacket,
+ TxDataPacket,
+ RxDataPacket,
+ TxHandshakePacket,
+ RxHandshakePacket,
+ USB_PID,
+)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
+
+# Only test on EP 0 - Update params
+PARAMS = deepcopy(PARAMS)
+for v in PARAMS.values():
+ v.update({"ep": [0]})
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ ied = 500
+
+ trafficAddress1 = (address + 1) % 128
+ trafficAddress2 = (address + 127) % 128
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # SETUP to another address (Note, DUT would not see ACK)
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=trafficAddress1,
+ endpoint=ep,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=[1, 2, 3, 4, 5, 6, 7, 8],
+ pid=USB_PID["DATA0"],
+ )
+ )
+
+ # SETUP transaction to DUT
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 8),
+ pid=USB_PID["DATA0"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
+
+ # IN transaction
+ # Note, quite big gap to avoid nak
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=10000,
+ )
+ )
+ session.add_event(
+ RxDataPacket(
+ dataPayload=session.getPayload_in(ep, 10),
+ pid=USB_PID["DATA1"],
+ )
+ )
+ session.add_event(TxHandshakePacket())
+
+ # SETUP to another address (Note, DUT would not see ACK)
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=trafficAddress2,
+ endpoint=ep,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=[1, 2, 3, 4, 5, 6, 7, 8],
+ pid=USB_PID["DATA0"],
+ )
+ )
+
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"],
+ address=trafficAddress2,
+ endpoint=ep,
+ interEventDelay=1000,
+ )
+ )
+
+ # Send 0 length OUT transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["OUT"], address=address, endpoint=ep, interEventDelay=ied
+ )
+ )
+ session.add_event(TxDataPacket(length=0, pid=USB_PID["DATA1"]))
+ session.add_event(RxHandshakePacket())
+
+ return session
diff --git a/tests/test_control_traffic/Makefile b/tests/test_control_traffic/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_control_traffic/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_control_traffic/src/main.xc b/tests/test_control_traffic/src/main.xc
new file mode 100644
index 00000000..46893c3f
--- /dev/null
+++ b/tests/test_control_traffic/src/main.xc
@@ -0,0 +1,6 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "shared.h"
+
+#include "../test_control_basic_get/src/main.xc"
+
diff --git a/tests/test_device_attach.py b/tests/test_device_attach.py
new file mode 100644
index 00000000..d4b653e9
--- /dev/null
+++ b/tests/test_device_attach.py
@@ -0,0 +1,64 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import CreateSofToken
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+from usb_signalling import UsbDeviceAttach
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
+
+# Only need to run device attach tests for one ep/address
+PARAMS = deepcopy(PARAMS)
+for k in PARAMS:
+ PARAMS[k].update({"ep": [1], "address": [1]})
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ start_length = 10
+ end_length = 12
+ pktLength = 10
+ frameNumber = 52 # Note, for frame number 52 we expect A5 34 40 on the bus
+
+ session = UsbSession(
+ bus_speed=bus_speed,
+ run_enumeration=False,
+ device_address=address,
+ initial_delay=19000,
+ )
+
+ session.add_event(UsbDeviceAttach())
+
+ session.add_event(CreateSofToken(frameNumber, interEventDelay=100))
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=0,
+ )
+ )
+
+ frameNumber = frameNumber + 1
+ pktLength = pktLength + 1
+
+ session.add_event(CreateSofToken(frameNumber))
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=0,
+ )
+ )
+
+ return session
diff --git a/tests/test_device_attach/Makefile b/tests/test_device_attach/Makefile
new file mode 100644
index 00000000..920b679a
--- /dev/null
+++ b/tests/test_device_attach/Makefile
@@ -0,0 +1,4 @@
+
+TEST_FLAGS = -DSUSPEND_TIMEOUT_us=300 -DSUSPEND_T_WTWRSTHS_us=20 -DT_FILT_us=1 -DINVALID_DELAY_us=100
+
+include ../test_makefile.mak
diff --git a/tests/test_device_attach/src/main.xc b/tests/test_device_attach/src/main.xc
new file mode 100644
index 00000000..0ff38feb
--- /dev/null
+++ b/tests/test_device_attach/src/main.xc
@@ -0,0 +1,69 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#include
+#include
+#include
+#include "xud.h"
+#include "platform.h"
+#include "shared.h"
+
+#define XUD_EP_COUNT_OUT 5
+#define XUD_EP_COUNT_IN 5
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START 10
+#endif
+
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END 11
+#endif
+
+#ifndef TEST_EP_NUM
+#define TEST_EP_NUM 1
+#endif
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+#ifdef XUD_SIM_RTL
+int testmain()
+#else
+int main()
+#endif
+{
+ chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
+
+ par
+ {
+ {
+ #if defined(XUD_TEST_SPEED_FS)
+ unsigned speed = XUD_SPEED_FS;
+ #elif defined(XUD_TEST_SPEED_HS)
+ unsigned speed = XUD_SPEED_HS;
+ #else
+ #error XUD_TEST_SPEED_XX not defined
+ #endif
+
+ XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ null, epTypeTableOut, epTypeTableIn, speed, XUD_PWR_BUS);
+ }
+
+ {
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
+
+
+ XUD_ep ep0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep0);
+
+ if(fail)
+ TerminateFail(fail);
+ else
+ TerminatePass(fail);
+
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/test_invalidtoken.py b/tests/test_invalidtoken.py
index 43e6d103..e868c4ed 100644
--- a/tests/test_invalidtoken.py
+++ b/tests/test_invalidtoken.py
@@ -1,104 +1,132 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
# Same as simple RX bulk test but some invalid tokens also included
-
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-
-# Single, setup transaction to EP 0
-
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- dev_address = get_dut_address()
- ep = 1
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- # Reserved PID
- packets.append(TokenPacket(
- inter_pkt_gap=2000,
- pid=0x0,
- address=dev_address,
- endpoint=ep))
-
- # Valid IN but not for us..
- packets.append(TokenPacket(
- inter_pkt_gap=200,
- pid=0x69,
- address=dev_address,
- endpoint=ep,
- valid=False))
-
- # Valid OUT but not for us..
- packets.append(TokenPacket(
- inter_pkt_gap=200,
- pid=0xe1,
- address=dev_address,
- endpoint=ep,
- valid=False))
-
- AppendOutToken(packets, ep)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
+from usb_packet import (
+ TokenPacket,
+ TxDataPacket,
+ RxDataPacket,
+ TxHandshakePacket,
+ RxHandshakePacket,
+ USB_PID,
+)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # Reserved/Invalid PID
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["RESERVED"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+
+ # Valid IN but not for DUT
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"],
+ address=address + 1,
+ endpoint=ep,
+ )
+ )
+
+ # Valid OUT but not for DUT
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["OUT"],
+ address=address + 1,
+ endpoint=ep,
+ )
+ )
+
+ # Valid OUT transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
# Valid SETUP but not for us..
- packets.append(TokenPacket(
- inter_pkt_gap=200,
- pid=0x2d,
- address=dev_address,
- endpoint=ep,
- valid=False))
-
-
-
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=address + 2,
+ endpoint=ep,
+ )
+ )
+
+ # Valid OUT transaction
# Note, quite big gap to allow checking.
-
- dataval += 10
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=6000,
+ )
+ )
# Valid PING but not for us..
- packets.append(TokenPacket(
- inter_pkt_gap=200,
- pid=0xb4,
- address=dev_address,
- endpoint=ep,
- valid=False))
-
-
-
- dataval += 11
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
- dataval += 12
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=13, pid=0xb)) #DATA1
- packets.append(RxHandshakePacket())
-
- dataval += 13
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
-
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address + 2,
+ endpoint=ep,
+ )
+ )
+
+ # Finish with some valid transactions
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=12,
+ interEventDelay=6000,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=13,
+ interEventDelay=6000,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=14,
+ interEventDelay=6000,
+ )
+ )
+
+ return session
diff --git a/tests/test_invalidtoken/Makefile b/tests/test_invalidtoken/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_invalidtoken/Makefile
+++ b/tests/test_invalidtoken/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_invalidtoken/src/main.xc b/tests/test_invalidtoken/src/main.xc
index fbc71f2d..8c3dd36c 100644
--- a/tests/test_invalidtoken/src/main.xc
+++ b/tests/test_invalidtoken/src/main.xc
@@ -1,33 +1,28 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
+
#include
#include
#include
#include "xud.h"
#include "platform.h"
-//#include "test.h"
-#include "xc_ptr.h"
-
-//#error
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
-//extern xc_ptr char_array_to_xc_ptr(const unsigned char a[]);
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL};
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL,
+ XUD_EPTYPE_BUL};
void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
@@ -43,11 +38,11 @@ unsigned fail(int x)
switch(x)
{
case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
+ printstr("XCORE RX Data Error\n");
break;
case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
+ printstr("XCORE RX Length Error\n");
break;
}
@@ -55,41 +50,11 @@ unsigned fail(int x)
exit(1);
}
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
+unsigned char g_rxDataCheck[EP_COUNT_OUT] = {0};
+unsigned char g_txDataCheck[EP_COUNT_IN] = {0};
+unsigned g_txLength[EP_COUNT_IN] = {0};
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-
-
-
-
-//xc_ptr p_rxDataCheck;
-//xc_ptr p_txDataCheck;
-//xc_ptr p_txLength;
-
#pragma unsafe arrays
int RxDataCheck(unsigned char b[], int l, int epNum)
{
@@ -113,19 +78,17 @@ int RxDataCheck(unsigned char b[], int l, int epNum)
}
g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
}
return 0;
}
-int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
+int TestEp_Bulk(chanend c_out, chanend c_in, int epNum, chanend c_out_0)
{
unsigned int length;
XUD_Result_t res;
+ XUD_ep ep_out_0 = XUD_InitEp(c_out_0);
XUD_ep ep_out = XUD_InitEp(c_out);
XUD_ep ep_in = XUD_InitEp(c_in);
@@ -149,31 +112,23 @@ int TestEp_Bulk(chanend c_out, chanend c_in, int epNum)
}
+ XUD_Kill(ep_out_0);
exit(0);
}
-
-#define USB_CORE 0
int main()
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- //p_rxDataCheck = char_array_to_xc_ptr(g_rxDataCheck);
- //p_txDataCheck = char_array_to_xc_ptr(g_txDataCheck);
- //p_txLength = array_to_xc_ptr(g_txLength);
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
par
{
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ XUD_Main( c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
- //TestEp_Control(c_ep_out[0], c_ep_in[0], 0);
- TestEp_Bulk(c_ep_out[1], c_ep_in[1], 1);
+ TestEp_Bulk(c_ep_out[TEST_EP_NUM], c_ep_in[TEST_EP_NUM], TEST_EP_NUM, c_ep_out[0]);
}
return 0;
diff --git a/tests/test_invalidtoken/src/test.xn b/tests/test_invalidtoken/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_invalidtoken/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_invalidtoken/src/test_xs1.xn b/tests/test_invalidtoken/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_invalidtoken/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_loopback.py b/tests/test_iso_loopback.py
index 9204b97b..f3af6362 100644
--- a/tests/test_iso_loopback.py
+++ b/tests/test_iso_loopback.py
@@ -1,56 +1,74 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
-
- rand = random.Random()
- rand.seed(seed)
-
- ep_loopback = 3
- ep_loopback_kill = 2
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(200, 204):
-
- AppendOutToken(packets, ep_loopback)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=pkt_length, pid=data_pid)) #DATA0
-
- #XXwas min IPG supported on iso loopback to not nak
- #This was 420, had to increase when moved to lib_xud (14.1.2 tools)
- # increased again from 437 when SETUP/OUT checking added
- AppendInToken(packets, ep_loopback, inter_pkt_gap=477)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=pkt_length, pid=data_pid, timeout=9)) #DATA0
- #No toggle for Iso
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ ep_loopback = ep
+ ep_loopback_kill = ep + 1
- pkt_length = 10
+ start_length = 200
+ end_length = 203
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
- #Loopback and die..
- AppendOutToken(packets, ep_loopback_kill)
- packets.append(TxDataPacket(rand, length=pkt_length, pid=3)) #DATA0
- packets.append(RxHandshakePacket())
-
- AppendInToken(packets, ep_loopback_kill, inter_pkt_gap=397)
- packets.append(RxDataPacket(rand, length=pkt_length, pid=3)) #DATA0
- packets.append(TxHandshakePacket())
+ # TODO randomise packet lengths and data
+ for pktLength in range(start_length, end_length + 1):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback,
+ endpointType="ISO",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ # Was min IPG supported on iso loopback to not nak
+ # This was 420, had to increase when moved to lib_xud (14.1.2 tools)
+ # increased again from 437 when SETUP/OUT checking added
+ # increaed from 477 when adding xs3
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback,
+ endpointType="ISO",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=498,
+ )
+ )
+ pktLength = 10
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
+ # Loopback and die..
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback_kill,
+ endpointType="ISO",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_loopback_kill,
+ endpointType="ISO",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ return session
diff --git a/tests/test_iso_loopback/Makefile b/tests/test_iso_loopback/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_iso_loopback/Makefile
+++ b/tests/test_iso_loopback/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_iso_loopback/src/main.xc b/tests/test_iso_loopback/src/main.xc
index bd737f50..5e95c6dc 100644
--- a/tests/test_iso_loopback/src/main.xc
+++ b/tests/test_iso_loopback/src/main.xc
@@ -1,34 +1,25 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
#include
#include
#include
#include "xud.h"
#include "platform.h"
-#include "xc_ptr.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL};
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO};
void exit(int);
+#define KILL_EP_NUM (TEST_EP_NUM +1)
/* Loopback packets forever */
#pragma unsafe arrays
-int TestEp_Bulk(chanend c_out1, chanend c_in1)
+int TestEp_LoopbackForever(chanend c_out1, chanend c_in1)
{
unsigned int length;
XUD_Result_t res;
@@ -36,7 +27,6 @@ int TestEp_Bulk(chanend c_out1, chanend c_in1)
XUD_ep ep_out1 = XUD_InitEp(c_out1);
XUD_ep ep_in1 = XUD_InitEp(c_in1);
- /* Buffer for Setup data */
unsigned char buffer[1024];
while(1)
@@ -51,39 +41,36 @@ int TestEp_Bulk(chanend c_out1, chanend c_in1)
/* Loopback packet and terminate */
#pragma unsafe arrays
-int TestEp_Bulk2(chanend c_out, chanend c_in)
+int TestEp_LoopbackOnce(chanend c_out, chanend c_in, chanend c_out_0)
{
unsigned int length;
XUD_Result_t res;
+ XUD_ep ep_out_0 = XUD_InitEp(c_out_0);
XUD_ep ep_out = XUD_InitEp(c_out);
XUD_ep ep_in = XUD_InitEp(c_in);
- /* Buffer for Setup data */
unsigned char buffer[1024];
XUD_GetBuffer(ep_out, buffer, length);
XUD_SetBuffer(ep_in, buffer, length);
+ XUD_Kill(ep_out_0);
exit(0);
}
-#define USB_CORE 0
int main()
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
par
{
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
- TestEp_Bulk(c_ep_out[3], c_ep_in[3]);
- TestEp_Bulk2(c_ep_out[2], c_ep_in[2]);
+ TestEp_LoopbackForever(c_ep_out[TEST_EP_NUM], c_ep_in[TEST_EP_NUM]);
+ TestEp_LoopbackOnce(c_ep_out[KILL_EP_NUM], c_ep_in[KILL_EP_NUM], c_ep_out[0]);
}
return 0;
diff --git a/tests/test_iso_loopback/src/test.xn b/tests/test_iso_loopback/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_iso_loopback/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_loopback/src/test_xs1.xn b/tests/test_iso_loopback/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_iso_loopback/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_loopback/src/xc_ptr.h b/tests/test_iso_loopback/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_iso_loopback/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_iso_rx_basic.py b/tests/test_iso_rx_basic.py
index dd2a435b..37e41a4a 100644
--- a/tests/test_iso_rx_basic.py
+++ b/tests/test_iso_rx_basic.py
@@ -1,50 +1,31 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- ep = 2
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- AppendOutToken(packets, ep)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
-
- # Note, quite big gap to allow checking.
-
- dataval += 10
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=11, pid=0x3)) #DATA0
-
- dataval += 11
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
-
- dataval += 12
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=13, pid=0x3)) #DATA0
-
- dataval += 13
- AppendOutToken(packets, ep, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
-
-
- do_rx_test(arch, clk, phy, packets, __file__, seed, level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ start_length = 10
+ end_length = 14
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ for pktLength in range(10, end_length + 1):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="ISO",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_iso_rx_basic/Makefile b/tests/test_iso_rx_basic/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_iso_rx_basic/Makefile
+++ b/tests/test_iso_rx_basic/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_iso_rx_basic/src/main.xc b/tests/test_iso_rx_basic/src/main.xc
index e2d0a7dd..841edf92 100644
--- a/tests/test_iso_rx_basic/src/main.xc
+++ b/tests/test_iso_rx_basic/src/main.xc
@@ -1,153 +1,29 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
+#include "shared.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (14)
+#endif
-void exit(int);
+#include "shared.h"
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO};
-unsigned fail(int x)
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
+ return fail;
}
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
-
- g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
-
- return 0;
-}
+#include "test_main.xc"
-int TestEp(chanend c_out, chanend c_in, int epNum)
-{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
- unsigned char buffer[1024];
-
- for(int i = 10; i <= 14; i++)
- {
- XUD_GetBuffer(ep_out, buffer, length);
-
- if(length != i)
- {
- printintln(length);
- fail(FAIL_RX_LENERROR);
- }
-
- if(RxDataCheck(buffer, length, epNum))
- {
- fail(FAIL_RX_DATAERROR);
- }
-
- }
-
- exit(0);
-}
-
-
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- TestEp(c_ep_out[2], c_ep_in[2], 2);
- }
-
- return 0;
-}
diff --git a/tests/test_iso_rx_basic/src/test.xn b/tests/test_iso_rx_basic/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_iso_rx_basic/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_rx_basic/src/test_xs1.xn b/tests/test_iso_rx_basic/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_iso_rx_basic/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_rx_basic/src/xc_ptr.h b/tests/test_iso_rx_basic/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_iso_rx_basic/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_iso_rxtx_fastpacket.py b/tests/test_iso_rxtx_fastpacket.py
index 53dae9ec..dc157bc8 100644
--- a/tests/test_iso_rxtx_fastpacket.py
+++ b/tests/test_iso_rxtx_fastpacket.py
@@ -1,41 +1,46 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
-import random
-import xmostest
-from usb_packet import *
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
+@pytest.fixture
+def test_session(ep, address, bus_speed):
- ep = 3
+ start_length = 10
+ end_length = 19
- packets = []
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
- data_val = 0;
- pkt_length = 20
- data_pid = 0x3 #DATA0
-
- for pkt_length in range(10, 20):
+ for pktLength in range(start_length, end_length + 1):
# < 17 fails
- AppendOutToken(packets, ep, inter_pkt_gap=17)
- packets.append(TxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid)) #DATA0
-
- AppendInToken(packets, ep, inter_pkt_gap=37)
- packets.append(RxDataPacket(rand, data_start_val=data_val, length=pkt_length, pid=data_pid))
-
- data_val = data_val + pkt_length
- #data_pid = data_pid ^ 8
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="ISO",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=20,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="ISO",
+ direction="IN",
+ dataLength=pktLength,
+ interEventDelay=58,
+ )
+ )
+
+ return session
diff --git a/tests/test_iso_rxtx_fastpacket/Makefile b/tests/test_iso_rxtx_fastpacket/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_iso_rxtx_fastpacket/Makefile
+++ b/tests/test_iso_rxtx_fastpacket/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_iso_rxtx_fastpacket/src/main.xc b/tests/test_iso_rxtx_fastpacket/src/main.xc
index 46018ac0..97172173 100644
--- a/tests/test_iso_rxtx_fastpacket/src/main.xc
+++ b/tests/test_iso_rxtx_fastpacket/src/main.xc
@@ -1,192 +1,42 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#include "shared.h"
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL};
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-#define PKT_COUNT 10
-#define INITIAL_PKT_LENGTH 10
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
-
- g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
-
- return 0;
-}
-
-
-#pragma unsafe arrays
-int TestEp_Bulk_Tx(chanend c_in1, int epNum1)
-{
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
-
- unsigned char buffer[PKT_COUNT][1024];
-
- int counter = 0;
- int length = INITIAL_PKT_LENGTH;
-
- for(int i = 0; i< PKT_COUNT; i++)
- {
- for(int j = 0; j < length; j++)
- {
- buffer[i][j] = counter++;
- }
- length++;
- }
-
- length = INITIAL_PKT_LENGTH;
-
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- XUD_SetBuffer(ep_in1, buffer[i], length++);
- }
-
- exit(0);
-
-}
-#pragma unsafe arrays
-int TestEp_Bulk_Rx(chanend c_out1, int epNum1)
-{
- // TODO check rx lengths
-
- unsigned int length[PKT_COUNT];
- XUD_Result_t res;
-
- XUD_ep ep_out1 = XUD_InitEp(c_out1);
-
- /* Buffer for Setup data */
- unsigned char buffer[PKT_COUNT][1024];
-
- /* Receive a bunch of packets quickly, then check them */
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- XUD_GetBuffer(ep_out1, buffer[i], length[i]);
- }
-#pragma loop unroll
- for(int i = 0; i < PKT_COUNT; i++)
- {
- RxDataCheck(buffer[i], length[i], epNum1);
- }
-
- while(1);
-
-}
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (19)
+#endif
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO};
-#define USB_CORE 0
int main()
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
par
{
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ XUD_Main( c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
-
- TestEp_Bulk_Tx(c_ep_in[3], 3);
- TestEp_Bulk_Rx(c_ep_out[3], 3);
- }
+ XUD_SPEED_HS, XUD_PWR_BUS);
+
+ TestEp_Tx(c_ep_in[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
+
+ {
+ TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
+ XUD_ep ep0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep0);
+ exit(0); // TODO should be able to move this out of the par
+ }
+ }
- return 0;
}
diff --git a/tests/test_iso_rxtx_fastpacket/src/test.xn b/tests/test_iso_rxtx_fastpacket/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_iso_rxtx_fastpacket/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_rxtx_fastpacket/src/test_xs1.xn b/tests/test_iso_rxtx_fastpacket/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_iso_rxtx_fastpacket/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_tx_basic.py b/tests/test_iso_tx_basic.py
index 9a1a4c05..1a65d543 100644
--- a/tests/test_iso_tx_basic.py
+++ b/tests/test_iso_tx_basic.py
@@ -1,52 +1,34 @@
-#!/usr/bin/env python
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-
-# Single, setup transaction to EP 0
-
-def do_test(arch, tx_clk, tx_phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- ep = 3
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- AppendInToken(packets, ep)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
-
- dataval += 10
- AppendInToken(packets, ep, inter_pkt_gap=2000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=11, pid=0x3)) #DATA0
-
- dataval += 11
- AppendInToken(packets, ep, inter_pkt_gap=2000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=12, pid=0x3)) #DATA0
-
- dataval += 12
- AppendInToken(packets, ep, inter_pkt_gap=2000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=13, pid=0x3)) #DATA0
-
- dataval += 13
- AppendInToken(packets, ep, inter_pkt_gap=2000)
- packets.append(RxDataPacket(rand, data_start_val=dataval, length=14, pid=0x3)) #DATA0
-
- # Note, quite big gap to allow checking.
- do_rx_test(arch, tx_clk, tx_phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed, dummy_threads):
+
+ start_length = 10
+ end_length = 14
+
+ session = UsbSession(
+ bus_speed=bus_speed,
+ run_enumeration=False,
+ device_address=address,
+ initial_delay=100000,
+ )
+
+ for pktLength in range(10, end_length + 1):
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="ISO",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_iso_tx_basic/Makefile b/tests/test_iso_tx_basic/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_iso_tx_basic/Makefile
+++ b/tests/test_iso_tx_basic/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_iso_tx_basic/src/main.xc b/tests/test_iso_tx_basic/src/main.xc
index b11c57c8..e44a8988 100644
--- a/tests/test_iso_tx_basic/src/main.xc
+++ b/tests/test_iso_tx_basic/src/main.xc
@@ -1,90 +1,44 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
-#define XUD_EP_COUNT_OUT 4
-#define XUD_EP_COUNT_IN 4
+#ifndef EP_COUNT_OUT
+#define EP_COUNT_OUT (6)
+#endif
+#ifndef EP_COUNT_IN
+#define EP_COUNT_IN (6)
+#endif
-/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_BUL,
- XUD_EPTYPE_ISO};
-
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END (14)
+#endif
+#include "shared.h"
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO,
+ XUD_EPTYPE_ISO};
-int TestEp(chanend c_out, chanend c_in, int epNum)
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
{
- unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out = XUD_InitEp(c_out);
- XUD_ep ep_in = XUD_InitEp(c_in);
-
- /* Buffer for Setup data */
- unsigned char buffer[1024];
+ unsigned fail = TestEp_Tx(c_ep_in[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END, RUNMODE_DIE);
- for(int i = 10; i <= 14; i++)
- {
- SendTxPacket(ep_in, i, epNum);
- }
-
- exit(0);
+ return fail;
}
+#include "test_main.xc"
-#define USB_CORE 0
-int main()
-{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
-
- par
- {
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
- null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
- TestEp(c_ep_out[3], c_ep_in[3], 1);
- }
- return 0;
-}
diff --git a/tests/test_iso_tx_basic/src/test.xn b/tests/test_iso_tx_basic/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_iso_tx_basic/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_tx_basic/src/test_xs1.xn b/tests/test_iso_tx_basic/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_iso_tx_basic/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_iso_tx_basic/src/xc_ptr.h b/tests/test_iso_tx_basic/src/xc_ptr.h
deleted file mode 100644
index 8fa5a04e..00000000
--- a/tests/test_iso_tx_basic/src/xc_ptr.h
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2016-2021 XMOS LIMITED.
-// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-#ifndef __xc_ptr__
-#define __xc_ptr__
-
-typedef unsigned int xc_ptr;
-
-// Note that this function is marked as const to avoid the XC
-// parallel usage checks, this is only really going to work if this
-// is the *only* way the array a is accessed (and everything else uses
-// the xc_ptr)
-inline xc_ptr array_to_xc_ptr(const unsigned a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-inline xc_ptr char_array_to_xc_ptr(const unsigned char a[])
-{
- xc_ptr x;
- asm("mov %0, %1":"=r"(x):"r"(a));
- return x;
-}
-
-#define write_via_xc_ptr_indexed(p,i,x) asm volatile("stw %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_byte_via_xc_ptr_indexed(p,i,x) asm volatile("st8 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-#define write_short_via_xc_ptr_indexed(p,i,x) asm volatile("st16 %0, %1[%2]"::"r"(x),"r"(p),"r"(i))
-
-#define write_via_xc_ptr(p,x) asm volatile("stw %0, %1[0]"::"r"(x),"r"(p))
-// No immediate st8 format
-#define write_byte_via_xc_ptr(p,x) write_byte_via_xc_ptr_indexed(p, 0, x)
-#define write_short_via_xc_ptr(p,x) write_short_via_xc_ptr_indexed(p, 0, x)
-
-#define read_via_xc_ptr_indexed(x,p,i) asm("ldw %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_byte_via_xc_ptr_indexed(x,p,i) asm("ld8u %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-#define read_short_via_xc_ptr_indexed(x,p,i) asm("ld16s %0, %1[%2]":"=r"(x):"r"(p),"r"(i));
-
-#define read_via_xc_ptr(x,p) asm("ldw %0, %1[0]":"=r"(x):"r"(p));
-// No immediate ld8u format
-#define read_byte_via_xc_ptr(x,p) read_byte_via_xc_ptr_indexed(x, p, 0)
-#define read_short_via_xc_ptr(x,p) read_short_via_xc_ptr_indexed(x, p, 0)
-
-#define GET_SHARED_GLOBAL(x, g) asm volatile("ldw %0, dp[" #g "]":"=r"(x)::"memory")
-#define SET_SHARED_GLOBAL(g, v) asm volatile("stw %0, dp[" #g "]"::"r"(v):"memory")
-
-#endif
diff --git a/tests/test_bulk_rxtx_fastpacket/Makefile b/tests/test_makefile.mak
similarity index 64%
rename from tests/test_bulk_rxtx_fastpacket/Makefile
rename to tests/test_makefile.mak
index 83edfc42..13501762 100644
--- a/tests/test_bulk_rxtx_fastpacket/Makefile
+++ b/tests/test_makefile.mak
@@ -1,9 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
-
-TARGET = test.xn
-
# The APP_NAME variable determines the name of the final .xe file. It should
# not include the .xe postfix. If left blank the name will default to
# the project name
@@ -20,23 +14,43 @@ APP_NAME =
SHARED_CODE = ../../shared_src
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
+COMMON_FLAGS = -DDEBUG_PRINT_ENABLE \
+ -O3 \
+ -I$(SHARED_CODE) \
+ -DUSB_TILE=tile[0] \
+ -DXUD_SIM_XSIM=1 \
+ -DXUD_TEST_SPEED_HS=1 \
+ $(CFLAGS)
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
+TEST_FLAGS ?=
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
+ifndef TEST_ARCH
+$(error TEST_ARCH is not set)
+endif
+ifndef TEST_FREQ
+$(error TEST_FREQ is not set)
+endif
+ifndef TEST_DTHREADS
+$(error TEST_DTHREADS is not set)
+endif
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
+ifndef TEST_EP_NUM
+$(error TEST_EP_NUM is not set)
endif
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
+ifndef XUD_STARTUP_ADDRESS
+$(error XUD_STARTUP_ADDRESS is not set)
endif
+XCC_FLAGS_$(TEST_ARCH)_$(TEST_FREQ)_$(TEST_DTHREADS)_$(TEST_EP_NUM)_$(XUD_STARTUP_ADDRESS) = $(TEST_FLAGS) $(COMMON_FLAGS)
+
+# The TARGET variable determines what target system the application is
+# compiled for. It either refers to an XN file in the source directories
+# or a valid argument for the --target option when compiling.
+TARGET = test_$(TEST_ARCH)_$(TEST_FREQ).xn
# The USED_MODULES variable lists other module used by the application.
USED_MODULES = lib_xud
diff --git a/tests/test_ping_rx_basic.py b/tests/test_ping_rx_basic.py
index 7a4823cd..90f77e29 100644
--- a/tests/test_ping_rx_basic.py
+++ b/tests/test_ping_rx_basic.py
@@ -3,70 +3,124 @@
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
# Basic check of PING functionality
-
-import random
-import xmostest
-from usb_packet import *
-#import * AppendSetupToken, TxDataPacket, RxDataPacket, TokenPacket, RxHandshakePacket, TxHandshakePacket
-from usb_clock import Clock
-from helpers import do_rx_test, packet_processing_time, get_dut_address
-from helpers import choose_small_frame_size, check_received_packet, runall_rx
-
-
-# Single, setup transaction to EP 0
-
-def do_test(arch, clk, phy, seed):
- rand = random.Random()
- rand.seed(seed)
-
- dev_address = get_dut_address()
- ep = 1
-
- # The inter-frame gap is to give the DUT time to print its output
- packets = []
-
- dataval = 0;
-
- # Ping EP 2, expect NAK
- AppendPingToken(packets, 2)
- packets.append(RxHandshakePacket(pid=0x5a))
+from usb_packet import (
+ TokenPacket,
+ TxDataPacket,
+ RxDataPacket,
+ TxHandshakePacket,
+ RxHandshakePacket,
+ USB_PID,
+)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # Ping test EP, expect NAK
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))
# And again
- AppendPingToken(packets, 2)
- packets.append(RxHandshakePacket(pid=0x5a))
-
-
- # Send packet to EP 1, xCORE should mark EP 2 as ready
- AppendOutToken(packets, ep)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
- # Ping EP 2 again - expect ACK
- AppendPingToken(packets, 2, inter_pkt_gap=6000)
- packets.append(RxHandshakePacket())
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))
+
+ # Send packet to "ctrl" EP, DUT should mark test EP as ready
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep + 1,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
+
+ # Ping test EP again - expect ACK
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=6000,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["ACK"]))
# And again..
- AppendPingToken(packets, 2)
- packets.append(RxHandshakePacket())
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=6000,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["ACK"]))
# Send out to EP 2.. expect ack
- AppendOutToken(packets, 2, inter_pkt_gap=6000)
- packets.append(TxDataPacket(rand, data_start_val=dataval, length=10, pid=0x3)) #DATA0
- packets.append(RxHandshakePacket())
-
- # Re-Ping EP 2, expect NAK
- AppendPingToken(packets, 2)
- packets.append(RxHandshakePacket(pid=0x5a))
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ interEventDelay=6000,
+ )
+ )
+
+ # Re-Ping EP 2, expect NAK
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))
# And again
- AppendPingToken(packets, 2)
- packets.append(RxHandshakePacket(pid=0x5a))
-
-
-
- do_rx_test(arch, clk, phy, packets, __file__, seed,
- level='smoke', extra_tasks=[])
-
-def runtest():
- random.seed(1)
- runall_rx(do_test)
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["NAK"]))
+
+ # Send a packet to "ctrl" EP so the DUT knows it can exit.
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep + 1,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
+
+ return session
diff --git a/tests/test_ping_rx_basic/Makefile b/tests/test_ping_rx_basic/Makefile
index 83edfc42..a2c9ee98 100644
--- a/tests/test_ping_rx_basic/Makefile
+++ b/tests/test_ping_rx_basic/Makefile
@@ -1,50 +1,3 @@
-# The TARGET variable determines what target system the application is
-# compiled for. It either refers to an XN file in the source directories
-# or a valid argument for the --target option when compiling.
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
-TARGET = test.xn
-
-# The APP_NAME variable determines the name of the final .xe file. It should
-# not include the .xe postfix. If left blank the name will default to
-# the project name
-
-APP_NAME =
-
-# The flags passed to xcc when building the application
-# You can also set the following to override flags for a particular language:
-#
-# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
-#
-# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
-# xcc for the final link (mapping) stage.
-
-SHARED_CODE = ../../shared_src
-
-COMMON_FLAGS = -g -report -DDEBUG_PRINT_ENABLE -save-temps -O3 -Xmapper --map -Xmapper MAPFILE -I$(SHARED_CODE) -DUSB_TILE=tile[0] -DSIMULATION -DARCH_L
-
-XCC_FLAGS_xs2 = $(COMMON_FLAGS) -DARCH_X200 -DXUD_SERIES_SUPPORT=XUD_X200_SERIES
-
-XCC_FLAGS_xs1 = $(COMMON_FLAGS) -DARCH_S -DXUD_SERIES_SUPPORT=XUD_U_SERIES
-
-
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs1))
- TARGET = test_xs1.xn
-endif
-
-ifeq ($(CONFIG),$(filter $(CONFIG),xs2))
- TARGET = test.xn
-endif
-
-
-
-# The USED_MODULES variable lists other module used by the application.
-USED_MODULES = lib_xud
-
-
-#=============================================================================
-# The following part of the Makefile includes the common build infrastructure
-# for compiling XMOS applications. You should not need to edit below here.
-
-XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
+include ../test_makefile.mak
diff --git a/tests/test_ping_rx_basic/src/main.xc b/tests/test_ping_rx_basic/src/main.xc
index a3db66ae..e6c34740 100644
--- a/tests/test_ping_rx_basic/src/main.xc
+++ b/tests/test_ping_rx_basic/src/main.xc
@@ -1,174 +1,74 @@
// Copyright 2016-2021 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
-/*
- * Test the use of the ExampleTestbench. Test that the value 0 and 1 can be sent
- * in both directions between the ports.
- *
- * NOTE: The src/testbenches/ExampleTestbench must have been compiled for this to run without error.
- *
- */
-#include
-#include
-#include
-#include "xud.h"
-#include "platform.h"
-#include "xc_ptr.h"
+#include "shared.h"
-#define XUD_EP_COUNT_OUT 5
-#define XUD_EP_COUNT_IN 5
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
/* Endpoint type tables */
-XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
-void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend ?c_usb_test);
-
-void exit(int);
-
-#define FAIL_RX_DATAERROR 0
-#define FAIL_RX_LENERROR 1
-
-unsigned fail(int x)
-{
-
- printstr("\nXCORE: ### FAIL ******");
- switch(x)
- {
- case FAIL_RX_DATAERROR:
- printstr("XCORE RX Data Error\n");
- break;
-
- case FAIL_RX_LENERROR:
- printstr("XCORE RX Length Error\n");
- break;
-
- }
-
- exit(1);
-}
-
-unsigned char g_rxDataCheck[5] = {0, 0, 0, 0, 0};
-unsigned char g_txDataCheck[5] = {0,0,0,0,0,};
-unsigned g_txLength[5] = {0,0,0,0,0};
-
-
-#pragma unsafe arrays
-void SendTxPacket(XUD_ep ep, int length, int epNum)
-{
- unsigned char buffer[1024];
- unsigned char x;
-
- for (int i = 0; i < length; i++)
- {
- buffer[i] = g_txDataCheck[epNum]++;
-
- //asm("ld8u %0, %1[%2]":"=r"(x):"r"(g_txDataCheck),"r"(epNum));
- // read_byte_via_xc_ptr_indexed(x, p_txDataCheck, epNum);
-
- //buffer[i] = x;
- //x++;
- //asm("st8 %0, %1[%2]"::"r"(x),"r"(g_txDataCheck),"r"(epNum));
- //write_byte_via_xc_ptr_indexed(p_txDataCheck,epNum,x);
- }
-
- XUD_SetBuffer(ep, buffer, length);
-}
-
-#pragma unsafe arrays
-int RxDataCheck(unsigned char b[], int l, int epNum)
-{
- int fail = 0;
- unsigned char x;
-
- for (int i = 0; i < l; i++)
- {
- unsigned char y;
- //read_byte_via_xc_ptr_indexed(y, p_rxDataCheck, epNum);
- if(b[i] != g_rxDataCheck[epNum])
- {
- printstr("#### Mismatch on EP: ");
- printint(epNum);
- printstr(". Got:");
- printhex(b[i]);
- printstr(" Expected:");
- printhexln(g_rxDataCheck[epNum]);
- //printintln(l); // Packet length
- return 1;
- }
-
- g_rxDataCheck[epNum]++;
- //read_byte_via_xc_ptr_indexed(x, p_rxDataCheck, epNum);
- //x++;
- //write_byte_via_xc_ptr_indexed(p_rxDataCheck,epNum,x);
- }
-
- return 0;
-}
-
-int TestEp_Bulk(chanend c_out1, chanend c_in1, int epNum1, chanend c_out2, chanend c_in2, int epNum2)
+int TestEp_PingTest(XUD_ep ep_out1, XUD_ep ep_out2, int epNum1, int epNum2)
{
unsigned int length;
- XUD_Result_t res;
-
- XUD_ep ep_out1 = XUD_InitEp(c_out1);
- XUD_ep ep_out2 = XUD_InitEp(c_out2);
- XUD_ep ep_in1 = XUD_InitEp(c_in1);
- XUD_ep ep_in2 = XUD_InitEp(c_in2);
- /* Buffer for Setup data */
unsigned char buffer[1024];
int i = 10;
- {
- XUD_GetBuffer(ep_out1, buffer, length);
-
- if(length != i)
- {
- printintln(length);
- fail(FAIL_RX_LENERROR);
- }
-
- if(RxDataCheck(buffer, length, epNum1))
- {
- fail(FAIL_RX_DATAERROR);
- }
+
+ XUD_GetBuffer(ep_out1, buffer, length);
+ if(RxDataCheck(buffer, length, epNum1, i))
+ {
+ return FAIL_RX_DATAERROR;
}
-
- XUD_GetBuffer(ep_out2, buffer, length);
-
- if(length != i)
- {
- printintln(length);
- fail(FAIL_RX_LENERROR);
- }
+ XUD_GetBuffer(ep_out2, buffer, length);
- if(RxDataCheck(buffer, length, epNum2))
- {
- fail(FAIL_RX_DATAERROR);
- }
+ if(RxDataCheck(buffer, length, epNum2, i))
+ {
+ return FAIL_RX_DATAERROR;
+ }
+ // Another packet to "ctrl" EP means we can exit
+ XUD_GetBuffer(ep_out1, buffer, length);
- exit(0);
+ if(RxDataCheck(buffer, length, epNum1, i))
+ {
+ return FAIL_RX_DATAERROR;
+ }
+
+ return 0;
}
+#define CTRL_EP_NUM (TEST_EP_NUM + 1)
-#define USB_CORE 0
int main()
{
- chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
- chan c_sync;
- chan c_sync_iso;
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
par
{
-
- XUD_Manager( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ XUD_Main(c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
null, epTypeTableOut, epTypeTableIn,
- null, null, -1, XUD_SPEED_HS, XUD_PWR_BUS);
+ XUD_SPEED_HS, XUD_PWR_BUS);
+
+ {
+ XUD_ep ep_out1 = XUD_InitEp(c_ep_out[CTRL_EP_NUM]);
+ XUD_ep ep_out2 = XUD_InitEp(c_ep_out[TEST_EP_NUM]);
+
+ unsigned fail = TestEp_PingTest(ep_out1, ep_out2, CTRL_EP_NUM, TEST_EP_NUM);
+
+ XUD_ep ep0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep0);
+
+ if(fail)
+ TerminateFail(fail);
+ else
+ TerminatePass(fail);
+ }
- TestEp_Bulk(c_ep_out[1], c_ep_in[1], 1, c_ep_out[2], c_ep_in[2], 2);
}
return 0;
diff --git a/tests/test_ping_rx_basic/src/test.xn b/tests/test_ping_rx_basic/src/test.xn
deleted file mode 100644
index d0ee86b8..00000000
--- a/tests/test_ping_rx_basic/src/test.xn
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
- Board
- XS2 MC Audio
-
- tileref tile[2]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_ping_rx_basic/src/test_xs1.xn b/tests/test_ping_rx_basic/src/test_xs1.xn
deleted file mode 100755
index 573aef45..00000000
--- a/tests/test_ping_rx_basic/src/test_xs1.xn
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
-
- tileref tile[1]
- tileref usb_tile
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/test_ping_stall.py b/tests/test_ping_stall.py
new file mode 100644
index 00000000..7a27b558
--- /dev/null
+++ b/tests/test_ping_stall.py
@@ -0,0 +1,77 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+from usb_packet import TokenPacket, USB_PID, RxHandshakePacket
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ pktLength = 10
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ ep_ctrl = ep + 1
+
+ # Ping EP, expect stall
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["STALL"]))
+
+ # And again
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["PING"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(RxHandshakePacket(pid=USB_PID["STALL"]))
+
+ # Valid transaction to another EP informing test code to clear stall
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_ctrl,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ # Expect normal transactions
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_ping_stall/Makefile b/tests/test_ping_stall/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_ping_stall/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_ping_stall/src/main.xc b/tests/test_ping_stall/src/main.xc
new file mode 100644
index 00000000..ba19cdb6
--- /dev/null
+++ b/tests/test_ping_stall/src/main.xc
@@ -0,0 +1,50 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+
+#ifndef CTRL_EP_NUM
+#define CTRL_EP_NUM (TEST_EP_NUM + 1)
+#endif
+
+#include "shared.h"
+
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned failed = 0;
+ uint8_t outBuffer[128];
+ unsigned length;
+ XUD_Result_t result;
+
+ /* Stall test EP */
+ XUD_ep ep_out = XUD_InitEp(c_ep_out[TEST_EP_NUM]);
+ XUD_SetStall(ep_out);
+
+ XUD_ep ep_ctrl = XUD_InitEp(c_ep_out[CTRL_EP_NUM]);
+
+ /* Valid transaction on another EP, clear STALL on the test EP's */
+ result = XUD_GetBuffer(ep_ctrl, outBuffer, length);
+ failed = (result != XUD_RES_OKAY);
+
+ /* Clear stall on the test EP's */
+ XUD_ClearStall(ep_out);
+
+ /* Ensure test EP's now operate as expected */
+ result = XUD_GetBuffer(ep_out, outBuffer, length);
+ failed |= (result != XUD_RES_OKAY);
+
+ result = XUD_GetBuffer(ep_out, outBuffer, length);
+ failed |= (result != XUD_RES_OKAY);
+
+ return failed;
+}
+
+#include "test_main.xc"
diff --git a/tests/test_shorttoken.py b/tests/test_shorttoken.py
new file mode 100644
index 00000000..fea5e86a
--- /dev/null
+++ b/tests/test_shorttoken.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# Copyright 2019-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import TxPacket, USB_PID
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+# TODO Can this be moved?
+@pytest.fixture
+def test_file():
+ return __file__
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed, arch):
+
+ if arch == "xs3":
+ pytest.xfail("Known failure on xs3")
+
+ address = 1
+ ep = 1
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # Start with a valid transaction */
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
+
+ # tmp hack for xs2 - for xs2 the shim will throw away the short token and it will never be seen by the xCORE
+ if arch == "xs3":
+ # Create a short token, only PID and 2nd byte
+ shorttoken = TxPacket(
+ pid=USB_PID["OUT"],
+ data_bytes=[0x81],
+ interEventDelay=100,
+ )
+ session.add_event(shorttoken)
+
+ # Finish with valid transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=6000,
+ )
+ )
+
+ return session
diff --git a/tests/test_shorttoken/Makefile b/tests/test_shorttoken/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_shorttoken/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_shorttoken/src/main.xc b/tests/test_shorttoken/src/main.xc
new file mode 100644
index 00000000..3b8c41c5
--- /dev/null
+++ b/tests/test_shorttoken/src/main.xc
@@ -0,0 +1,69 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include
+#include
+#include
+#include "xud.h"
+#include "platform.h"
+#include "shared.h"
+
+#define XUD_EP_COUNT_OUT 5
+#define XUD_EP_COUNT_IN 5
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL,XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+void exit(int);
+
+int TestEp_Bulk(chanend c_out, chanend c_in, int epNum, chanend c_out_0)
+{
+ unsigned int length;
+ XUD_Result_t res;
+
+ XUD_ep ep_out_0 = XUD_InitEp(c_out_0);
+ XUD_ep ep_out = XUD_InitEp(c_out);
+ XUD_ep ep_in = XUD_InitEp(c_in);
+
+ /* Buffer for Setup data */
+ unsigned char buffer[1024];
+
+ for(int i = 10; i <= 11; i++)
+ {
+ XUD_GetBuffer(ep_out, buffer, length);
+
+ if(length != i)
+ {
+ printintln(length);
+ TerminateFail(FAIL_RX_LENERROR);
+ }
+
+ if(RxDataCheck(buffer, length, epNum,i))
+ {
+ TerminateFail(FAIL_RX_DATAERROR);
+ }
+
+ }
+
+ XUD_Kill(ep_out_0);
+ exit(0);
+}
+
+
+int main()
+{
+ chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
+
+ par
+ {
+
+ XUD_Main( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ null, epTypeTableOut, epTypeTableIn,
+ XUD_SPEED_HS, XUD_PWR_BUS);
+
+
+ TestEp_Bulk(c_ep_out[1], c_ep_in[1], 1, c_ep_out[0]);
+ }
+
+ return 0;
+}
diff --git a/tests/test_sof_badcrc.py b/tests/test_sof_badcrc.py
new file mode 100644
index 00000000..f83558e7
--- /dev/null
+++ b/tests/test_sof_badcrc.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# Copyright 2019-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import TokenPacket, USB_PID, CreateSofToken
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ pytest.xfail("Known failure (on XS3)")
+
+ frameNumber = 52 # Note, for frame number 52 we expect A5 34 40 on the bus
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # Start with a valid transaction */
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
+
+ session.add_event(CreateSofToken(frameNumber))
+ session.add_event(CreateSofToken(frameNumber + 1))
+ session.add_event(CreateSofToken(frameNumber + 2))
+ session.add_event(
+ CreateSofToken(frameNumber + 3, badCrc=True)
+ ) # Invalidate the CRC
+ session.add_event(CreateSofToken(frameNumber + 4))
+
+ # Finish with valid transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=6000,
+ )
+ )
+
+ return session
diff --git a/tests/test_sof_badcrc/Makefile b/tests/test_sof_badcrc/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_sof_badcrc/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_sof_badcrc/src/main.xc b/tests/test_sof_badcrc/src/main.xc
new file mode 100644
index 00000000..f5030961
--- /dev/null
+++ b/tests/test_sof_badcrc/src/main.xc
@@ -0,0 +1,118 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include
+#include
+#include
+#include "xud.h"
+#include "platform.h"
+#include "shared.h"
+
+#define XUD_EP_COUNT_OUT 5
+#define XUD_EP_COUNT_IN 5
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL,XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+void exit(int);
+
+int TestEp(chanend c_out, chanend c_in, int epNum, chanend c_sof)
+{
+ unsigned int length;
+ XUD_Result_t res;
+
+ XUD_ep ep_out = XUD_InitEp(c_out);
+ XUD_ep ep_in = XUD_InitEp(c_in);
+
+ unsigned frames[10];
+
+ /* Buffer for Setup data */
+ unsigned char buffer[1024];
+
+ XUD_GetBuffer(ep_out, buffer, length);
+
+ if(length != 10)
+ {
+ printintln(length);
+ return FAIL_RX_LENERROR;
+ }
+
+ if(RxDataCheck(buffer, length, epNum, 10))
+ {
+ return FAIL_RX_DATAERROR;
+ }
+
+ /* Receive SOFs */
+ /* Host sends 5 SOFs, but one has its CRC nobbled so we should only see 4. */
+ for (int i = 0; i< 5; i++)
+ {
+ if(i == 3)
+ continue;
+
+ frames[i] = inuint(c_sof);
+ }
+
+ XUD_GetBuffer(ep_out, buffer, length);
+
+ if(length != 11)
+ {
+ printintln(length);
+ return FAIL_RX_LENERROR;
+ }
+
+ if(RxDataCheck(buffer, length, epNum, 11))
+ {
+ return FAIL_RX_DATAERROR;
+ }
+
+ unsigned expectedFrame = 52;
+
+ /* Check frame numbers */
+ for (int i = 0 ; i < 5; i++)
+ {
+ if(i == 3)
+ continue;
+
+ if(frames[i] != i+expectedFrame)
+ {
+ printstr("Expected: ");
+ printintln(i+expectedFrame);
+ printstr("Received: ");
+ printintln(frames[i]);
+ return FAIL_RX_FRAMENUMBER;
+ }
+ }
+
+ return 0;
+}
+
+
+int main()
+{
+ chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
+ chan c_sof;
+
+ par
+ {
+
+ XUD_Main( c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ c_sof, epTypeTableOut, epTypeTableIn,
+ XUD_SPEED_HS, XUD_PWR_BUS);
+
+ {
+ unsigned fail = TestEp(c_ep_out[1], c_ep_in[1], 1, c_sof);
+
+ if(fail)
+ TerminateFail(fail);
+ else
+ TerminatePass(fail);
+
+ XUD_ep ep0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep0);
+ exit(0);
+
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/test_sof_basic.py b/tests/test_sof_basic.py
new file mode 100644
index 00000000..e2f2edae
--- /dev/null
+++ b/tests/test_sof_basic.py
@@ -0,0 +1,50 @@
+# Copyright 2019-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+from usb_packet import CreateSofToken
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ frameNumber = 52 # Note, for frame number 52 we expect A5 34 40 on the bus
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ # Start with a valid transaction */
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=10,
+ )
+ )
+
+ session.add_event(CreateSofToken(frameNumber))
+ session.add_event(CreateSofToken(frameNumber + 1))
+ session.add_event(CreateSofToken(frameNumber + 2))
+ session.add_event(CreateSofToken(frameNumber + 3))
+ session.add_event(CreateSofToken(frameNumber + 4))
+
+ # Finish with valid transaction
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=11,
+ interEventDelay=6000,
+ )
+ )
+
+ return session
diff --git a/tests/test_sof_basic/Makefile b/tests/test_sof_basic/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_sof_basic/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_sof_basic/src/main.xc b/tests/test_sof_basic/src/main.xc
new file mode 100644
index 00000000..0f7ff9fb
--- /dev/null
+++ b/tests/test_sof_basic/src/main.xc
@@ -0,0 +1,100 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "shared.h"
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+void exit(int);
+
+unsigned TestEp_Bulk(chanend c_out, chanend c_in, int epNum, chanend c_sof)
+{
+ unsigned int length;
+ XUD_Result_t res;
+
+ XUD_ep ep_out = XUD_InitEp(c_out);
+ XUD_ep ep_in = XUD_InitEp(c_in);
+
+ unsigned frames[10];
+
+ /* Buffer for Setup data */
+ unsigned char buffer[1024];
+
+ XUD_GetBuffer(ep_out, buffer, length);
+
+ if(length != 10)
+ {
+ printintln(length);
+ return FAIL_RX_LENERROR;
+ }
+
+ if(RxDataCheck(buffer, length, epNum, 10))
+ {
+ return FAIL_RX_DATAERROR;
+ }
+
+ /* Receive SOFs */
+ for (int i = 0; i< 5; i++)
+ frames[i] = inuint(c_sof);
+
+ XUD_GetBuffer(ep_out, buffer, length);
+
+ if(length != 11)
+ {
+ printintln(length);
+ return FAIL_RX_LENERROR;
+ }
+
+ if(RxDataCheck(buffer, length, epNum, 11))
+ {
+ return FAIL_RX_DATAERROR;
+ }
+
+ unsigned expectedFrame = 52;
+
+ /* Check frame numbers */
+ for (int i = 0 ; i < 5; i++)
+ {
+ if(frames[i] != i+expectedFrame)
+ {
+ printhexln(i);
+ printhexln(frames[i]);
+ return FAIL_RX_FRAMENUMBER;
+ }
+ }
+
+ return 0;
+}
+
+int main()
+{
+ chan c_ep_out[EP_COUNT_OUT], c_ep_in[EP_COUNT_IN];
+ chan c_sof;
+
+ par
+ {
+
+ XUD_Main( c_ep_out, EP_COUNT_OUT, c_ep_in, EP_COUNT_IN,
+ c_sof, epTypeTableOut, epTypeTableIn,
+ XUD_SPEED_HS, XUD_PWR_BUS);
+
+ {
+ unsigned fail = TestEp_Bulk(c_ep_out[TEST_EP_NUM], c_ep_in[TEST_EP_NUM], TEST_EP_NUM, c_sof);
+
+ XUD_ep ep0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep0);
+
+ if(fail)
+ TerminateFail(fail);
+ else
+ TerminatePass(fail);
+
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/test_stall_basic.py b/tests/test_stall_basic.py
new file mode 100644
index 00000000..7ee02d3a
--- /dev/null
+++ b/tests/test_stall_basic.py
@@ -0,0 +1,111 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ if bus_speed == "FS":
+ pytest.xfail("Known failure at FS")
+
+ pktLength = 10
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ ep_ctrl = ep + 1
+
+ # Expect test EP's to be halted
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ halted=True,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ halted=True,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ halted=True,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ halted=True,
+ )
+ )
+
+ # Valid transaction to another EP informing test code to clear stall
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_ctrl,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=1000,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
+
+
+# for result in RunUsbTest(
+# gen_test_session, test_arch, test_ep, test_address, test_bus_speed, __file__
+# ):
+# assert result
diff --git a/tests/test_stall_basic/Makefile b/tests/test_stall_basic/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_stall_basic/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_stall_basic/src/main.xc b/tests/test_stall_basic/src/main.xc
new file mode 100644
index 00000000..4283bfb6
--- /dev/null
+++ b/tests/test_stall_basic/src/main.xc
@@ -0,0 +1,72 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+#include
+#include
+#include
+#include "xud.h"
+#include "platform.h"
+#include "shared.h"
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+
+#ifndef TEST_EP_NUM
+#error
+#endif
+
+#ifndef CTRL_EP_NUM
+#define CTRL_EP_NUM (TEST_EP_NUM + 1)
+#endif
+
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned failed = 0;
+ uint8_t outBuffer[128];
+ uint8_t inBuffer[128];
+ unsigned length;
+ XUD_Result_t result;
+
+ for(size_t i = 0; i < sizeof(outBuffer); i++)
+ inBuffer[i] = i;
+
+ /* Stall EPs */
+ XUD_ep ep_out = XUD_InitEp(c_ep_out[TEST_EP_NUM]);
+ XUD_SetStall(ep_out);
+
+ XUD_ep ep_in = XUD_InitEp(c_ep_in[TEST_EP_NUM]);
+ XUD_SetStall(ep_in);
+
+ XUD_ep ep_ctrl = XUD_InitEp(c_ep_out[CTRL_EP_NUM]);
+
+ /* Valid transaction on another EP, clear STALL on the test EP's */
+ result = XUD_GetBuffer(ep_ctrl, outBuffer, length);
+ failed = (result != XUD_RES_OKAY);
+
+ /* Clear stall on the test EP's */
+ XUD_ClearStall(ep_out);
+ XUD_ClearStall(ep_in);
+
+ /* Ensure test EP's now operate as expected */
+ result = XUD_GetBuffer(ep_out, outBuffer, length);
+ failed |= (result != XUD_RES_OKAY);
+
+ result = XUD_SetBuffer(ep_in, inBuffer, PKT_LENGTH_START);
+ failed |= (result != XUD_RES_OKAY);
+
+ return failed;
+}
+
+#include "test_main.xc"
+
+
diff --git a/tests/test_stall_control.py b/tests/test_stall_control.py
new file mode 100644
index 00000000..1705dd42
--- /dev/null
+++ b/tests/test_stall_control.py
@@ -0,0 +1,159 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import (
+ TokenPacket,
+ TxDataPacket,
+ RxDataPacket,
+ TxHandshakePacket,
+ RxHandshakePacket,
+ USB_PID,
+)
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+from copy import deepcopy
+
+# Only test on EP 0 - Update params
+PARAMS = deepcopy(PARAMS)
+PARAMS["default"].update({"ep": [0]})
+PARAMS["smoke"].update({"ep": [0]})
+PARAMS["extended"].update({"ep": [0]})
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed, dummy_threads):
+
+ ied = 500
+ pktLength = 10
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ #### Ctrl transaction 0
+
+ # SETUP transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=address,
+ endpoint=ep,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 8),
+ pid=USB_PID["DATA0"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
+
+ # OUT transaction
+ # Note, quite big gap to avoid nak
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["OUT"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=10000,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 10),
+ pid=USB_PID["DATA1"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
+
+ # Expect 0 length IN transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["IN"], address=address, endpoint=ep, interEventDelay=ied
+ )
+ )
+ session.add_event(RxDataPacket(dataPayload=[], pid=USB_PID["DATA1"]))
+ session.add_event(TxHandshakePacket())
+
+ #### Ctrl transaction 1
+
+ # SETUP transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=10000,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 8),
+ pid=USB_PID["DATA0"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
+
+ # Check that the EP is now Halted
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="CONTROL",
+ direction="IN",
+ dataLength=pktLength,
+ halted=True,
+ interEventDelay=1000,
+ )
+ )
+
+ #### Ctrl transaction 2
+
+ # SETUP transaction
+ session.add_event(
+ TokenPacket(
+ pid=USB_PID["SETUP"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=10000,
+ )
+ )
+ session.add_event(
+ TxDataPacket(
+ dataPayload=session.getPayload_out(ep, 8),
+ pid=USB_PID["DATA0"],
+ )
+ )
+ session.add_event(RxHandshakePacket())
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="CONTROL",
+ direction="IN",
+ dataLength=pktLength,
+ halted=False,
+ interEventDelay=1000,
+ resetDataPid=True,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=0,
+ halted=False,
+ interEventDelay=1000,
+ resetDataPid=True,
+ )
+ )
+
+ return session
diff --git a/tests/test_stall_control/Makefile b/tests/test_stall_control/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_stall_control/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_stall_control/src/main.xc b/tests/test_stall_control/src/main.xc
new file mode 100644
index 00000000..72541d00
--- /dev/null
+++ b/tests/test_stall_control/src/main.xc
@@ -0,0 +1,79 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include "shared.h"
+
+#define EP_COUNT_OUT (5)
+#define EP_COUNT_IN (5)
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_ISO, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+int TestEp_Control(XUD_ep ep0_out, XUD_ep ep0_in, int epNum)
+{
+ unsigned int slength;
+ unsigned int length;
+
+ XUD_Result_t sres;
+ XUD_Result_t res;
+
+ unsigned char sbuffer[120];
+ unsigned char buffer[120];
+
+ /* Wait for Setup data */
+ sres = XUD_GetSetupBuffer(ep0_out, sbuffer, slength);
+
+ res = XUD_GetBuffer(ep0_out, buffer, length);
+
+ res = SendTxPacket(ep0_in, 0, epNum);
+
+ /* Checking for the Setup */
+ if(sres != XUD_RES_OKAY)
+ {
+ return 1;
+ }
+
+ if(RxDataCheck(sbuffer, slength, epNum, 8))
+ {
+ return 1;
+ }
+
+ /* Checking for the OUT buffer */
+ if(res != XUD_RES_OKAY)
+ {
+ return 1;
+ }
+
+ if(RxDataCheck(buffer, length, epNum, 10))
+ {
+ return 1;
+ }
+
+ sres = XUD_GetSetupBuffer(ep0_out, sbuffer, slength);
+
+ /* Stall the EP(s) as if the request was not recognised */
+ XUD_SetStall(ep0_out);
+ XUD_SetStall(ep0_in);
+
+ /* Check that EP is un-Halted on a SETUP */
+ sres = XUD_GetSetupBuffer(ep0_out, sbuffer, slength);
+
+ res = SendTxPacket(ep0_in, 10, epNum);
+
+ res = XUD_GetBuffer(ep0_out, buffer, length);
+
+ return 0;
+}
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ XUD_ep ep0_out = XUD_InitEp(c_ep_out[0]);
+ XUD_ep ep0_in = XUD_InitEp(c_ep_in[0]);
+
+ unsigned failed = TestEp_Control(ep0_out, ep0_in, 0);
+
+ XUD_Kill(ep0_out);
+
+ return failed;
+}
+#include "test_main.xc"
diff --git a/tests/test_stall_epready.py b/tests/test_stall_epready.py
new file mode 100644
index 00000000..2615d300
--- /dev/null
+++ b/tests/test_stall_epready.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+# Directed test for (github) issue #58
+from usb_packet import *
+import usb_packet
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ pktLength = 10
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ ep_ctrl = ep + 1
+
+ # Expect test EP's to be halted
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ halted=True,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ halted=True,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ halted=True,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ halted=True,
+ )
+ )
+
+ # Inform DUT to un halt EP's
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep_ctrl,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ # Expect normal transactions
+ # DUT will exit after one normal transaction per EP.
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ )
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="IN",
+ dataLength=pktLength,
+ )
+ )
+
+ return session
diff --git a/tests/test_stall_epready/Makefile b/tests/test_stall_epready/Makefile
new file mode 100644
index 00000000..a2c9ee98
--- /dev/null
+++ b/tests/test_stall_epready/Makefile
@@ -0,0 +1,3 @@
+TEST_FLAGS = -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_stall_epready/src/main.xc b/tests/test_stall_epready/src/main.xc
new file mode 100644
index 00000000..384405c2
--- /dev/null
+++ b/tests/test_stall_epready/src/main.xc
@@ -0,0 +1,74 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+
+#define EP_COUNT_OUT (6)
+#define EP_COUNT_IN (6)
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START (10)
+#endif
+
+#ifndef TEST_EP_NUM
+#define TEST_EP_NUM (1)
+#endif
+
+#ifndef CTRL_EP_NUM
+#define CTRL_EP_NUM (TEST_EP_NUM + 1)
+#endif
+
+#include "shared.h"
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+unsigned test_func(chanend c_ep_out[EP_COUNT_OUT], chanend c_ep_in[EP_COUNT_IN])
+{
+ unsigned failed = 0;
+ uint8_t outBuffer[128];
+ uint8_t ctrlBuffer[128];
+ uint8_t inBuffer[128];
+ unsigned length;
+ XUD_Result_t result;
+
+ for(size_t i = 0; i < sizeof(outBuffer); i++)
+ inBuffer[i] = i;
+
+ XUD_ep ep_ctrl = XUD_InitEp(c_ep_out[CTRL_EP_NUM]);
+
+ XUD_ep ep_out = XUD_InitEp(c_ep_out[TEST_EP_NUM]);
+ XUD_ep ep_in = XUD_InitEp(c_ep_in[TEST_EP_NUM]);
+ XUD_SetStall(ep_out);
+ XUD_SetStall(ep_in);
+
+ XUD_SetReady_Out(ep_out, outBuffer);
+ XUD_SetReady_In(ep_in, inBuffer, PKT_LENGTH_START);
+ XUD_SetReady_Out(ep_ctrl, ctrlBuffer);
+
+ unsigned loop0 = 1;
+ unsigned loop1 = 1;
+ while(loop0 | loop1)
+ {
+ select
+ {
+ case XUD_GetData_Select(c_ep_out[TEST_EP_NUM], ep_out, length, result):
+ loop0 = 0;
+ break;
+
+ case XUD_GetData_Select(c_ep_out[CTRL_EP_NUM], ep_ctrl, length, result):
+ XUD_ClearStall(ep_out);
+ XUD_ClearStall(ep_in);
+ break;
+
+ case XUD_SetData_Select(c_ep_in[TEST_EP_NUM], ep_in, result):
+ loop1 = 0;
+ break;
+ }
+ failed |= (result != XUD_RES_OKAY);
+ }
+
+ return failed;
+}
+
+#include "test_main.xc"
diff --git a/tests/test_suspend_resume.py b/tests/test_suspend_resume.py
new file mode 100644
index 00000000..68aff185
--- /dev/null
+++ b/tests/test_suspend_resume.py
@@ -0,0 +1,55 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import CreateSofToken
+from usb_signalling import UsbSuspend, UsbResume
+from usb_session import UsbSession
+from usb_transaction import UsbTransaction
+import pytest
+from conftest import PARAMS, test_RunUsbSession
+
+
+@pytest.fixture
+def test_session(ep, address, bus_speed):
+
+ start_length = 10
+ end_length = 12
+ pktLength = 10
+ frameNumber = 52 # Note, for frame number 52 we expect A5 34 40 on the bus
+
+ session = UsbSession(
+ bus_speed=bus_speed, run_enumeration=False, device_address=address
+ )
+
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=0,
+ )
+ )
+
+ session.add_event(CreateSofToken(frameNumber))
+
+ session.add_event(UsbSuspend(350000))
+ session.add_event(UsbResume())
+
+ frameNumber = frameNumber + 1
+ pktLength = pktLength + 1
+ session.add_event(CreateSofToken(frameNumber, interEventDelay=2000))
+ session.add_event(
+ UsbTransaction(
+ session,
+ deviceAddress=address,
+ endpointNumber=ep,
+ endpointType="BULK",
+ direction="OUT",
+ dataLength=pktLength,
+ interEventDelay=0,
+ )
+ )
+
+ return session
diff --git a/tests/test_suspend_resume/Makefile b/tests/test_suspend_resume/Makefile
new file mode 100644
index 00000000..6dd0ad9e
--- /dev/null
+++ b/tests/test_suspend_resume/Makefile
@@ -0,0 +1,4 @@
+
+TEST_FLAGS = -DSUSPEND_TIMEOUT_us=300 -DSUSPEND_T_WTWRSTHS_us=20 -DXUD_BYPASS_RESET=1
+
+include ../test_makefile.mak
diff --git a/tests/test_suspend_resume/src/main.xc b/tests/test_suspend_resume/src/main.xc
new file mode 100644
index 00000000..0d6d6e90
--- /dev/null
+++ b/tests/test_suspend_resume/src/main.xc
@@ -0,0 +1,68 @@
+// Copyright 2016-2021 XMOS LIMITED.
+// This Software is subject to the terms of the XMOS Public Licence: Version 1.
+#include
+#include
+#include
+#include "xud.h"
+#include "platform.h"
+#include "shared.h"
+
+#define XUD_EP_COUNT_OUT 5
+#define XUD_EP_COUNT_IN 5
+
+#ifndef PKT_LENGTH_START
+#define PKT_LENGTH_START 10
+#endif
+
+#ifndef PKT_LENGTH_END
+#define PKT_LENGTH_END 11
+#endif
+
+#ifndef TEST_EP_NUM
+#error
+#endif
+
+/* Endpoint type tables */
+XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL, XUD_EPTYPE_BUL};
+
+#ifdef XUD_SIM_RTL
+int testmain()
+#else
+int main()
+#endif
+{
+ chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
+
+ par
+ {
+ {
+ #if defined(XUD_TEST_SPEED_FS)
+ unsigned speed = XUD_SPEED_FS;
+ #elif defined(XUD_TEST_SPEED_HS)
+ unsigned speed = XUD_SPEED_HS;
+ #else
+ #error XUD_TEST_SPEED_XX not defined
+ #endif
+
+ XUD_Main(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN,
+ null, epTypeTableOut, epTypeTableIn, speed, XUD_PWR_BUS);
+ }
+
+ {
+ unsigned fail = TestEp_Rx(c_ep_out[TEST_EP_NUM], TEST_EP_NUM, PKT_LENGTH_START, PKT_LENGTH_END);
+
+
+ XUD_ep ep0 = XUD_InitEp(c_ep_out[0]);
+ XUD_Kill(ep0);
+
+ if(fail)
+ TerminateFail(fail);
+ else
+ TerminatePass(fail);
+
+ }
+ }
+
+ return 0;
+}
diff --git a/tests/usb_clock.py b/tests/usb_clock.py
index 7ae37d04..a39a59f8 100644
--- a/tests/usb_clock.py
+++ b/tests/usb_clock.py
@@ -1,47 +1,52 @@
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
-import xmostest
+from Pyxsim import SimThread
import sys
import zlib
-class Clock(xmostest.SimThread):
- (CLK_125MHz, CLK_60MHz, CLK_2_5MHz) = (0x4, 0x2, 0x0)
+class Clock(SimThread):
- def __init__(self, port, clk):
+ CLK_60MHz = 0x0
+
+ def __init__(self, port, clk, coreFreq_Mhz):
self._running = True
self._clk = clk
- if clk == self.CLK_125MHz:
- self._period = float(1000000000) / 125000000
- self._name = '125Mhz'
- self._min_ifg = 96
- self._bit_time = 1
- elif clk == self.CLK_60MHz:
- self._period = float(1000000000) / 60000000
- self._name = '60Mhz'
- self._bit_time = 5 # TODO
- elif clk == self.CLK_2_5MHz:
- self._period = float(1000000000) / 2500000
- self._name = '2.5Mhz'
- self._bit_time = 100
- self._min_ifg = 96 * self._bit_time
+ if clk == self.CLK_60MHz:
+ self._period = float(1000000000.0 / 60000000.0)
+ self._period *= (1.0 / coreFreq_Mhz) * 1000.0
+ self._name = "60Mhz"
+ else:
+ raise ValueError("Unsupported Clock Frequency")
self._val = 0
self._port = port
def run(self):
+
+ time = self.xsi.get_time()
+
while True:
- self.wait_until(self.xsi.get_time() + self._period/2)
+
+ time += self._period / 2
+ self.wait_until(time)
self._val = 1 - self._val
if self._running:
- #print "{}".format(self._val)
- self.xsi.drive_port_pins(self._port, self._val)
+ self.xsi.drive_periph_pin(self._port, self._val)
+
+ @property
+ def period_ns(self):
+ return self._period
+
+ @property
+ def period_us(self):
+ return self._period / 1000
def is_high(self):
- return (self._val == 1)
+ return self._val == 1
def is_low(self):
- return (self._val == 0)
+ return self._val == 0
def get_rate(self):
return self._clk
@@ -49,14 +54,8 @@ def get_rate(self):
def get_name(self):
return self._name
- def get_min_ifg(self):
- return self._min_ifg
-
- def get_bit_time(self):
- return self._bit_time
-
def stop(self):
- print "**** CLOCK STOP ****"
+ print("**** CLOCK STOP ****")
self._running = False
def start(self):
diff --git a/tests/usb_event.py b/tests/usb_event.py
new file mode 100644
index 00000000..f445eb91
--- /dev/null
+++ b/tests/usb_event.py
@@ -0,0 +1,36 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from abc import ABC, abstractmethod, abstractproperty
+
+
+class UsbEvent(ABC):
+ def __init__(self, time=0, interEventDelay=None):
+ self._time = time
+ self._interEventDelay = interEventDelay
+
+ # TODO so we want to use relative delays or absolute times?
+ @property
+ def time(self):
+ return self._time
+
+ # NOTE: its not always sensible for an event to used the IED - for example an Rx Packet
+ @property
+ def interEventDelay(self):
+ return self._interEventDelay
+
+ @abstractmethod
+ def expected_output(self, bus_speed, offset=0):
+ pass
+
+ # Drive event to simulator
+ @abstractmethod
+ def drive(self, usb_phy, bus_speed):
+ pass
+
+ # Note, an event might contain events
+ @abstractproperty
+ def event_count(self):
+ pass
+
+ def __str__(self):
+ return "UsbEvent: IED: " + str(self.interEventDelay)
diff --git a/tests/usb_packet.py b/tests/usb_packet.py
index 0377f65d..2531622b 100644
--- a/tests/usb_packet.py
+++ b/tests/usb_packet.py
@@ -1,246 +1,589 @@
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+""" Define packet types
+
+Packet Class Hierarchy
+----------------------
+
++-----------+
+| Object |
++-----------+
+ ^
+ |
++-----------+
+| UsbPacket |
++-----------+
+ ^
+ | +------------+
+ |-------| DataPacket |
+ | +------------+
+ |
+ | +-----------------+
+ |-------| HandshakePacket |
+ | +-----------------+
+ |
+ | +----------+
+ |-------| RxPacket |
+ | +----------+
+ |
+ | +----------+
+ --------| TxPacket |
+ +----------+
+ ^
+ |
+ +-------------+
+ | TokenPacket |
+ +-------------+
+
++----------+ +------------+ +----------+
+| RxPacket | | DataPacket | | TxPacket |
++----------+ +------------+ +----------+
+ ^ ^ ^ ^
+ | | | |
+ ------------- --------------
+ | |
+ +--------------+ +--------------+
+ | RxDataPacket | | TxDataPacket |
+ +--------------+ +--------------+
+
++----------+ +-----------------+ +----------+
+| RxPacket | | HandshakePacket | | TxPacket |
++----------+ +-----------------+ +----------+
+ ^ ^ ^ ^
+ | | | |
+ ------------- --------------
+ | |
+ +-------------------+ +-------------------+
+ | RxHandshakePacket | | TxHandshakePacket |
+ +-------------------+ +-------------------+
+"""
+
+from usb_event import UsbEvent
+import usb_phy
+
+
+USB_DATA_VALID_COUNT = {"FS": 39, "HS": 0}
+
+# In USB clocks
+RXA_END_DELAY = 2 # Pad delay not currently simulated in xsim for USB or OTP, so add this delay here
+RXA_START_DELAY = 5 # Taken from RTL sim
+
+# TODO shoud we have a PID class?
+# TODO remove the inverted check bits
+USB_PID = {
+ "OUT": 0xE1,
+ "ACK": 0xD2,
+ "DATA0": 0xC3,
+ "PING": 0xB4,
+ "SOF": 0xA5,
+ "DATA1": 0x4B,
+ "IN": 0x69,
+ "NAK": 0x5A,
+ "SETUP": 0x2D,
+ "STALL": 0x1E,
+ "RESERVED": 0x0F,
+}
+
+
+def CreateSofToken(frameNumber, badCrc=False, interEventDelay=1000):
+ ep = (frameNumber >> 7) & 0xF
+ address = (frameNumber) & 0x7F
+
+ if badCrc:
+ return TokenPacket(
+ pid=USB_PID["SOF"],
+ address=address,
+ endpoint=ep,
+ crc5=0xFF,
+ interEventDelay=interEventDelay,
+ )
+ else:
+ return TokenPacket(
+ pid=USB_PID["SOF"],
+ address=address,
+ endpoint=ep,
+ interEventDelay=interEventDelay,
+ )
-import sys
-import zlib
-import random
-def AppendSetupToken(packets, ep, **kwargs):
- ipg = kwargs.pop('inter_pkt_gap', 500)
- AppendTokenPacket(packets, 0x2d, ep, ipg)
-
-def AppendOutToken(packets, ep, **kwargs):
- ipg = kwargs.pop('inter_pkt_gap', 500)
- AppendTokenPacket(packets, 0xe1, ep, ipg)
+def reflect(val, numBits):
-def AppendPingToken(packets, ep, **kwargs):
- ipg = kwargs.pop('inter_pkt_gap', 500)
- AppendTokenPacket(packets, 0xb4, ep, ipg)
+ valRef = 0
+ for i in range(numBits):
+ valRef <<= 1
-def AppendInToken(packets, ep, **kwargs):
+ if val & 1:
+ valRef |= 1
- #357 was min IPG supported on bulk loopback to not nak
- #lower values mean the loopback NAKs
- ipg = kwargs.pop('inter_pkt_gap', 10)
- AppendTokenPacket(packets, 0x69, ep, ipg)
+ val >>= 1
-
-def AppendTokenPacket(packets, _pid, ep, ipg):
-
- packets.append(TokenPacket(
- inter_pkt_gap=ipg,
- pid=_pid,
- address=0,
- endpoint=ep))
+ return valRef
-def reflect(val, numBits):
- valRef = 0;
- for i in range(numBits):
- valRef <<= 1;
-
- if (val & 1):
- valRef |= 1;
-
- val >>= 1;
-
- return valRef;
-
-def GenCrc16(args):
-
- data = args
-
- crc = 0xffff;
- poly = 0x8005;
-
- for byte in data:
- topBit = 1 << 15;
- crc ^= reflect(int(byte) & int(0xFF), 8) << 8;
-
- for k in range(0,8):
- if crc & topBit:
- crc = (crc << 1) ^ poly;
+def GenCrc16(data: bytes):
+ poly = 0xA001
+ crc = 0xFFFF
+ for b in data:
+ crc ^= 0xFF & b
+ for _ in range(0, 8):
+ if crc & 0x0001:
+ crc = (crc >> 1) ^ poly
else:
- crc <<= 1;
+ crc >>= 1
+
+ return crc ^ 0xFFFF
+
+
+def GenCrc5(args):
+ poly = 0x14
+ crc = 0x1F
+ n = args & 0x7FF
+ i = 11
+
+ while i > 0:
+ if (n ^ crc) & 1:
+ crc = (crc >> 1) ^ poly
+ else:
+ crc >>= 1
+ i -= 1
+ n >>= 1
+
+ # Invert contents to generate crc field
+ crc ^= 0x1F
+
+ return crc
- #//crc = crc ^0xffff;
- crc = reflect(crc,16);
- crc = ~crc;
- crc = crc & 0xffff;
- #print "CRC: : {0:#x}".format(crc)
- return crc;
# Functions for creating the data contents of packets
def create_data(args):
- f_name,f_args = args
- func = 'create_data_{}'.format(f_name)
+ f_name, f_args = args
+ func = "create_data_{}".format(f_name)
return globals()[func](f_args)
+
def create_data_step(args):
- step,num_data_bytes = args
- return [(step * i) & 0xff for i in range(num_data_bytes)]
+ step, num_data_bytes = args
+ return [(step * i) & 0xFF for i in range(num_data_bytes)]
+
def create_data_same(args):
- value,num_data_bytes = args
- return [value & 0xff for i in range(num_data_bytes)]
+ value, num_data_bytes = args
+ return [value & 0xFF for i in range(num_data_bytes)]
# Functions for creating the expected output that the DUT will print given
# this packet
def create_data_expect(args):
- f_name,f_args = args
- func = 'create_data_expect_{}'.format(f_name)
+ f_name, f_args = args
+ func = "create_data_expect_{}".format(f_name)
return globals()[func](f_args)
+
def create_data_expect_step(args):
- step,num_data_bytes = args
+ step, num_data_bytes = args
return "Step = {0}\n".format(step)
+
def create_data_expect_same(args):
- value,num_data_bytes = args
+ value, num_data_bytes = args
return "Value = {0}\n".format(value)
+
+class BusReset(object):
+ def __init__(self, **kwargs):
+ self.duration_ms = kwargs.pop("duraton", 10) # Duration of reset
+ self.bus_speed = kwargs.pop("bus_speed", "high") # Bus speed to reset into
+
+
# Lowest base class for all packets. All USB packets have:
# - a PID
# - some (or none) data bytes
-class UsbPacket(object):
-
+class UsbPacket(UsbEvent):
def __init__(self, **kwargs):
- self.pid = kwargs.pop('pid', 0xc3)
- self.num_data_bytes = kwargs.pop('length', 0)
- self.data_bytes = None
- self.data_valid_count = kwargs.pop('data_valid_count', 0)
- self.bad_crc = kwargs.pop('bad_crc', False)
+ self.pid = kwargs.pop("pid", 0xC3)
+ self.data_bytes = kwargs.pop("data_bytes", None)
+ self.num_data_bytes = kwargs.pop("length", 0)
+ self.bad_crc = kwargs.pop("bad_crc", False)
+ ied = kwargs.pop("interEventDelay", None)
+ super(UsbPacket, self).__init__(interEventDelay=ied)
- def get_data_valid_count(self):
- return self.data_valid_count
+ @property
+ def event_count(self):
+ return 1
+ def __str__(self):
+ return super().__str__() + " USBPacket"
+
+ def get_pid_str(self):
+ for key, value in USB_PID.items():
+ if value == self.pid:
+ return key
+ return "UNKNOWN"
-#Rx to host i.e. xCORE Tx
-class RxPacket(UsbPacket):
+# Rx to host i.e. xCORE Tx
+class RxPacket(UsbPacket):
def __init__(self, **kwargs):
- self.timeout = kwargs.pop('timeout', 8)
+ self._timeout = kwargs.pop(
+ "timeout", usb_phy.USB_PKT_TIMINGS["TX_TO_RX_PACKET_TIMEOUT"]
+ )
super(RxPacket, self).__init__(**kwargs)
+ @property
+ def timeout(self):
+ return self._timeout
- def get_timeout(self):
- return self.timeout
+ def expected_output(self, bus_speed, offset=0):
+ expected_output = "Packet:\tDEVICE -> HOST\n"
-#Tx from host i.e. xCORE Rx
-class TxPacket(UsbPacket):
+ for (i, byte) in enumerate(self.get_bytes()):
+ expected_output += "\tRX byte: {0:#x}\n".format(byte)
- def __init__(self, **kwargs):
- self.inter_pkt_gap = kwargs.pop('inter_pkt_gap', 13) #13 lowest working for single issue loopback
- self.rxa_start_delay = kwargs.pop('rxa_start_delay', 2)
- self.rxa_end_delay = kwargs.pop('rxa_end_delay', 2)
- self.rxe_assert_time = kwargs.pop('rxe_assert_time', 0)
- self.rxe_assert_length = kwargs.pop('rxe_assert_length', 1)
- super(TxPacket, self).__init__(**kwargs)
+ return expected_output
- def get_inter_pkt_gap(self):
- return self.inter_pkt_gap
+ def drive(self, usb_phy, bus_speed):
-# DataPacket class, inherits from Usb Packet
-class DataPacket(UsbPacket):
+ wait = usb_phy.wait
+ xsi = usb_phy.xsi
+
+ timeout = self.timeout
+ in_rx_packet = False
+ rx_packet = []
+
+ while timeout != 0:
+
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ timeout = timeout - 1
+
+ # sample TXV for new packet
+ if xsi.sample_port_pins(usb_phy._txv) == 1:
+ print("Packet:\tDEVICE -> HOST")
+ in_rx_packet = True
+ break
+
+ if in_rx_packet == False:
+ print("ERROR: Timed out waiting for packet")
+ else:
+ while in_rx_packet == True:
+
+ # TODO txrdy pulsing
+ xsi.drive_port_pins(usb_phy._txrdy, 1)
+ data = xsi.sample_port_pins(usb_phy._txd)
+
+ print("\tRX byte: {0:#x}".format(data))
+ rx_packet.append(data)
+
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ if xsi.sample_port_pins(usb_phy._txv) == 0:
+ # TxV low, break out of loop
+ in_rx_packet = False
+
+ # End of packet
+ xsi.drive_port_pins(usb_phy._txrdy, 0)
+ # Check packet against expected
+ expected = self.get_bytes(do_tokens=False)
+ if len(expected) != len(rx_packet):
+ print(
+ "ERROR: Rx packet length bad. Expecting: {} actual: {}".format(
+ len(expected), len(rx_packet)
+ )
+ )
+
+ # Check packet data against expected
+ if expected != rx_packet:
+ print("ERROR: Rx Packet Error. Expected:")
+ for item in expected:
+ print("{0:#x}".format(item))
+
+ print("Received:")
+ for item in rx_packet:
+ print("{0:#x}".format(item))
+
+
+# Tx from host i.e. xCORE Rx
+class TxPacket(UsbPacket):
def __init__(self, **kwargs):
- super(DataPacket, self).__init__(**kwargs)
- self.pid = kwargs.pop('pid', 0x3) #DATA0
- data_start_val = kwargs.pop('data_start_val', None)
+ self.rxa_start_delay = kwargs.pop("rxa_start_delay", 2)
+ self.rxa_end_delay = kwargs.pop("rxa_end_delay", RXA_END_DELAY)
+ self.rxe_assert_time = kwargs.pop("rxe_assert_time", 0)
+ self.rxe_assert_length = kwargs.pop("rxe_assert_length", 1)
+
+ ied = kwargs.pop(
+ "interEventDelay", usb_phy.USB_PKT_TIMINGS["TX_TO_TX_PACKET_DELAY"]
+ )
+ super(TxPacket, self).__init__(**kwargs, interEventDelay=ied)
+
+ def expected_output(self, bus_speed, offset=0):
+ expected_output = "Packet:\tHOST -> DEVICE\n"
+ expected_output += "\tPID: {} ({:#x})\n".format(self.get_pid_str(), self.pid)
+ return expected_output
+
+ def drive(self, usb_phy, bus_speed, verbose=True):
+
+ xsi = usb_phy.xsi
+ wait = usb_phy.wait
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(usb_phy._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE (TxPacket 0)")
+
+ rxv_count = USB_DATA_VALID_COUNT[bus_speed]
+
+ usb_phy.wait_for_clocks(self.interEventDelay)
- if data_start_val != None:
- self.data_bytes = [x+data_start_val for x in range(self.num_data_bytes)]
+ print(
+ "Packet:\tHOST -> DEVICE\n\tPID: {0} ({1:#x})".format(
+ self.get_pid_str(), self.pid
+ )
+ )
+
+ # Set RXA high to USB shim
+ xsi.drive_periph_pin(usb_phy._rxa, 1)
+
+ # Wait for RXA start delay
+ rxa_start_delay = RXA_START_DELAY
+
+ while rxa_start_delay != 0:
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+ rxa_start_delay = rxa_start_delay - 1
+
+ for (i, byte) in enumerate(self.get_bytes(do_tokens=False)):
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(usb_phy._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE (TxPacket 1)")
+
+ wait(lambda x: usb_phy._clock.is_low())
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+ xsi.drive_periph_pin(usb_phy._rxdv, 1)
+ xsi.drive_periph_pin(usb_phy._rxd, byte)
+
+ if (self.rxe_assert_time != 0) and (self.rxe_assert_time == i):
+ xsi.drive_periph_pin(usb_phy._rxer, 1)
+
+ while rxv_count != 0:
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+ xsi.drive_periph_pin(usb_phy._rxdv, 0)
+ rxv_count = rxv_count - 1
+
+ # xCore should not be trying to send if we are trying to send..
+ # We assume that the Phy internally blocks the TXValid signal to the Transmit State Machine
+ # until the Rx packet has completed
+
+ # if xsi.sample_port_pins(usb_phy._txv) == 1:
+ # print("ERROR: Unexpected packet from xCORE (TxPacket 2)")
+
+ rxv_count = USB_DATA_VALID_COUNT[bus_speed]
+
+ # Wait for last byte
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ xsi.drive_periph_pin(usb_phy._rxdv, 0)
+ xsi.drive_periph_pin(usb_phy._rxer, 0)
+
+ rxa_end_delay = self.rxa_end_delay
+
+ while rxa_end_delay != 0:
+ # Wait for RXA fall delay TODO, this should be configurable
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+ rxa_end_delay = rxa_end_delay - 1
+
+ # xCore should not be trying to send if we are trying to send..
+ # We assume that the Phy internally blocks the TXValid signal to the Transmit State Machine
+ # until the Rx packet has completed
+
+ # if xsi.sample_port_pins(usb_phy._txv) == 1:
+ # print("ERROR: Unexpected packet from xCORE (TxPacket 3)")
+
+ xsi.drive_periph_pin(usb_phy._rxa, 0)
+
+ # Implemented such that we can generate malformed packets
+ def get_bytes(self, do_tokens=False):
+ bytes = []
+ if do_tokens:
+ bytes.append(self.pid)
else:
- self.data_bytes = [x for x in range(self.num_data_bytes)]
+ bytes.append(self.pid | ((~self.pid) << 4))
+ for x in range(len(self.data_bytes)):
+ bytes.append(self.data_bytes[x])
+ return bytes
+# DataPacket class, inherits from Usb Packet
+class DataPacket(UsbPacket):
+ def __init__(self, dataPayload=[], **kwargs):
+ super(DataPacket, self).__init__(**kwargs)
+ self.pid = kwargs.pop("pid", 0x3) # DATA0
+ self.data_bytes = dataPayload
+
def get_packet_bytes(self):
packet_bytes = []
packet_bytes = self.data_bytes
return packet_bytes
-
+
def get_crc(self, packet_bytes):
- crc = GenCrc16(packet_bytes)
+ crc = GenCrc16(packet_bytes)
return crc
- def get_bytes(self):
+ def get_bytes(self, do_tokens=False):
+
bytes = []
- bytes.append(self.pid)
+ if do_tokens:
+ bytes.append(self.pid)
+ else:
+ bytes.append(self.pid | (((~self.pid) & 0xF) << 4))
packet_bytes = self.get_packet_bytes()
for byte in packet_bytes:
bytes.append(byte)
if self.bad_crc == True:
- crc = 0xbeef
- else:
+ crc = 0xBEEF
+ else:
crc = self.get_crc(packet_bytes)
# Append the 2 bytes of CRC onto the packet
for i in range(0, 2):
- bytes.append((crc >> (8*i)) & 0xff)
+ bytes.append((crc >> (8 * i)) & 0xFF)
return bytes
class RxDataPacket(RxPacket, DataPacket):
-
- def __init__(self, rand, **kwargs):
- _pid = self.pid = kwargs.pop('pid', 0x3) #DATA0
+ def __init__(self, **kwargs):
+ _pid = self.pid = kwargs.pop("pid", 0x3) # DATA0
- #Re-construct full PID - xCORE sends out full PIDn | PID on Tx
- super(RxDataPacket, self).__init__(pid = (_pid & 0xf) | (((~_pid)&0xf) << 4), **kwargs)
+ # Re-construct full PID - xCORE sends out full PIDn | PID on Tx
+ super(RxDataPacket, self).__init__(
+ pid=(_pid & 0xF) | (((~_pid) & 0xF) << 4), **kwargs
+ )
-class TxDataPacket(TxPacket, DataPacket):
+ def __str__(self):
+ return (
+ super(DataPacket, self).__str__()
+ + ": RX DataPacket: "
+ + super(DataPacket, self).get_pid_str()
+ + " "
+ + str(self.data_bytes)
+ )
- def __init__(self, rand, **kwargs):
- super(TxDataPacket, self).__init__(**kwargs)
- #self.inter_pkt_gap = kwargs.pop('inter_pkt_gap', 13) #13 lowest working for single issue loopback
+class TxDataPacket(DataPacket, TxPacket):
+ def __init__(self, **kwargs):
+ super(TxDataPacket, self).__init__(**kwargs)
-#Always TX
+ def __str__(self):
+ return (
+ super(DataPacket, self).__str__()
+ + ": TX DataPacket: "
+ + super(DataPacket, self).get_pid_str()
+ + " "
+ + str(self.data_bytes)
+ + " Valid CRC: "
+ + str(not self.bad_crc)
+ + "RXE Assert: "
+ + str(self.rxe_assert_time)
+ )
+
+
+# Always TX
class TokenPacket(TxPacket):
-
def __init__(self, **kwargs):
super(TokenPacket, self).__init__(**kwargs)
- self.endpoint = kwargs.pop('endpoint', 0)
- self.valid = kwargs.pop('valid', 1)
-
- # Always override to match IFM
- self.data_valid_count = 4 #todo
+ self.endpoint = kwargs.pop("endpoint", 0)
+ self.valid = kwargs.pop("valid", 1)
+ self.address = kwargs.pop("address", 0)
+
+ # Generate correct crc5
+ crc5 = GenCrc5(((self.endpoint & 0xF) << 7) | ((self.address & 0x7F) << 0))
+
+ # Correct crc5 can be overridden
+ self.crc5 = kwargs.pop("crc5", crc5)
- def get_bytes(self):
+ # TODO Always override data_valid count to match IFM for archs < XS3
+
+ def get_bytes(self, do_tokens=False):
bytes = []
- bytes.append(self.pid & 0xf)
- bytes.append(self.endpoint)
+
+ if do_tokens:
+ bytes.append(self.pid & 0xF)
+ bytes.append(self.endpoint)
+ else:
+ bytes.append(self.pid)
+
+ tokenbyte0 = self.address | ((self.endpoint & 1) << 7)
+ tokenbyte1 = (self.endpoint >> 1) | (self.crc5 << 3)
+
+ bytes.append(tokenbyte0)
+ bytes.append(tokenbyte1)
+
return bytes
+ def __str__(self):
+ return (
+ super(TokenPacket, self).__str__()
+ + ": TokenPacket: "
+ + super(TokenPacket, self).get_pid_str()
+ )
+
# Token valid
def get_token_valid(self):
return self.valid
+
class HandshakePacket(UsbPacket):
-
def __init__(self, **kwargs):
super(HandshakePacket, self).__init__(**kwargs)
- self.pid = kwargs.pop('pid', 0x2) #Default to ACK
+ self.pid = kwargs.pop("pid", USB_PID["ACK"]) # Default to ACK
- def get_bytes(self):
+ def get_bytes(self, do_tokens=False):
bytes = []
bytes.append(self.pid)
return bytes
-class RxHandshakePacket(HandshakePacket, RxPacket):
+class RxHandshakePacket(HandshakePacket, RxPacket):
def __init__(self, **kwargs):
super(RxHandshakePacket, self).__init__(**kwargs)
- self.pid = kwargs.pop('pid', 0xd2) #Default to ACK (not expect inverted bits on Rx)
- self.timeout = kwargs.pop('timeout', 9)
+ self.pid = kwargs.pop(
+ "pid", 0xD2
+ ) # Default to ACK (not expect inverted bits on Rx)
+ # self._timeout = kwargs.pop("timeout", RX_TX_DELAY) # TODO handled by Super()
+
+ def __str__(self):
+ return (
+ super(RxHandshakePacket, self).__str__()
+ + ": RX HandshakePacket: "
+ + super(RxHandshakePacket, self).get_pid_str()
+ )
+
class TxHandshakePacket(HandshakePacket, TxPacket):
-
def __init__(self, **kwargs):
super(TxHandshakePacket, self).__init__(**kwargs)
+ def get_bytes(self, do_tokens=False):
+ bytes = []
+ if do_tokens:
+ bytes.append(self.pid)
+ else:
+ bytes.append(self.pid | ((~self.pid) << 4))
+ return bytes
+
+ def __str__(self):
+ return (
+ super(TxHandshakePacket, self).__str__()
+ + ": TX HandshakePacket: "
+ + super(TxHandshakePacket, self).get_pid_str()
+ )
diff --git a/tests/usb_phy.py b/tests/usb_phy.py
index a2d41e1f..ac21367a 100644
--- a/tests/usb_phy.py
+++ b/tests/usb_phy.py
@@ -1,44 +1,137 @@
# Copyright 2016-2021 XMOS LIMITED.
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
import random
-import xmostest
+import Pyxsim
import sys
import zlib
-from usb_packet import RxPacket, TokenPacket
-
-class TxPhy(xmostest.SimThread):
-
-
- # Time in ns from the last packet being sent until the end of test is signalled to the DUT
+import usb_packet
+
+USB_MAX_EP_ADDRESS = 15
+
+USB_LINESTATE = {
+ "IDLE": 0,
+ "FS_J": 2,
+ "FS_K": 1,
+ "HS_J": 1,
+ "HS_K": 2,
+}
+
+# TODO want two sets of these, one "spec" and one "fast" for testing
+USB_TIMINGS_SPEC = {
+ "IDLE_TO_FS_MIN_US": 300, # Spec: 3000
+ "IDLE_TO_FS_MAX_US": 312, # Spec: 3125
+ "RESUME_FSK_MIN_US": 200, # Spec: 20000us
+ "RESUME_SE0_US": 1.25, # 1.25uS - 1.5uS
+ "T_UCHEND": 7000, # Upstream Chirp end time
+ "T_UCH_US": 1000, # Upstream Chirp length
+ "T_WTDCH_US": 100,
+ "T_SIGATT_US": 100000, # Maximum time from Vbus valid to when the device must signal attach
+ "T_ATTDB_US": 10, # 100000 Debouce interval. The device now enters the HS Detection Handshake protocol
+ "T_DCHBIT_MIN_US": 40,
+ "T_DCHBIT_MAX_US": 60,
+ "CHIRP_COUNT_MIN": 3, # Minimum chirp pairs DUT must detect before moving into HS mode
+ "CHIRP_COUNT_MAX": 10, # TODO should these chirp defines be removed and use timing?
+}
+
+USB_TIMINGS_SHORT = {
+ "IDLE_TO_FS_MIN_US": 300, # Spec: 3000
+ "IDLE_TO_FS_MAX_US": 312, # Spec: 3125
+ "RESUME_FSK_MIN_US": 200, # Spec: 20000us
+ "RESUME_SE0_US": 1.25, # 1.25uS - 1.5uS
+ "T_UCHEND": 7000, # Upstream Chirp end time
+ "T_UCH_US": 10, # Upstream Chirp length
+ "T_WTDCH_US": 50,
+ "T_SIGATT_US": 100000, # Maximum time from Vbus valid to when the device must signal attach
+ "T_ATTDB_US": 10, # 100000 Debouce interval. The device now enters the HS Detection Handshake protocol
+ "T_DCHBIT_MIN_US": 4, # Spec: 40us
+ "T_DCHBIT_MAX_US": 6, # Spec: 60us
+ "CHIRP_COUNT_MIN": 3, # Minimum chirp pairs DUT must detect before moving into HS mode
+ "CHIRP_COUNT_MAX": 10, # TODO should these chirp defines be removed and use timing?
+}
+
+
+USB_PKT_TIMINGS_TIGHT = {
+ "TX_TO_RX_PACKET_TIMEOUT": 14, # Timeout between sending DUT a packet and the expected response (in USB clocks). This is SIE decision time in UTMI spec
+ "TX_TO_TX_PACKET_DELAY": 4, # Delay between transmitting two packets
+}
+
+
+USB_TIMINGS = USB_TIMINGS_SHORT
+USB_PKT_TIMINGS = USB_PKT_TIMINGS_TIGHT
+
+
+class UsbPhy(Pyxsim.SimThread):
+
+ # Time in ns from the last event packet being sent until the end of test
END_OF_TEST_TIME = 5000
- def __init__(self, name, rxd, rxa, rxdv, rxer, vld, txd, txv, txrdy, clock, initial_delay, verbose,
- test_ctrl, do_timeout, complete_fn, expect_loopback, dut_exit_time):
+ def __init__(
+ self,
+ name,
+ rxd,
+ rxa,
+ rxdv,
+ rxer,
+ txd,
+ txv,
+ txrdy,
+ ls,
+ xcvrsel,
+ termsel,
+ clock,
+ initial_delay,
+ verbose,
+ do_timeout,
+ complete_fn,
+ dut_exit_time,
+ ):
self._name = name
- self._test_ctrl = test_ctrl
- self._rxd = rxd #Rx data
- self._rxa = rxa #Rx Active
- self._rxdv = rxdv #Rx valid
- self._rxer = rxer #Rx Error
- self._vld = vld
+ self._rxd = rxd # Rx data
+ self._rxa = rxa # Rx Active
+ self._rxdv = rxdv # Rx valid
+ self._rxer = rxer # Rx Error
self._txd = txd
self._txv = txv
self._txrdy = txrdy
- self._packets = []
+ self._ls = ls
+ self._xcvrsel = xcvrsel
+ self._termsel = termsel
+ self._session = []
self._clock = clock
self._initial_delay = initial_delay
self._verbose = verbose
self._do_timeout = do_timeout
self._complete_fn = complete_fn
- self._expect_loopback = expect_loopback
self._dut_exit_time = dut_exit_time
- def get_name(self):
+ @property
+ def initial_delay(self):
+ return self._initial_delay
+
+ @initial_delay.setter
+ def initial_delay(self, d):
+ self._initial_delay = d
+
+ @property
+ def name(self):
return self._name
- def get_clock(self):
+ @property
+ def clock(self):
return self._clock
+ @property
+ def session(self):
+ return self._session
+
+ @session.setter
+ def session(self, session):
+ self._session = session
+
+ def us_to_clocks(self, time_us):
+ time_clocks = int(time_us / self._clock.period_us)
+ return time_clocks
+
def start_test(self):
self.wait_until(self.xsi.get_time() + self._initial_delay)
self.wait(lambda x: self._clock.is_high())
@@ -46,330 +139,49 @@ def start_test(self):
def end_test(self):
if self._verbose:
- print "All packets sent"
+ print("All events sent")
if self._complete_fn:
self._complete_fn(self)
- # Give the DUT a reasonable time to process the packet
+ # Give the DUT a reasonable time to process the last packet
self.wait_until(self.xsi.get_time() + self.END_OF_TEST_TIME)
if self._do_timeout:
- # Allow time for a maximum sized packet to arrive
- timeout_time = (self._clock.get_bit_time() * 1522 * 8)
-
- if self._expect_loopback:
- # If looping back then take into account all the data
- total_packet_bytes = sum([len(packet.get_bytes()) for packet in self._packets])
- total_data_bits = total_packet_bytes * 8
-
- # Allow 2 cycles per bit
- timeout_time += 2 * total_data_bits
-
- # The clock ticks are 2ns long
- timeout_time *= 2
-
- # The packets are copied to and from the user application
- timeout_time *= 2
-
- self.wait_until(self.xsi.get_time() + timeout_time)
-
- if self._test_ctrl:
- # Indicate to the DUT that the test has finished
- self.xsi.drive_port_pins(self._test_ctrl, 1)
# Allow time for the DUT to exit
self.wait_until(self.xsi.get_time() + self._dut_exit_time)
- print "ERROR: Test timed out"
+ print("ERROR: Test timed out")
self.xsi.terminate()
def set_clock(self, clock):
self._clock = clock
- def set_packets(self, packets):
- self._packets = packets
-
def drive_error(self, value):
self.xsi.drive_port_pins(self._rxer, value)
+ def wait_for_clocks(self, clockCount):
-class UsbPhy(TxPhy):
-
- def __init__(self, rxd, rxa, rxdv, rxer, vld, txd, txv, txrdy, clock,
- initial_delay=85000, verbose=False, test_ctrl=None,
- do_timeout=True, complete_fn=None, expect_loopback=True,
- dut_exit_time=25000):
- super(UsbPhy, self).__init__('mii', rxd, rxa, rxdv, rxer, vld, txd, txv, txrdy, clock,
- initial_delay, verbose, test_ctrl,
- do_timeout, complete_fn, expect_loopback,
- dut_exit_time)
+ delay = clockCount
+ while delay >= 0:
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+ delay = delay - 1
def run(self):
- xsi = self.xsi
-
- self.start_test()
-
- for i,packet in enumerate(self._packets):
- #error_nibbles = packet.get_error_nibbles()
-
- if isinstance(packet, RxPacket):
-
- timeout = packet.get_timeout()
-
- #print "Expecting pkt. Timeout in: {i}".format(i=timeout)
-
- in_rx_packet = False
- rx_packet = []
-
- while timeout != 0:
-
- self.wait(lambda x: self._clock.is_high())
- self.wait(lambda x: self._clock.is_low())
-
- timeout = timeout - 1
- #print "{i}".format(i=timeout)
-
- #sample TXV for new packet
- if xsi.sample_port_pins(self._txv) == 1:
- print "Receiving packet {}".format(i)
- in_rx_packet = True
- break
-
- if in_rx_packet == False:
- print "ERROR: Timed out waiting for packet"
-
- else:
- #print "in packet"
- while in_rx_packet == True:
-
- # TODO txrdy pulsing
- xsi.drive_port_pins(self._txrdy, 1)
- data = xsi.sample_port_pins(self._txd)
-
- print "Received byte: {0:#x}".format(data)
- rx_packet.append(data)
-
- self.wait(lambda x: self._clock.is_high())
- self.wait(lambda x: self._clock.is_low())
-
- if xsi.sample_port_pins(self._txv) == 0:
- #print "TXV low, breaking out of loop"
- in_rx_packet = False
-
-
-
- # End of packet
- xsi.drive_port_pins(self._txrdy, 0)
-
- # Check packet agaist expected
- expected = packet.get_bytes()
- if len(expected) != len(rx_packet):
- print "ERROR: Rx packet length bad. Expecting: {} actual: {}".format(len(expected), len(rx_packet))
-
- # Check packet data against expected
- if cmp(expected, rx_packet):
- print "ERROR: Rx Packet Error. Expected:"
- for item in expected:
- print "{0:#x}".format(item)
-
- print "Received:"
- for item in rx_packet:
- print "{0:#x}".format(item)
- else:
-
-
- # xCore should not be trying to send if we are trying to send..
- if xsi.sample_port_pins(self._txv) == 1:
- print "ERROR: Unexpected packet from xCORE"
-
- rxv_count = packet.get_data_valid_count();
-
- #print "Waiting for inter_pkt_gap: {i}".format(i=packet.inter_frame_gap)
- self.wait_until(xsi.get_time() + packet.inter_pkt_gap)
-
- print "Sending packet {}".format(i)
- if self._verbose:
- sys.stdout.write(packet.dump())
-
- # Set RXA high
- xsi.drive_port_pins(self._rxa, 1)
-
- # Wait for RXA rise delay TODO, this should be configurable
- self.wait(lambda x: self._clock.is_high())
- self.wait(lambda x: self._clock.is_low())
-
- #if isinstance(packet, TokenPacket):
- # print "Token packet, clear valid token"
- xsi.drive_port_pins(self._vld, 0)
-
- for (i, byte) in enumerate(packet.get_bytes()):
-
- # xCore should not be trying to send if we are trying to send..
- if xsi.sample_port_pins(self._txv) == 1:
- print "ERROR: Unexpected packet from xCORE"
-
- self.wait(lambda x: self._clock.is_low())
-
- self.wait(lambda x: self._clock.is_high())
- self.wait(lambda x: self._clock.is_low())
- xsi.drive_port_pins(self._rxdv, 1)
- xsi.drive_port_pins(self._rxd, byte)
-
- if (packet.rxe_assert_time != 0) and (packet.rxe_assert_time == i):
- xsi.drive_port_pins(self._rxer, 1)
-
- while rxv_count != 0:
- self.wait(lambda x: self._clock.is_high())
- self.wait(lambda x: self._clock.is_low())
- xsi.drive_port_pins(self._rxdv, 0)
- rxv_count = rxv_count - 1
-
- # xCore should not be trying to send if we are trying to send..
- if xsi.sample_port_pins(self._txv) == 1:
- print "ERROR: Unexpected packet from xCORE"
-
- #print "Sending byte {0:#x}".format(byte)
-
- rxv_count = packet.get_data_valid_count();
-
- if isinstance(packet, TokenPacket):
- #print "Token packet, driving valid"
- if packet.get_token_valid():
- xsi.drive_port_pins(self._vld, 1)
- else:
- xsi.drive_port_pins(self._vld, 0)
-
- # Wait for last byte
- self.wait(lambda x: self._clock.is_high())
- self.wait(lambda x: self._clock.is_low())
-
- xsi.drive_port_pins(self._rxdv, 0)
- xsi.drive_port_pins(self._rxer, 0)
-
- rxa_end_delay = packet.rxa_end_delay
- while rxa_end_delay != 0:
- # Wait for RXA fall delay TODO, this should be configurable
- self.wait(lambda x: self._clock.is_high())
- self.wait(lambda x: self._clock.is_low())
- rxa_end_delay = rxa_end_delay - 1
-
- # xCore should not be trying to send if we are trying to send..
- if xsi.sample_port_pins(self._txv) == 1:
- print "ERROR: Unexpected packet from xCORE"
-
- xsi.drive_port_pins(self._rxa, 0)
-
- #if self._verbose:
- #print "Sent"
-
- print "Test done"
- self.end_test()
-
-class RxPhy(xmostest.SimThread):
-
- def __init__(self, name, txd, txen, clock, print_packets, packet_fn, verbose, test_ctrl):
- self._name = name
- self._txd = txd
- self._txen = txen
- self._clock = clock
- self._print_packets = print_packets
- self._verbose = verbose
- self._test_ctrl = test_ctrl
- self._packet_fn = packet_fn
-
- self.expected_packets = None
- self.expect_packet_index = 0
- self.num_expected_packets = 0
-
- self.expected_packets = None
- self.expect_packet_index = 0
- self.num_expected_packets = 0
-
- def get_name(self):
- return self._name
-
- def get_clock(self):
- return self._clock
-
- def set_expected_packets(self, packets):
- self.expect_packet_index = 0;
- self.expected_packets = packets
- if self.expected_packets is None:
- self.num_expected_packets = 0
- else:
- self.num_expected_packets = len(self.expected_packets)
-
-class MiiReceiver(RxPhy):
-
- def __init__(self, txd, txen, clock, print_packets=False,
- packet_fn=None, verbose=False, test_ctrl=None):
- super(MiiReceiver, self).__init__('mii', txd, txen, clock, print_packets,
- packet_fn, verbose, test_ctrl)
-
- def run(self):
xsi = self.xsi
- self.wait(lambda x: xsi.sample_port_pins(self._txen) == 0)
-
- # Need a random number generator for the MiiPacket constructor but it shouldn't
- # have any affect as only blank packets are being created
- rand = random.Random()
-
- packet_count = 0
- last_frame_end_time = None
- while True:
- # Wait for TXEN to go high
- if self._test_ctrl is None:
- self.wait(lambda x: xsi.sample_port_pins(self._txen) == 1)
- else:
- self.wait(lambda x: xsi.sample_port_pins(self._txen) == 1 or \
- xsi.sample_port_pins(self._test_ctrl) == 1)
- if (xsi.sample_port_pins(self._txen) == 0 and
- xsi.sample_port_pins(self._test_ctrl) == 1):
- xsi.terminate()
+ # TODO ideally each session could have it's own start up delay rather than modifying the
+ # phy start up delay
+ if self._session.initial_delay is not None:
+ self._initial_delay = self._session.initial_delay
- # Start with a blank packet to ensure they are filled in by the receiver
- packet = MiiPacket(rand, blank=True)
-
- frame_start_time = self.xsi.get_time()
- in_preamble = True
-
- if last_frame_end_time:
- ifgap = frame_start_time - last_frame_end_time
- packet.inter_frame_gap = ifgap
-
- while True:
- # Wait for a falling clock edge or enable low
- self.wait(lambda x: self._clock.is_low() or \
- xsi.sample_port_pins(self._txen) == 0)
-
- if xsi.sample_port_pins(self._txen) == 0:
- last_frame_end_time = self.xsi.get_time()
- break
-
- nibble = xsi.sample_port_pins(self._txd)
- if in_preamble:
- if nibble == 0xd:
- packet.set_sfd_nibble(nibble)
- in_preamble = False
- else:
- packet.append_preamble_nibble(nibble)
- else:
- packet.append_data_nibble(nibble)
-
- self.wait(lambda x: self._clock.is_high())
-
- packet.complete()
-
- if self._print_packets:
- sys.stdout.write(packet.dump())
-
- if self._packet_fn:
- self._packet_fn(packet, self)
-
- # Perform packet checks
- packet.check(self._clock)
+ self.start_test()
+ for event in self._session.events:
+ event.drive(self, self._session.bus_speed)
+ print("Test done")
+ self.end_test()
diff --git a/tests/usb_phy_shim.py b/tests/usb_phy_shim.py
new file mode 100644
index 00000000..1dfc71e7
--- /dev/null
+++ b/tests/usb_phy_shim.py
@@ -0,0 +1,204 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+import random
+import sys
+import zlib
+from usb_packet import RxPacket, TokenPacket
+from usb_phy import UsbPhy
+
+
+class UsbPhyShim(UsbPhy):
+ def __init__(
+ self,
+ rxd,
+ rxa,
+ rxdv,
+ rxer,
+ vld,
+ txd,
+ txv,
+ txrdy,
+ clock,
+ initial_delay=85000,
+ verbose=False,
+ test_ctrl=None,
+ do_timeout=True,
+ complete_fn=None,
+ expect_loopback=True,
+ dut_exit_time=25000,
+ ):
+
+ # Shim adds a valid token line
+ self._vld = vld
+
+ super(UsbPhyShim, self).__init__(
+ "mii",
+ rxd,
+ rxa,
+ rxdv,
+ rxer,
+ txd,
+ txv,
+ txrdy,
+ clock,
+ initial_delay,
+ verbose,
+ test_ctrl,
+ do_timeout,
+ complete_fn,
+ expect_loopback,
+ dut_exit_time,
+ )
+
+ def run(self):
+ xsi = self.xsi
+
+ self.start_test()
+
+ for i, packet in enumerate(self._packets):
+
+ if isinstance(packet, RxPacket):
+
+ timeout = packet.get_timeout()
+
+ in_rx_packet = False
+ rx_packet = []
+
+ while timeout != 0:
+
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+
+ timeout = timeout - 1
+
+ # sample TXV for new packet
+ if xsi.sample_port_pins(self._txv) == 1:
+ print("Receiving packet {}".format(i))
+ in_rx_packet = True
+ break
+
+ if in_rx_packet == False:
+ print("ERROR: Timed out waiting for packet")
+
+ else:
+ while in_rx_packet == True:
+
+ # TODO txrdy pulsing
+ xsi.drive_port_pins(self._txrdy, 1)
+ data = xsi.sample_port_pins(self._txd)
+
+ print("Received byte: {0:#x}".format(data))
+ rx_packet.append(data)
+
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+
+ if xsi.sample_port_pins(self._txv) == 0:
+ # print "TXV low, breaking out of loop"
+ in_rx_packet = False
+
+ # End of packet
+ xsi.drive_port_pins(self._txrdy, 0)
+
+ # Check packet agaist expected
+ expected = packet.get_bytes(do_tokens=True)
+ if len(expected) != len(rx_packet):
+ print(
+ "ERROR: Rx packet length bad. Expecting: {} actual: {}".format(
+ len(expected), len(rx_packet)
+ )
+ )
+
+ # Check packet data against expected
+ if expected != rx_packet:
+ print("ERROR: Rx Packet Error. Expected:")
+ for item in expected:
+ print("{0:#x}".format(item))
+
+ print("Received:")
+ for item in rx_packet:
+ print("{0:#x}".format(item))
+ else:
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(self._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ rxv_count = packet.get_data_valid_count()
+
+ self.wait_until(xsi.get_time() + packet.inter_pkt_gap)
+
+ print(
+ "Phy transmitting packet {} PID: {} ({})".format(
+ i, packet.get_pid_pretty(), packet.pid
+ )
+ )
+ if self._verbose:
+ sys.stdout.write(packet.dump())
+
+ # Set RXA high
+ xsi.drive_port_pins(self._rxa, 1)
+
+ # Wait for RXA rise delay TODO, this should be configurable
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+
+ xsi.drive_port_pins(self._vld, 0)
+
+ for (i, byte) in enumerate(packet.get_bytes(do_tokens=True)):
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(self._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ self.wait(lambda x: self._clock.is_low())
+
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+ xsi.drive_port_pins(self._rxdv, 1)
+ xsi.drive_port_pins(self._rxd, byte)
+
+ if (packet.rxe_assert_time != 0) and (packet.rxe_assert_time == i):
+ xsi.drive_port_pins(self._rxer, 1)
+
+ while rxv_count != 0:
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+ xsi.drive_port_pins(self._rxdv, 0)
+ rxv_count = rxv_count - 1
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(self._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ rxv_count = packet.get_data_valid_count()
+
+ if isinstance(packet, TokenPacket):
+
+ if packet.get_token_valid():
+ xsi.drive_port_pins(self._vld, 1)
+ else:
+ xsi.drive_port_pins(self._vld, 0)
+
+ # Wait for last byte
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+
+ xsi.drive_port_pins(self._rxdv, 0)
+ xsi.drive_port_pins(self._rxer, 0)
+
+ rxa_end_delay = packet.rxa_end_delay
+ while rxa_end_delay != 0:
+ # Wait for RXA fall delay TODO, this should be configurable
+ self.wait(lambda x: self._clock.is_high())
+ self.wait(lambda x: self._clock.is_low())
+ rxa_end_delay = rxa_end_delay - 1
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(self._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ xsi.drive_port_pins(self._rxa, 0)
+
+ print("Test done")
+ self.end_test()
diff --git a/tests/usb_phy_utmi.py b/tests/usb_phy_utmi.py
new file mode 100644
index 00000000..0437e134
--- /dev/null
+++ b/tests/usb_phy_utmi.py
@@ -0,0 +1,49 @@
+# Copyright 2016-2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+from usb_packet import RxPacket, TokenPacket
+import usb_packet
+from usb_phy import UsbPhy
+
+
+class UsbPhyUtmi(UsbPhy):
+ def __init__(
+ self,
+ rxd,
+ rxa,
+ rxdv,
+ rxer,
+ txd,
+ txv,
+ txrdy,
+ ls,
+ xcvrsel,
+ termsel,
+ clock,
+ initial_delay=60000,
+ verbose=False,
+ do_timeout=True,
+ complete_fn=None,
+ dut_exit_time=30000,
+ ):
+
+ self._do_tokens = False
+
+ super(UsbPhyUtmi, self).__init__(
+ "UsbPhyUtmi",
+ rxd,
+ rxa,
+ rxdv,
+ rxer,
+ txd,
+ txv,
+ txrdy,
+ ls,
+ xcvrsel,
+ termsel,
+ clock,
+ initial_delay,
+ verbose,
+ do_timeout,
+ complete_fn,
+ dut_exit_time,
+ )
diff --git a/tests/usb_session.py b/tests/usb_session.py
new file mode 100644
index 00000000..dcc789dd
--- /dev/null
+++ b/tests/usb_session.py
@@ -0,0 +1,130 @@
+# Copyright 2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+from usb_packet import USB_DATA_VALID_COUNT
+import usb_transaction
+import usb_packet
+
+# TODO should EP numbers include the IN bit?
+
+
+def CounterByte(startVal=0, length=0):
+ l = startVal
+ while l < length:
+ yield l % 256
+ l += 1
+
+
+class UsbSession(object):
+ def __init__(
+ self,
+ bus_speed="HS",
+ run_enumeration=False,
+ device_address=0,
+ initial_delay=None,
+ **kwargs
+ ):
+ self._initial_delay = initial_delay
+ self._bus_speed = bus_speed
+ self._events = []
+ self._enumerate = run_enumeration
+ self._deviceAddress = device_address
+ self._pidTable_out = [usb_packet.USB_PID["DATA0"]] * 16
+ self._pidTable_in = [usb_packet.USB_PID["DATA0"]] * 16
+
+ self._dataGen_in = [0] * 16
+ self._dataGen_out = [0] * 16
+
+ assert run_enumeration == False, "Not yet supported"
+
+ @property
+ def initial_delay(self):
+ return self._initial_delay
+
+ @property
+ def bus_speed(self):
+ return self._bus_speed
+
+ @property
+ def events(self):
+ return self._events
+
+ @property
+ def deviceAddress(self):
+ return self._deviceAddress
+
+ @property
+ def enumerate(self):
+ return self._enumerate
+
+ @property
+ def data_valid_count(self):
+ return USB_DATA_VALID_COUNT[self._bus_speed]
+
+ def getPayload_out(self, n, length, resend=False):
+ payload = [
+ (x & 0xFF)
+ for x in range(self._dataGen_out[n], self._dataGen_out[n] + length)
+ ]
+ if not resend:
+ self._dataGen_out[n] += length
+ return payload
+
+ def getPayload_in(self, n, length, resend=False):
+ payload = [
+ (x & 0xFF) for x in range(self._dataGen_in[n], self._dataGen_in[n] + length)
+ ]
+ if not resend:
+ self._dataGen_in[n] += length
+ return payload
+
+ def _pid_toggle(self, pid_table, n):
+
+ if pid_table[n] == usb_packet.USB_PID["DATA0"]:
+ pid_table[n] = usb_packet.USB_PID["DATA1"]
+ else:
+ pid_table[n] = usb_packet.USB_PID["DATA0"]
+
+ def data_pid_in(self, n, togglePid=True, resetDataPid=False):
+
+ if resetDataPid:
+ self._pidTable_in[n] = usb_packet.USB_PID["DATA1"]
+ pid = self._pidTable_in[n]
+ return pid
+
+ pid = self._pidTable_in[n]
+ if togglePid:
+ self._pid_toggle(self._pidTable_in, n)
+ return pid
+
+ def data_pid_out(self, n, togglePid=True, resetDataPid=False):
+
+ if resetDataPid:
+ self._pidTable_out[n] = usb_packet.USB_PID["DATA1"]
+ pid = self._pidTable_out[n]
+ return pid
+
+ pid = self._pidTable_out[n]
+ if togglePid:
+ self._pid_toggle(self._pidTable_out, n)
+ return pid
+
+ def __str__(self):
+ s = ""
+ for e in self._events:
+ s += str(self._events.index(e)) + ": "
+ s += str(e) + "\n"
+ return s
+
+ def add_event(self, e):
+ e.bus_speed = (
+ self.bus_speed
+ ) # TODO ideally dont need transction to know bus speed
+
+ self._events.append(e)
+
+ def pop_event(self, e):
+ self.events.pop(0)
+
+ def _sort_events_by_time(self, events):
+ return sorted(events, key=lambda x: x.time, reverse=True)
diff --git a/tests/usb_signalling.py b/tests/usb_signalling.py
new file mode 100644
index 00000000..699bcfdf
--- /dev/null
+++ b/tests/usb_signalling.py
@@ -0,0 +1,348 @@
+# Copyright 2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+from usb_event import UsbEvent
+from usb_phy import USB_LINESTATE, USB_TIMINGS
+
+
+class UsbDeviceAttach(UsbEvent):
+ def __init__(self, interEventDelay=0):
+ super().__init__(interEventDelay=interEventDelay)
+
+ def __str__(self):
+ return "DeviceAttach"
+
+ def expected_output(self, bus_speed, offset=0):
+
+ expected = self.__str__() + "\nDUT entered FS\nReceived upstream chirp\n"
+
+ if bus_speed == "HS":
+ expected += "DUT entered HS mode\n"
+
+ return expected
+
+ @property
+ def event_count(self):
+ return 1
+
+ def drive(self, usb_phy, bus_speed):
+
+ wait = usb_phy.wait
+ wait_until_ns = usb_phy.wait_until
+ xsi = usb_phy.xsi
+ time = xsi.get_time
+
+ print("DeviceAttach")
+ tConnect_ns = time()
+
+ # Check XcvrSel & TermSel low
+ xcvrsel = xsi.sample_periph_pin(usb_phy._xcvrsel)
+ termsel = xsi.sample_periph_pin(usb_phy._termsel)
+
+ # TODO Drive VBUS and enabled these checks
+ # if xcvrsel == 1:
+ # print("ERROR: DUT enabled pull up before valid Vbus (XCVRSel)")
+
+ # if termsel == 1:
+ # print("ERROR: DUT enabled pull up before valid Vbus (TermSel)")
+
+ while True:
+
+ if (time() - tConnect_ns) > USB_TIMINGS["T_SIGATT_US"]:
+ print("ERROR: DUT didnt not assert XcvrSel & TermSel quickly enough")
+
+ # Check device asserts XcvrSel and TermSel before T_SIGATT
+ xcvrsel = xsi.sample_periph_pin(usb_phy._xcvrsel)
+ termsel = xsi.sample_periph_pin(usb_phy._termsel)
+
+ if xcvrsel == 1 and termsel == 1:
+ break
+
+ print("DUT entered FS")
+
+ # Bus state: Idle (FS 'J')
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_J"])
+
+ # Drive bus reset (SE0) after T_ATTDB - This is T0 of Figure 25
+ wait_until_ns(time() + USB_TIMINGS["T_ATTDB_US"] * 1000)
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["IDLE"])
+
+ # Check DUT enables HS Transceiver and asserts Chirp K on the bus (XcvrSel low, TxValid high)
+ # (This needs to be done before T_UCHEND - T_UCH)
+ while True:
+ xcvrsel = xsi.sample_periph_pin(usb_phy._xcvrsel)
+ txv = xsi.sample_port_pins(usb_phy._txv)
+
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ if (xcvrsel == 0) and (txv == 1):
+ t_ChirpStart_ns = time()
+ break
+
+ print("Received upstream chirp")
+
+ while True:
+
+ xsi.drive_port_pins(usb_phy._txrdy, 1)
+ data = xsi.sample_port_pins(usb_phy._txd)
+
+ if data != 0:
+ print("ERROR: Unexpected data from DUT during upstream chirp")
+
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ txv = xsi.sample_port_pins(usb_phy._txv)
+
+ if txv == 0:
+ # End of upstream chirp
+ t_ChirpEnd_ns = time()
+ break
+
+ xsi.drive_port_pins(usb_phy._txrdy, 0)
+
+ # Check that Chirp K lasts atleast T_UCH
+ if (t_ChirpEnd_ns - t_ChirpStart_ns) < USB_TIMINGS["T_UCH_US"] * 1000:
+ print("ERROR: Upstream chirp too short")
+
+ # Check that Chirp K ends before T_UCHEND
+ if (t_ChirpEnd_ns - tConnect_ns) > USB_TIMINGS["T_UCHEND"] * 1000:
+ print("ERROR: Upstream chirp finished too late")
+
+ if bus_speed == "HS":
+
+ wait_until_ns(time() + USB_TIMINGS["T_WTDCH_US"] * 1000)
+
+ for chirp_count in range(USB_TIMINGS["CHIRP_COUNT_MIN"]):
+
+ # Before end of Chirp K + T_WTDCH assert chirp K on the bus
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_K"])
+ wait_until_ns(time() + USB_TIMINGS["T_DCHBIT_MIN_US"] * 1000)
+
+ # After between T_DCHBIT_MIN and T_DCHBIT_MAX toogle chirp K to chirp J
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_J"])
+ wait_until_ns(time() + USB_TIMINGS["T_DCHBIT_MIN_US"] * 1000)
+
+ # After between T_DCHBIT_MIN and T_DCHBIT_MAX toogle chirp J to chirp K
+
+ # After atleast 3 chirp pairs ensure DUT de-asserts TermSel to enter HS mode
+ if xsi.sample_periph_pin(usb_phy._termsel) != 0:
+ print("ERROR: DUT didnt enter HS as expected")
+ else:
+ print("DUT entered HS mode")
+
+ for chirp_count in range(
+ USB_TIMINGS["CHIRP_COUNT_MAX"] - USB_TIMINGS["CHIRP_COUNT_MIN"]
+ ):
+
+ # Before end of Chirp K + T_WTDCH assert chirp K on the bus
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_K"])
+ wait_until_ns(time() + USB_TIMINGS["T_DCHBIT_MIN_US"] * 1000)
+
+ # After between T_DCHBIT_MIN and T_DCHBIT_MAX toogle chirp K to chirp J
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_J"])
+ wait_until_ns(time() + USB_TIMINGS["T_DCHBIT_MIN_US"] * 1000)
+
+ # Terminate downstream chirp K-J Sequence (between T_DCHSE0_MAX and T_DCHSE0_MIN
+
+ # Ensure DUT enters HS before T0 + T_DRST
+
+ # Drive HS Idle (SE0) on bus
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["IDLE"])
+
+ # TODO how long to drive SE0 for?
+ wait_until_ns(time() + 10000)
+
+ if bus_speed == "FS":
+ # Wait for device to timeout and move back into FS mode
+ while True:
+ xcvrsel = xsi.sample_periph_pin(usb_phy._xcvrsel)
+ termsel = xsi.sample_periph_pin(usb_phy._termsel)
+
+ if xcvrsel == 1 and termsel == 1:
+ wait_until_ns(time() + 10000)
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_J"])
+ wait_until_ns(time() + 10000)
+ break
+
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+
+class UsbResume(UsbEvent):
+ def __init__(self, duration=USB_TIMINGS["RESUME_FSK_MIN_US"], interEventDelay=0):
+ self._duration = duration
+ super().__init__(interEventDelay=interEventDelay)
+
+ def expected_output(self, bus_speed, offset=0):
+ expected_output = "RESUME\n"
+ expected_output += "RESUME END\n"
+
+ if bus_speed == "HS":
+ expected_output += (
+ "DUT ENTERED HS MODE\n" # TODO only if was in HS pre-suspend
+ )
+
+ return expected_output
+
+ def __str__(self):
+ return "UsbResume: " + str(self._duration)
+
+ @property
+ def event_count(self):
+ return 1
+
+ def drive(self, usb_phy, bus_speed):
+ xsi = usb_phy.xsi
+ wait = usb_phy.wait
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(usb_phy._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ resumeStartTime_ns = xsi.get_time()
+
+ # print("RESUME: " + str(resumeStartTime_ns))
+ print("RESUME")
+
+ # Drive resume signalling
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_K"])
+
+ while True:
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ currentTime_ns = xsi.get_time()
+ if currentTime_ns >= resumeStartTime_ns + (
+ USB_TIMINGS["RESUME_FSK_MIN_US"] * 1000
+ ):
+ break
+
+ endResumeStartTime_ns = xsi.get_time()
+ # print("TB SE0: " + str(endResumeStartTime_ns))
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["IDLE"])
+
+ while True:
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ currentTime_ns = xsi.get_time()
+ if currentTime_ns >= endResumeStartTime_ns + (
+ USB_TIMINGS["RESUME_SE0_US"] * 1000
+ ):
+ break
+
+ print("RESUME END")
+ # print("RESUME END: " + str(currentTime_ns))
+
+ if bus_speed == "HS":
+ # Check that the DUT has re-entered HS
+ xcvrsel = xsi.sample_periph_pin(usb_phy._xcvrsel)
+ termsel = xsi.sample_periph_pin(usb_phy._termsel)
+
+ if xcvrsel == 1:
+ print("ERROR: DUT did not enter HS after resume (XCVRSel)")
+
+ if termsel == 1:
+ print("ERROR: DUT did not enter HS after resume (TermSel)")
+
+ print("DUT ENTERED HS MODE")
+
+
+class UsbSuspend(UsbEvent):
+
+ # TODO create instance of Suspend with duracton in seconds and convert to clks?
+ def __init__(self, duration_ns, interEventDelay=0):
+ self._duration_ns = duration_ns
+ super().__init__(interEventDelay=interEventDelay)
+
+ def expected_output(self, bus_speed, offset=0):
+ expected_output = "SUSPEND START. WAITING FOR DUT TO ENTER FS\n"
+ expected_output += "DEVICE ENTERED FS MODE\n"
+ expected_output += "SUSPEND END\n"
+ return expected_output
+
+ def __str__(self):
+ return "UsbSuspend: " + str(self._duration_ns)
+
+ @property
+ def event_count(self):
+ return 1
+
+ def drive(self, usb_phy, bus_speed):
+
+ xsi = usb_phy.xsi
+ wait = usb_phy.wait
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(usb_phy._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ suspendStartTime_ns = xsi.get_time()
+ # print("SUSPEND START TIME: " + str(suspendStartTime_ns))
+
+ assert self.interEventDelay == 0
+
+ # Drive IDLE state onto LS pins
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["IDLE"])
+
+ # Within X uS device should transition to FS
+ print("SUSPEND START. WAITING FOR DUT TO ENTER FS")
+
+ while True:
+
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ # TODO check other pins
+ if xsi.sample_port_pins(usb_phy._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ xcvr = xsi.sample_periph_pin(usb_phy._xcvrsel)
+ termsel = xsi.sample_periph_pin(usb_phy._termsel)
+
+ # Wait for DUT to move into FS mode
+ if xcvr == 1 and termsel == 1:
+
+ fsTime_ns = xsi.get_time()
+ timeToFs_ns = fsTime_ns - suspendStartTime_ns
+ # print("DEVICE ENTERED FS AT TIME " + str(fsTime_ns/1000) + "(after " + str(timeToFs_ns/1000) +" uS)")
+ print("DEVICE ENTERED FS MODE")
+
+ if bus_speed == "HS":
+ if timeToFs_ns < (USB_TIMINGS["IDLE_TO_FS_MIN_US"] * 1000):
+ print("ERROR: DUT ENTERED FS MODE TOO SOON")
+
+ # Drive J state onto LS pins - replicate pullup
+ xsi.drive_periph_pin(usb_phy._ls, USB_LINESTATE["FS_J"])
+ break
+
+ time_ns = xsi.get_time() - suspendStartTime_ns
+ if time_ns > (USB_TIMINGS["IDLE_TO_FS_MAX_US"] * 1000):
+ print("ERROR: DUT DID NOT ENTER FS MODE IN TIME")
+
+ # Wait for end of suspend
+ while True:
+
+ wait(lambda x: usb_phy._clock.is_high())
+ wait(lambda x: usb_phy._clock.is_low())
+
+ # xCore should not be trying to send if we are trying to send..
+ if xsi.sample_port_pins(usb_phy._txv) == 1:
+ print("ERROR: Unexpected packet from xCORE")
+
+ xcvr = xsi.sample_periph_pin(usb_phy._xcvrsel)
+ termsel = xsi.sample_periph_pin(usb_phy._termsel)
+
+ # Check DUT doesn't prematurely move out of FS mode
+ if not (xcvr == 1 and termsel == 1):
+ print("ERROR: DUT moved out of FS mode unexpectly during suspend")
+
+ time_ns = xsi.get_time() - suspendStartTime_ns
+ if time_ns >= self._duration_ns:
+ print("SUSPEND END")
+ break
diff --git a/tests/usb_transaction.py b/tests/usb_transaction.py
new file mode 100644
index 00000000..7bfdbd5d
--- /dev/null
+++ b/tests/usb_transaction.py
@@ -0,0 +1,216 @@
+# Copyright 2021 XMOS LIMITED.
+# This Software is subject to the terms of the XMOS Public Licence: Version 1.
+
+from usb_event import UsbEvent
+from usb_packet import (
+ USB_PID,
+ TokenPacket,
+ TxDataPacket,
+ RxHandshakePacket,
+ RxDataPacket,
+ TxHandshakePacket,
+)
+from usb_packet import USB_DATA_VALID_COUNT
+
+INTER_TRANSACTION_DELAY = 500
+
+USB_DIRECTIONS = ["OUT", "IN"]
+USB_EP_TYPES = ["CONTROL", "BULK", "ISO", "INTERRUPT"]
+
+# TODO UsbTransaction_IN and UsbTransaction_OUT
+class UsbTransaction(UsbEvent):
+ def __init__(
+ self,
+ session,
+ deviceAddress=0,
+ endpointNumber=0,
+ endpointType="BULK",
+ direction="OUT",
+ bus_speed="HS",
+ eventTime=0,
+ dataLength=0,
+ interEventDelay=INTER_TRANSACTION_DELAY,
+ badDataCrc=False,
+ resend=False,
+ rxeAssertDelay_data=0,
+ halted=False,
+ resetDataPid=False,
+ ): # TODO Enums when we move to py3
+
+ self._deviceAddress = deviceAddress
+ self._endpointNumber = endpointNumber
+ self._endpointType = endpointType
+ self._direction = direction
+ self._datalength = dataLength
+ self._bus_speed = bus_speed
+ self._badDataCrc = badDataCrc
+ self._rxeAssertDelay_data = rxeAssertDelay_data
+ self._halted = halted
+
+ assert endpointType in USB_EP_TYPES
+ assert direction in USB_DIRECTIONS
+
+ # Populate packet list for a (valid) transaction
+ self._packets = []
+
+ # TODO would it be better to generate packets on the fly in drive() rather than create a packet list?
+ if direction == "OUT":
+
+ packets = []
+ packets.append(
+ TokenPacket(
+ interEventDelay=interEventDelay,
+ pid=USB_PID["OUT"],
+ address=self._deviceAddress,
+ endpoint=self._endpointNumber,
+ data_valid_count=self.data_valid_count,
+ )
+ )
+
+ # Don't toggle data pid if we had a bad data crc
+ if (
+ self._badDataCrc
+ or self._rxeAssertDelay_data
+ or endpointType == "ISO"
+ or halted
+ ):
+ togglePid = False
+ else:
+ togglePid = True
+
+ if (
+ (not self._badDataCrc)
+ and (not self._rxeAssertDelay_data)
+ and (deviceAddress == session.deviceAddress)
+ and (self._endpointType != "ISO")
+ ):
+ expectHandshake = True
+ else:
+ expectHandshake = False
+
+ if expectHandshake or self._endpointType == "ISO":
+ resend = False
+ else:
+ resend = True
+
+ # Generate packet data payload
+ packetPayload = session.getPayload_out(
+ endpointNumber, dataLength, resend=resend
+ )
+
+ pid = session.data_pid_out(
+ endpointNumber, togglePid=togglePid, resetDataPid=resetDataPid
+ )
+
+ # Add data packet to packets list
+ packets.append(
+ TxDataPacket(
+ pid=pid,
+ dataPayload=packetPayload,
+ bad_crc=self._badDataCrc,
+ rxe_assert_time=self._rxeAssertDelay_data,
+ )
+ )
+
+ if expectHandshake:
+ if halted:
+ packets.append(RxHandshakePacket(pid=USB_PID["STALL"]))
+ else:
+ packets.append(RxHandshakePacket())
+
+ self._packets.extend(packets)
+
+ else:
+
+ self._packets.append(
+ TokenPacket(
+ interEventDelay=interEventDelay,
+ pid=USB_PID["IN"],
+ address=self._deviceAddress,
+ endpoint=self._endpointNumber,
+ data_valid_count=self.data_valid_count,
+ )
+ )
+
+ if (
+ self._badDataCrc
+ or self._rxeAssertDelay_data
+ or self._endpointType == "ISO"
+ ):
+ togglePid = False
+ else:
+ togglePid = True
+
+ pid = session.data_pid_in(endpointNumber, togglePid=togglePid)
+
+ # Add data packet to packets list
+ if not halted:
+ # Generate packet data payload
+ packetPayload = session.getPayload_in(endpointNumber, dataLength)
+ self._packets.append(RxDataPacket(pid=pid, dataPayload=packetPayload))
+
+ if self._endpointType != "ISO" and not halted:
+ self._packets.append(TxHandshakePacket())
+
+ if halted:
+ self._packets.append(RxHandshakePacket(pid=USB_PID["STALL"]))
+
+ super(UsbTransaction, self).__init__(
+ time=eventTime, interEventDelay=interEventDelay
+ )
+
+ # TODO ideally USBTransaction doesnt know about data_valid_count
+ @property
+ def data_valid_count(self):
+ return USB_DATA_VALID_COUNT[self.bus_speed]
+
+ @property
+ def endpointAddress(self):
+ return self._endpointAddress
+
+ @property
+ def endpointType(self):
+ return self._endpointType
+
+ @property
+ def packets(self):
+ return self._packets
+
+ @property
+ def bus_speed(self):
+ return self._bus_speed
+
+ @bus_speed.setter
+ def bus_speed(self, bus_speed):
+ self._bus_speed = bus_speed
+
+ @property
+ def event_count(self):
+ eventCount = 0
+
+ # We should be able to do len(packets) but lets just be sure..
+ for p in self.packets:
+ eventCount += p.event_count
+
+ # Sanity check
+ assert eventCount == len(self.packets)
+
+ return eventCount
+
+ def expected_output(self, bus_speed, offset=0):
+ expected_output = ""
+
+ for i, p in enumerate(self.packets):
+ expected_output += p.expected_output(bus_speed)
+
+ return expected_output
+
+ def __str__(self):
+ s = "UsbTransaction:\n"
+ for p in self.packets:
+ s += "\t" + str(p) + "\n"
+ return s
+
+ def drive(self, usb_phy, bus_speed):
+ for i, p in enumerate(self.packets):
+ p.drive(usb_phy, bus_speed)