Question: How to pass a streaming channel to C function?

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Question: How to pass a streaming channel to C function?

Post by landon »

I'm trying to pass a streaming channel to a C function so it can stuff the channel with some formatted string data, floats, etc.

I see there is a typedef for chanend which is just an unsigned, but I don't see anything related to the streaming modifier.

In XC, it makes a distinction in the argument list for streaming channels. But there is no "streaming" modifier in the xccompat.h.

How does one pass a streaming channel to a C function? Is there anything special about the streaming channel type vs pure channel (besides their non-sychronous behavior)?

Can channels and streaming channels be interchanged as far as a C function is concerned?

Landon


User avatar
skoe
Experienced Member
Posts: 94
Joined: Tue Apr 27, 2010 10:55 pm

Post by skoe »

Just use unsigned like for normal channel ends. The streaming modifier only tells the XC compiler how <: and :> have to be implemented.

However, take care that ordinary channels and streaming channels have to be handled differently in your C code. There's no token handshake for streaming channels.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

Hi Skoe,

Thanks for the response. I've tried several things to no avail - seems like it would be a trivial thing to solve but I haven't found a way to coerce it.

In the C function, I changed the prototype and fingerprint of the parameter chanend to unsigned, but still error'd out on type conversion.

Leaving the C function parameter as unsigned, I tried casting the streaming chanend variable to (unsigned) in the call from XC to C. Still got type conversion errors.

I still can't find the right combination.

Here's what I have tried

XC fragment:

Code: Select all

#include "mycstuff.h"

void executive(streaming chanend txChan )
{
   // ... do some stuff, then call a C function with the channel
   send_command_prompt( (unsigned)txChan );
}
C Fragments:
mycstuff.h

Code: Select all

extern void send_command_prompt( unsigned txChan );
mycstuff.c

Code: Select all

#include "mycstuff.h"

void send_command_prompt( unsigned txChan )
{

}
Fails:

Code: Select all

error: conversion to transmissive type requested
(I've tried "chanend txChan" for the prototype as well passing the streaming chanend which is what originally failed).

If I try type casting the streaming chanend to (unsigned) in XC (adjusting the prototypes in the C to match unsigned), I get:

Code: Select all

 `send_command_prompt' changes streaming qualifier of type
If I leave the C function prototypes as chanend and typecast the streaming channel to (unsigned), I still get the:

Code: Select all

error: conversion from transmissive type requested
I just can't find a combination that will allow me to pass a streaming channel variable as a parameter to a C function.

What am I missing?

Landon
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Don't forget the :

Code: Select all

#include <xccompat.h>
Also lookie using channels and ports in C/C++

regards
Al
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

Thanks, Al, I have looked at the wiki, but it only covers regular channels not streaming channels.

If I remove the streaming modifier, I have no problems with my compiles - the wiki page on channel passing to C works fine.

What I'm lacking is the technique to pass streaming channels to C. Once I try passing a streaming channel, since there is no streaming chanend in C xccompat.h and I can't figure out how to cast it to a regular chanend, I'm getting hung up.

Any hints? Have you tried passing a streaming channel to a C function - there must be some incantation I'm missing to do it.

Thanks for any help,

Landon
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Have a peek into the ethernet mii_wrappers for some clues, their in the ethernet software download , inside should be a use of streaming channels with both XC and C if I recall.

*PS
the Ethernet and TCP/IP examples are not the best XS1 examples in the world by the way, but it might give you some clues. Also they use a "streaming" def to document that the chanend is a streaming rather than a regular chanend which is quite a clever idea IMHO.

regards
Al
Last edited by Folknology on Wed Oct 06, 2010 3:14 pm, edited 8 times in total.
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

Hi Al,

Thanks for the pointer, I'll definitely take a look at it.

Landon
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

Ha! in mii_wrappers.c

here is the incantation :-)

Code: Select all

#include <xccompat.h>
#define streaming


Then in their function using a streaming channel:

Code: Select all

void mii_rx_pins_wr(port p1,
                    port p2,
                    int i,
                    streaming chanend c)
Wow, didn't realize I could get away with that...ridiculously easy. Clearly I was making it too hard,

Thanks for the pointer to this example - very helpful,

Landon
User avatar
landon
Experienced Member
Posts: 71
Joined: Mon Sep 06, 2010 4:05 pm

Post by landon »

I'm happy to report that I've now got a console user interface implemented on my XK-1 board that uses streaming channels.

I implemented the command line console interface using Ragel (http://www.complang.org/ragel/ ). I used the C implementation of Ragel parser output, integrated it with the rx/tx streaming channel and uart code on XMOS.

The Ragel code built without a hitch in the XDev tools (not too surprising since I've used Ragel in AVR tools before - it's very portable.) Works like a charm,

Landon
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

Maybe someone of you native english speaking could leave a note on that on wiki, chan & streaming chan usages (in C) :!: :?: Please
Probably not the most confused programmer anymore on the XCORE forum.