I am currently working on XMOS products, discovering XC programming language and having fun with channels and ports. So far so good, I can program my board and communicate over UART using ports.
In my project, I wanted to create a C structure (struct) containing some configuration variables (int, char, ...) and a channel, to pass to my threads on start-up. Here is a sample code to make my point clear:
Code: Select all
out port tx = PORT_UART_TX;
void uartTX(chanend c1, chanend c2, out port tx);
void producer(chanend data, chanend ctrl);
struct ctl {
chan ch;
// chanend ch; ??
char name;
int start;
};
int main() {
struct ctl a1, a2;
a1.name = 'A';
a1.start = 0x40FE12;
a2.name = 'B';
a2.start = 0xFF2842;
par {
on stdcore[0] : producer(a1.ch);
on stdcore[0] : producer(a2.ch);
on stdcore[0] : uartTX(a1.ch, a2.ch, tx);
}
return 0;
}
Unfortunately, XMOS compiler runs into an error on the struct declaration:
Code: Select all
../main.xc:25: error: field `ch' has resource type
So I wonder why it is not possible to have a channel in a C-structure? Is it a tool limitation or a real misconception from my part? I know chan must be associated with at most 2 threads, with chanend, and must be declared in the main body. But my struct is declared in the main body, and the a1.ch is connected to 2 threads.A structure or union may not contain a member of incomplete or resource type, except that
a structure may contain a member of type port or timer. If a structure is declared to have
a member with one of these types then variables of the structure may be declared only as
external declarations
Sorry if my question is stupid, but I'd better ask than stay stupid myself :-)
Cheers,
Julien