Using functions declared in xs1.h from C/C++ code

Technical questions regarding the XTC tools and programming with XMOS.
mculibrk
Active Member
Posts: 38
Joined: Tue Jul 13, 2010 2:57 pm

Using functions declared in xs1.h from C/C++ code

Post by mculibrk »

There are some nice functions declared in the XS1.H header but all of them are wrapped in the #ifdef __XC__ block so directly including xs1.h from a C/C++ file is useless.

What is the correct way to enable usage of functions declared there from a C/C++ file? To "rewrite" the header file is no problem but I suppose some library should be included in the link (or other funny things), right?
(as I found no obvious library specified in the makefiles/settings)

Any hints?

regards,
mculibrk


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

Post by lilltroll »

I wish the same, to aviod rewriting the functions as inline asm myself. It would be easier if it was maintained more central.

But until that happens, use inline asm.
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

I presume the contents of xsi are the equiv of gcc builtins for XC.

I too would like to see these accessibly from C/C++. I have also requested to see intrinsics documentation so that we can add architectural functionality from XS1 into C which already exists in the LLVM backend, there are ways we can expose this functionality.

Still waiting on a response

regards
Al
User avatar
japus
Member
Posts: 14
Joined: Tue Oct 26, 2010 12:18 pm

Post by japus »

I needed that too for my project (have a look at the multicore embedded robot) and used a workaround.

Create a XC-file (from which you can use all XC functions and include that in your regular C file. Like this you hide all XC operations inside other operations.

A small example to send a value over a channel.

Code: Select all

void sendOverChan(chanend c, int val){
c <: val;
}
You can use chanends in C by including the <xccompat.h> header file.

If you need more examples, in my code there is a XCwrapper file wich does only this kind of stuff.

Hope it helps...

Jasper