cdc interface function read

Technical questions regarding the XTC tools and programming with XMOS.
Posts: 16
Joined: Mon Jun 19, 2023 9:32 pm

cdc interface function read

Post by tom3 »


I want to use the function "int read(unsigned char data[], REFERENCE_PARAM(unsigned, count));" to read some data over usb. I took the function from "interface usb_cdc_interface " in the xud_cdc.h from an00184.

I want to use it like this : But unfortunately , i don´t know what parameters are expected in unsigned char data[]. Is it the array where the data that has been read must be stored, or is it something else? And what does reference_param mean.... ?

I will be grateful if someone could explain how this function works. In an00184 there are no explanations and i didn´t see any examples where this function is used like :

Thank you

User avatar
XCore Expert
Posts: 981
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

The REFERENCE_PARAM() macro just assists with the different pass by reference syntax of XC and pointers in C.

from xcccompat.h:

Code: Select all

 * Macro that expands to a reference to the specified type when used in
 * an XC source file and to a pointer to the specified type when used in
 * a C/C++ source file.
#ifdef __XC__
#define REFERENCE_PARAM(type, name) type &name
#define REFERENCE_PARAM(type, name) type *name

in xc you can just can use the function something like

Code: Select all

unsigned char buffer[10]
unsigned count;, count);
The number of bytes read will be stored in count.