Are interfaces supported in C?

Technical questions regarding the XTC tools and programming with XMOS.
Jcvc
Active Member
Posts: 38
Joined: Wed May 07, 2025 11:13 pm

Are interfaces supported in C?

Post by Jcvc »

Hi,

I was using application AN00124 to take advatange of the CDC protocol and I was attempting to convert the app_virtual_com() API from xC to C, which I'm circling around and not finding a way to achieve that, as at the end of the day, I always get the error:
member reference base type 'unsigned int' is not a structure or union
char cdc_char = cdc.get_char();

Essentially the changes I've done are below:

Code: Select all

main.xc
...
extern void app_virtual_com(client interface usb_cdc_interface cdc);

/* Endpoint type tables - informs XUD what the transfer types for each Endpoint in use and also
 * if the endpoint wishes to be informed of USB bus resets
 */
XUD_EpType epTypeTableOut[XUD_EP_COUNT_OUT] = {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_BUL};
XUD_EpType epTypeTableIn[XUD_EP_COUNT_IN] =   {XUD_EPTYPE_CTL | XUD_STATUS_ENABLE, XUD_EPTYPE_INT, XUD_EPTYPE_BUL};

/* Application task */
/*void app_virtual_com(client interface usb_cdc_interface cdc) -> Removed
{
    while (1)
    {
        char cdc_char = cdc.get_char();
        cdc.put_char(cdc_char);
        if (cdc_char == '\r')
            cdc.put_char('\n');
    }
}*/
...
and created a new .c file:

Code: Select all


#include <xccompat.h>

void app_virtual_com(CLIENT_INTERFACE(usb_cdc_interface, cdc))
{
    while (1)
    {
        char cdc_char = cdc.get_char();
        cdc.put_char(cdc_char);
        if (cdc_char == '\r')
            cdc.put_char('\n');
    }
}
I mean, I understand that the compiler throws that error if the cdc is passed as an unsigned integer, but I thought the client_interface would make it compatible for a .c file? Could I get a pointer to what am I doing wrong? Possibly something stupid (apologies in advance!), but spent the whole afternoon on this and simply couldn't figure it out.

Thank you!
User avatar
fabriceo
Respected Member
Posts: 277
Joined: Mon Jan 08, 2018 4:14 pm

Post by fabriceo »

Hi, the concept of interface can only be used within .XC files.
still the interface object can be passed as a parameter. it looks like an integer and is basically the ressource address of a channel used to communicate across tiles.
You have to create trampoline functions to interface between .c and .xc and then the interface value can be passed as a parameter if you need it to call the target XC function.

that's something I played with 6 year ago and you can find some stuff in this GitHub folder : https://github.com/fabriceo/XMOS/tree/m ... serial/src

the goal was to use the XMOS CDC functions from cpp application...not far from your project, but you will not find a turnkey solution in the files as I gave up with CDC and now using VendorRequests
sorry, might be confusing :)
hope it helps
fabriceo
Jcvc
Active Member
Posts: 38
Joined: Wed May 07, 2025 11:13 pm

Post by Jcvc »

Ahhhhh ok, thought there would be a cleaner way xD But well, at least there is a way :) I'll implement the wrappers and see how it goes!
Thank you Fabriceo (once again!)