problem with streaming chanend

If you have a simple question and just want an answer.
francescof
New User
Posts: 2
Joined: Tue Feb 09, 2016 9:47 am

problem with streaming chanend

Post by francescof »

Hi,
I am new to xcore development.
I am testing some code using the streaming chanend.
I am facing an issue.

Basically I am sending the input of a serial communication to a function called ReadRawData.

A while loop is sending any data sampled on the port.
Now inside the ReadRawData(streaming chanend cIn) function what happens is this:

let's assume that I am sending 3 bytes.

If I write something like:

unsigned char d;
while(1){
cIn:> d;
printf("d: 0x%1x\n", d);
}

I have always the first byte printed out, but if I write something like:

unsigned char a, b, c;

cIn:> a;
cIn:> b;
cIn:> c;

printf("a: 0x%1x\n", a)
printf("b: 0x%1x\n", b)
printf("c: 0x%1x\n", c)

Then I have all the 3 correct values.
Now from my understanding the while loop should do the same of writing multiple cIn:>?
I hope this is clear and thanks in advance for any help.
henk
Verified
Respected Member
Posts: 347
Joined: Wed Jan 27, 2016 5:21 pm

Post by henk »

Hi Francescof,

I think the problem is in the printf.

Printf by default uses JTAG to communicate with the host; it stops the processor, but the world around it moves on. So you may find you are losing data that way?

If you store the three characters in an array in a for-loop and then print them out it should be fine too.

You can reroute printf to use xSCOPE to sneak some data out in real-time.

Cheers,
Henk
peter
XCore Addict
Posts: 230
Joined: Wed Mar 10, 2010 12:46 pm

Post by peter »

It is also worth noting that the "printf" library function is very slow. XMOS has implemented a faster print function which you can use. It is provided in the logging library:

https://github.com/xmos/lib_logging

There is an example of using it, it is just worth noting that you need to add the following to your XCC_FLAGS, otherwise the debug_printf calls are removed.

XCC_FLAGS = -DDEBUG_PRINT_ENABLE=1

How to enable I/O over xSCOPE is explained here:

https://www.xmos.com/published/how-redi ... ope-timing
User avatar
infiniteimprobability
Verified
XCore Legend
Posts: 1164
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

We're going to add a warning in the JTAG option in the "run configurations" dialogue in the next version of tools that JTAG printing breaks real time. You're not the first to stumble across this behaviour breaking their code, but hopefully one of the last!