C++ and XMOS

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
feniksa
Member++
Posts: 22
Joined: Tue Apr 03, 2012 1:12 pm

C++ and XMOS

Postby feniksa » Sat Sep 20, 2014 1:12 pm

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

Postby richard » Mon Sep 22, 2014 11:39 am

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

Postby feniksa » Mon Sep 22, 2014 11:48 am

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

Who is online

Users browsing this forum: No registered users and 2 guests