How to connect ports via loopback using the XMOS simulator
version
1.1.1
scope
Example.
This code is provided as example code for a user to base their code on.
description
How to connect ports via loopback using the XMOS simulator
boards
Unless otherwise specified, this example runs on the SliceKIT Core Board, but can easily be run on any XMOS device by using a different XN file.
The xTIMEcomposer simulator contains a plugin mechanism that lets you model external components via plugins. As part of the xTIMEcomposer tools, a pre-built loopback plugin is provided which enables ports/pins to be connected, thus allowing testbenches to be written in XC.
For example, compile the following code for the XK-1A target:
#include <xs1.h> #include <print.h> #include <platform.h> port p1 = PORT_UART_RX; port p2 = PORT_UART_TX; int main() { par { { p1 <: 1; } { p2 when pinseq(1) :> void; printstrln("Done!\n"); } } return 0; }
The intention is to connect the pins of port p1 to the pins of port p2, thus allowing the example to complete successfully. Note: If you run the above code without making the connection, the execution will pause indefinitely, due to the fact that p2 will never go high.
There are a number of ways to specify the ports/pins to connect using the loopback plugin.
Using the port name as defined in the XN file
From within xTIMEcomposer Studio, select the Simulator tab of the Run configuration and the Loopback tab in the Plugins group. Add a new connection from PORT_UART_TX to PORT_UART_RX.
To run from the command line:
xsim --plugin LoopbackPort.dll "-port PORT_UART_RX 1 0 -port PORT_UART_TX 1 0" a.xe
Using the port names as defined by the XS1 architecture
From within xTIMEcomposer Studio, select the Simulator tab of the Run configuration and the Loopback tab in the Plugins group. Add a new connection from tile[0], XS1_PORT_1I (offset 0, width 1) to tile[0], XS1_PORT_1J (offset 0, width 1).
To run from the command line:
xsim --plugin LoopbackPort.dll "-port tile[0] XS1_PORT_1I 1 0 -port tile[0] XS1_PORT_1J 1 0" a.xe
Specifying the pins directly
To run from the command line:
xsim --plugin LoopbackPort.dll "-pin 0 X0D24 -pin 0 X0D25" a.xe