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

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
skoe
Experienced Member
Posts: 94
Joined: Tue Apr 27, 2010 10:55 pm

Post by skoe »

Nice that you solved the problem already, nevertheless let me show another possibility:

Code: Select all

#ifdef __XC__
void mos6502_mem_set_via_chanends(streaming chanend mos6502_via1_ce,
                                  streaming chanend mos6502_via2_ce);
#else
void mos6502_mem_set_via_chanends(unsigned mos6502_via1_ce,
                                  unsigned mos6502_via2_ce);
#endif
This makes the compiler see what we want it to see for C and for XC. And the linker doesn't care anyway.

(used in http://bitbucket.org/skoe/easy41/src/ti ... 2.h#cl-105)


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

Post by Folknology »

Wow that's cool Landon and I wasn't familiar with Ragel before, will you be sharing the code or is it private?

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

Post by landon »

I updated the wiki page for "Using channels and ports in C/C++" and added the section called:

Passing Streaming Channels to C Functions

Thanks,

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

Post by landon »

Hi Al,

The specific UI can't be published - work I'm doing for a company. However, when I get a chance, I'll write up a general article on how to use it with XMOS at some point.

Some time ago, I started a Ragel Recipies section on my blog where I created a skeleton command line interpreter in Ragel. Also, presented is a GPS NMEA parser with Ragel, ran it on a host, then went through the process of porting it to an AVR ATMega128. I ended up using it for my first entry into the AV competition at Sparkfun last April.

So, the process of creating a Ragel parser and hooking it up to XMOS very much the same as what I did in the article for hooking up the GPS parser to the AVR UART. It's just a matter of feeding the characters coming into the rx channel into the top level parsing function, then setting up actions to write data back out the channel based on what it has to do when it's crunched its way through an input stream.

So, the XMOS <-> Ragel interface is practically trivial...takes more to explain it than to do it. Ragel thinking takes some getting used to, but once it clicks, it sticks.

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

Post by landon »

Hi skoe,

I think it'd be great if you could update the Wiki with your variation as well - I have no doubt it would be useful to someone coming across the issue for the first time. I just poked in the summary on the wiki of what I did to get my bits working, but I'm sure you could add more useful knowledge to it as well.

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

Post by Folknology »

Thanks Landon, I will take a look at your blog re Ragel

regards
Al