Hei,
The Programming XC book describes chanend (ports, timers, cores and clocks) as resource types:
Appendix A.3.2 Basic Types, "Channel ends, ports, timers and cores are collectively referred to as having resource types. Except for cores, which do not reserve storage, an object of resource type refers to a location in storage in which an identifier for the resource is recorded."
Appendix A.7.4 Structure and Union Declarations, "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"
Appendix A.7.7. Meaning of Declarators, "A port may be declared as an external declaration (see §A.9) or as a parameter only. A channel may be declared as a local variable only and a channel end may be declared as a parameter only. A structure containing a member or, recursively, any submember of resource type may be declared as an external declaration only."
Appendix A.9.2 External Declarations, "The term “external” refers to their location outside functions, and is not directly connected with the extern keyword; the storage class for an externally-declared object may be left empty, or it may be specified as extern or static."
So, the XC language specification allows you to write
Code: Select all
typedef struct{ port p; timer t; } event;
at file-global scope but not a function-level scope. Yet you can't write
Code: Select all
typedef struct{ chanend c; } message;
at any scope. What you kind of want is a "reference to a resource type", except you can't declare a structure with a reference to any type either, e.g. you can't write
Code: Select all
struct { chanend ℞ chanend &tx;} Mychannel;
or even
So, you will have to pass chanend's by reference as parameters in function calls, rather than through structures.
[Even in PiXC only protocols are proposed as types, and chans/chanends as types are only mooted in context as a proper type in 6.2.]