What is the define __XC__ ?
-
- XCore Addict
- Posts: 204
- Joined: Sun Jun 01, 2014 10:25 pm
What is the define __XC__ ?
The ethernet code is full of conditional assembly statements ifdef __XC__ but nowhere can I find where this is defined or what is means. What is this define used for and where is it defined?
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
It is defined by the compiler if you are compiling XC code
(as opposed to, say, plain C code).
(as opposed to, say, plain C code).
-
- XCore Addict
- Posts: 204
- Joined: Sun Jun 01, 2014 10:25 pm
Ok, so if you can bear with me for this as I am mainly a hardware guy and not a c guy then in a header file is this code:
/**
* otp_ports_t structure - contains ports used to access the OTP memory.
*/
typedef struct otp_ports_t {
port data;
#ifdef __XC__
out port addr;
out port ctrl;
#else
port addr;
port ctrl;
#endif
} otp_ports_t;
so I understand from your explanation that if the header file is included in an xc source file it will compile differently than in c source file
my question is...why bother....why not just do this
/**
* otp_ports_t structure - contains ports used to access the OTP memory.
*/
typedef struct otp_ports_t {
port data;
port addr;
port ctrl;
} otp_ports_t;
/**
* otp_ports_t structure - contains ports used to access the OTP memory.
*/
typedef struct otp_ports_t {
port data;
#ifdef __XC__
out port addr;
out port ctrl;
#else
port addr;
port ctrl;
#endif
} otp_ports_t;
so I understand from your explanation that if the header file is included in an xc source file it will compile differently than in c source file
my question is...why bother....why not just do this
/**
* otp_ports_t structure - contains ports used to access the OTP memory.
*/
typedef struct otp_ports_t {
port data;
port addr;
port ctrl;
} otp_ports_t;
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
Because
and
are not the same thing?
Code: Select all
port addr;
Code: Select all
out port addr;
-
- XCore Legend
- Posts: 1274
- Joined: Thu Dec 10, 2009 10:20 pm
'port' In C is just an unsigned integer, the C compiler doesn't make any assumption beyond this. XC however can reason about the special port type and check that the port isn't being used in incorrect ways. Ports in XC are special resources that the compiler has some understanding of along with their modifiers such as in/out and buffering which allow the compiler to add specific config code etc..
regards
Al
regards
Al
-
- XCore Addict
- Posts: 204
- Joined: Sun Jun 01, 2014 10:25 pm
Ok, I get the distinction but from the overall program structure point of view, the program is written to run on XS1 parts that have physical ports so what is the point of some C code defining "ports" that are just integers?
Why not just assume that the header file will be used in an XC source file?
What is the point of all this?
Also the "data" port is defined as simply a port in XC presumably because it is bidirectional so if I didn't care about the compiler checking on my usage of ports, again why not just forget the use of in/out modifiers and just define everything as port and not worry about C or XC compiler differences.
Just trying to understand why some programmer has done this bit of code.....
Why not just assume that the header file will be used in an XC source file?
What is the point of all this?
Also the "data" port is defined as simply a port in XC presumably because it is bidirectional so if I didn't care about the compiler checking on my usage of ports, again why not just forget the use of in/out modifiers and just define everything as port and not worry about C or XC compiler differences.
Just trying to understand why some programmer has done this bit of code.....
-
- XCore Expert
- Posts: 844
- Joined: Sun Jul 11, 2010 1:31 am
A resource identifier in C is just an integer, exactly like on
the hardware. C is much closer to the generated machine
code than XC is.
The author of the header file made it work with both C and XC
presumably because it actually _is_ used with both.
the hardware. C is much closer to the generated machine
code than XC is.
The author of the header file made it work with both C and XC
presumably because it actually _is_ used with both.
-
- XCore Legend
- Posts: 1274
- Joined: Thu Dec 10, 2009 10:20 pm
Originally XC lacked some of C's features, pointers for example. Only recently has XC become more complete in this respect. Thus C has often been used in conjunction with XC to perform certain optimised code usage, C libraries can also be used if C is supported allowing the use of legacy libraries.
As for why bother creating a port type in C I guess it makes it more readable and standardises usage/manipulation in the native C support API.
P.S. it's worth poking around the headers in:
And in particular xccompat.h in this case
This helped me in the past
regards
Al
As for why bother creating a port type in C I guess it makes it more readable and standardises usage/manipulation in the native C support API.
P.S. it's worth poking around the headers in:
Code: Select all
XMOS/xTIMEcomposer/Community_13.1.0/target/include/
This helped me in the past
regards
Al