Thanks a lot, Robert!
I was looking at an example in some old code of mine (IAR compiler) that had that intermediate step, but I didn't see the forest for the trees. I thought it was for readability, so no bell rang! I must have battled the same ten years ago!
I need the intermediate step when I call the macro with other macros as parameters. In my humble opinion, why does the C preprocessor behave like that? The syntax is fine for both cases, the readability is, but the inner working needs to be held by the hand (or I, the user..). Hmm?
Here is the new code now (have changed naming convention again..). It compiles!
-> Another question, how should I relate to the aliasing errors in the .o file? The code downloads to target. I really haven't looked into the .o file before, so I wouldn't know how aliasing errors would be in those. My makefile is at the bottom.
Code: Select all
/*
#include <xs1.h>
#include <stdint.h> // uint8_t
// -------------------------------
// -- LIBRARY CODE --
// -------------------------------
// BOOLEAN #include <stdbool.h> if C99
typedef enum {false,true} bool; // 0,1
typedef enum {LOW,HIGH} val_t; // 0,1
#define CAT3(a,b,c) a##b##c
#define CAT4(a,b,c,d) a##b##c##d
#define XS1_PINMODE_OUTPUT(ID,WIDTH,LETTER) out CAT4(port p,WIDTH,_out_,ID) = CAT3(XS1_PORT_,WIDTH,LETTER) // Usage global only
// out port p1_out_13 = XS1_PORT_1A
// 1 13 1A
// | || |LETTER
// WIDTH ID WIDTH
//
// Examples:
// XS1_PINMODE_OUTPUT(13,1,A); // p1_out_13 created on XS1_PORT_1A
// XS1_PINMODE_OUTPUT(13,4,A); // p4_out_13 created on XS1_PORT_4A
//
#define XS1_PINMODE_INPUT(ID,WIDTH,LETTER) in CAT4(port p,WIDTH,_in_,ID) = CAT3(XS1_PORT_,WIDTH,LETTER) // Usage global only
// Examples:
// XS1_PINMODE_INPUT(7,1,B); // "p1_in_7" created on XS1_PORT_1B
// XS1_PINMODE_INPUT(7,4,B); // "p4_in_7" created on XS1_PORT_4B
//
// pinMode(12,INPUT_PULLUP) // Arduino, not implemented here
#define XS2_PINMODE_OUTPUT(ID,WIDTH,LETTER) out CAT4(port p,WIDTH,_out_,ID) = CAT3(XS2_PORT_,WIDTH,LETTER) // Usage global only
#define XS2_PINMODE_INPUT(ID,WIDTH,LETTER) in CAT4(port p,WIDTH,_in_, ID) = CAT3(XS2_PORT_,WIDTH,LETTER) // Usage global only
void digitalWrite (out port pin, const val_t val) {
pin <: val;
}
val_t digitalRead (in port pin) {
val_t val;
pin :> val;
return val;
}
// -------------------------------
// -- USER CODE --
// -------------------------------
#define LED_ID 13 // Drivers LED when LOW (not significant in this code)
#define BUT_ID 7 // Button input
#define LED_PORT_WIDTH 1
#define LED_PORT_LETTER A
#define BUT_PORT_LETTER B
// pinMode(13,OUTPUT) // Arduino
XS1_PINMODE_OUTPUT (LED_ID, LED_PORT_WIDTH, LED_PORT_LETTER); // p1_out_13 created on XS1_PORT_1A
// pinMode(7,INPUT) // Arduino
XS1_PINMODE_INPUT (BUT_ID, LED_PORT_WIDTH, BUT_PORT_LETTER); // "p1_in_7" created on XS1_PORT_1B
int main() {
#define ledPin p1_out_13 // note: expanded from here
#define inPin p1_in_7 // note: expanded from here
val_t val; // Exactly..
val = digitalRead(inPin); // ..like Arduino
digitalWrite(ledPin,val); // ..example
// In __arduino_on_xmos_test.xc.o there are _several_ of these; but not in console
// note: object used here
// error: call to `digitalRead' in `main' makes alias of global 'p1_in_7'
// error: call to `digitalWrite' in `main' makes alias of global 'p1_out_13'
return 0;
}
Here the makefile, relating to te aliasing error in the .o file. It's unchanged:
Code: Select all
# The TARGET variable determines what target system the application is
# compiled for. It either refers to an XN file in the source directories
# or a valid argument for the --target option when compiling
TARGET = STARTKIT
# The APP_NAME variable determines the name of the final .xe file. It should
# not include the .xe postfix. If left blank the name will default to
# the project name
APP_NAME = __arduino_on_xmos_test
# The USED_MODULES variable lists other module used by the application.
USED_MODULES =
# The flags passed to xcc when building the application
# You can also set the following to override flags for a particular language:
# XCC_XC_FLAGS, XCC_C_FLAGS, XCC_ASM_FLAGS, XCC_CPP_FLAGS
# If the variable XCC_MAP_FLAGS is set it overrides the flags passed to
# xcc for the final link (mapping) stage.
XCC_FLAGS = -O2 -g
# The XCORE_ARM_PROJECT variable, if set to 1, configures this
# project to create both xCORE and ARM binaries.
XCORE_ARM_PROJECT = 0
# The VERBOSE variable, if set to 1, enables verbose output from the make system.
VERBOSE = 0
XMOS_MAKE_PATH ?= ../..
-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common