Preprocessor not resolving parameter at usage of a port macro
Posted: Wed Jan 17, 2018 4:56 pm
The code below, with COMPILES_FINE commented away will not compile. I would have expected PIN_13_LED to be expanded to 1A, but it doesn't seem to be.
Also, when it compiles OK, there is an error message in the .o file about aliasing, see inside main()
I have added the project as compiled OK and with error, in case there is any compiler person wanting to look at this.
Some may see that I am trying to make it easy to port from Arduino. The source file in the attached zip is loaded with comments in that regard. Also, I will blog about this, starting at [1]
[1] http://www.teigfam.net/oyvind/home/tech ... to_xmos_xc Disclaimer: no money, no ads, no gifts - Just fun and expenses
Also, when it compiles OK, there is an error message in the .o file about aliasing, see inside main()
I have added the project as compiled OK and with error, in case there is any compiler person wanting to look at this.
Some may see that I am trying to make it easy to port from Arduino. The source file in the attached zip is loaded with comments in that regard. Also, I will blog about this, starting at [1]
[1] http://www.teigfam.net/oyvind/home/tech ... to_xmos_xc Disclaimer: no money, no ads, no gifts - Just fun and expenses
Code: Select all
#include <xs1.h>
#include <stdint.h> // uint8_t
typedef enum {LOW,HIGH} pinval_t; // 0,1
#define PINMODE_OUTPUT_pin_out_1X(num) out port pin_out_##num = XS1_PORT_##num // Usage global only
#define PINMODE_INPUT_pin_in_1X(num) in port pin_in_##num = XS1_PORT_##num // Usage global only
void digitalWrite (out port pin, const pinval_t pinval) {
pin <: pinval;
}
pinval_t digitalRead (in port pin) {
pinval_t pinval;
pin :> pinval;
return pinval;
}
#define PIN_13_LED 1A
#define PIN_07_BUTTON 1B
#define COMPILES_FINE
#ifdef COMPILES_FINE
PINMODE_OUTPUT_pin_out_1X(1A); // "pin_out_1A" created
PINMODE_INPUT_pin_in_1X (1B); // "pin_in_1B" created
#else
PINMODE_OUTPUT_pin_out_1X (PIN_13_LED); // error: use of undeclared identifer `XS1_PORT_PIN_13_LED'
PINMODE_INPUT_pin_in_1X (PIN_07_BUTTON); // error: use of undeclared identifer `XS1_PORT_PIN_07_BUTTON'
#endif
int main() {
pinval_t pinval;
// In __arduino_on_xmos_test.xc.o:
pinval = digitalRead (pin_in_1B); // note: object used here
// error: call to `digitalWrite' in `main' makes alias of global 'pin_out_1A'
digitalWrite (pin_out_1A, pinval); // error: call to `digitalRead' in `main' makes alias of global 'pin_in_1B'
// digitalWrite (pin_out_1A, digitalRead (pin_in_1B)); // One-liner2
return 0;
}