I am still experimenting with XMOS devices. Today, I have a question about ports.
My goal is simple: Set-up a loopback communication between 2 threads via pins connected together. The hidden goal is to learn how XMOS ports are working to connect to other devices in the future.
So my first guess was to connect 2 1-bit ports together (dataOut and dataIn) and 2 others for the clockOut and clockIn signals. I discovered that the clock was permanently running even without data (already explained in this forum) which makes my receiving thread a bit confused, so I added a strobe signal (in and out).
Here I am with my setup (running on XK-1 board as well as on Sparkfun XS1-L1-64 board):
- 6 x 1-bit ports connected by pair: dataIn - dataOut, clockIn - clockOut and readyIn - readyOut.
- 2 threads, one sending data on the buffered port once a second, the other reading that data and sending it up through UART.
Looking at the signals on my oscilloscope, I can see that data, clock and strobe signals are perfectly in accordance with documentation: Strobe signal goes high on clock's falling edge, data starts at the same time. Data is stable on clock's rising edges (when inPort is supposed to read). Finally strobe goes low on the last clock's falling edge.
So I wonder where I am wrong, and what should I do to make this very simple experiment works on my boards... Any help is welcome!
Here is the main part of the code (the complete code is attached) for easier understanding:
Code: Select all
int main(void)
{
unsigned int my_data = 0xA7712002;
in_config(inP, inClock, inReady, inClk);
out_config(outP, outClock, outReady, outClk, 100);
par {
output(my_data, outP);
input(inP);
}
return 0;
}
Code: Select all
void out_config(out buffered port:32 outP, out port outClock,
out port outR, clock clk, unsigned clkrate)
{
configure_clock_rate(clk, 100, clkrate);
configure_out_port_strobed_master(outP, outR, clk, 0);
configure_port_clock_output(outClock, clk);
start_clock(clk);
}
void in_config(in buffered port:32 inP, in port inClock,
in port inR, clock clk)
{
configure_clock_src(clk, inClock);
configure_in_port_strobed_slave(inP, inR, clk);
start_clock(clk);
}
Code: Select all
void output(unsigned int data, out buffered port:32 tx)
{
timer t;
unsigned time;
t :> time;
while (1) {
time += DELAY;
t when timerafter (time) :> void;
tx <: data;
}
}
void input(in buffered port:32 inP)
{
unsigned int data = 0;
while (1) {
inP :> data;
print_hex(data);
}
}
Julien