C++ and XMOS

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
feniksa
Member++
Posts: 22
Joined: Tue Apr 03, 2012 1:12 pm

C++ and XMOS

Post by feniksa »

C++ and XMOS

[hr]
Description:

Porting some libraries from Arduino to XMOS and it became a hell rewrite all libraries, that I need from Arduino to XC.

[hr]
Solution 1: Write wrapper for xc calls

#p11787]combining XC and C++
#p4518] C++ interworking

Idea of such solution goes in such way - create simple header files with some silly functions, like:

Code: Select all

#ifdef __cplusplus
extern "C" {
#endif
void write_byte_to_port(unsigned int port, unsigned char value);
unsigned char read_byte_from_port(unsigned int port);
#ifdef __cplusplus
}
#endif
in .xc file write just simple solution:

Code: Select all

void write_byte_to_port(port port_addr, unsigned char value) 
{
     port <: value;
}
unsigned char read_byte_from_port(unsigned int port_addr) 
{
    unsigned char byte;
    port :> byte;
    return byte;
}
But such solution have issues:
  1. impossible to call from cpp some xc dialect functions - par
  2. impossible to define timers from cpp code
  3. impossible to define ports from cpp code
  4. every cpp code should call wrapped function
[hr]
Solution 2: Write all code on C++

It is much better and easly way will be to write all code on C++. But to write it, I don't know how to:
  1. Define ports in C++ code
  2. Define timers in C++ code
  3. Chan / Channed types
  4. Read/Write from ports
  5. Call some specific XC functions, like configure_port, etc.
I though, about asm code, but I am not guru with asm and XC.

It will be cool, if someone will help to write XC "hello world" on C++


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

feniksa wrote:I though, about asm code, but I am not guru with asm and XC.

It will be cool, if someone will help to write XC "hello world" on C++
There used to be some code for accessing resources from C in the sc_util git repo, see module_xio, module_xthreads in the following snapshot: https://github.com/xcore/sc_util/tree/b ... 0dbd5046ce. The code was removed since it was buggy and it wasn't being maintained - even so it might be a useful starting point.
User avatar
feniksa
Member++
Posts: 22
Joined: Tue Apr 03, 2012 1:12 pm

Post by feniksa »

@richard : Thanks, I will try it... Good start point.
Post Reply