Channels and UART

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Channels and UART

Post by TSC »

I've set up a separate UART on my XMOS board, which is working fine.

I can print strings by calling

Code: Select all

my_printstr(txChan, "This is a string")
Because I have to pass an argument of a chanend, I can only use the my_printstr function in the one thread to which I have passed the chanend using the par statement. Also, I'm aware that memory sharing is not supported in XC.

Is there a way I can access my UART from any thread, like the regular printstr() function?

Thanks


User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

You can make your UART reading from multiple producer channels i.e.:

Code: Select all

int main() {
  chan c0, c1, c2;
  
  par {
    uart(c0, c1, c2);
    producer(c0);
    producer(c1);
    producer(c2);
  }
  
  return 0;
}
User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Post by TSC »

Thanks Bianco. I just wish I could use my own printstr from any thread with the ease of the built-in version.

I suppose I'll have to do something like you suggest, with select and case statements around the chanends in the UART.
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

There is a ptrintstr :> uart module to download at https://www.xmos.com/applications/utili ... og?ver=all
I have tested it in putty on the host. (If I understand the question)

DESCRIPTION:

This package contains a logging server that redirects print statements
over uart or over an XC channel.
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Post by TSC »

EXACTLY what I wanted!

I just replaced my old UART code with the XLOG library, added a TX pin and updated the function names and everything works.

To think of all the time I spent getting the old UART working at all, and then thinking of ways to print without passing a chanend argument... when I could have just used XLOG.

It looks like XLOG does some very clever stuff grabbing and releasing channel ends as required. I had an idea something like that was needed, but didn't really know how to do it.

Huge thanks lilltroll, and good job whoever wrote the library.