From: gieltjev on
Hi,

Im just new to the rabbit platform, and i am trying to make macro's to
set pins and clear them.

Ive created this three Macro's to set or get the value from a pin:
#define setPin(p,b,highval) BitWrPortI(p,& ## p ##
Shadow,highval,b)
#define clearPin(p,b,highval) BitWrPortI(p,& ## p ## Shadow,highval
^ 1,b)
#define getPin(p,b) BitRdPortI(p,b)

If i use the macro's manually the SetPin and ClearPin work perfectly,
but i want to put the pins in a define.
I've given pin Names (like DO_0, DI_1, DO_4), they are defined as
following:
#define DO_1 PEDR,4,1
#define DO_2 PEDR,5,1
#define DO_3 PEDR,6,1
#define DO_4 PEDR,7,1
#define DO_5 PEDR,3,1

when i execute the macro's with DO_1 as argument the compiler gives
the following error:: "Wrong number of arguments in macro call."

What do i need to adjust to get this working?

Thanks in advantage,

Michiel


From: gamma on
On Feb 11, 3:45 am, gieltjev <gielt...(a)hotmail.com> wrote:
> Hi,
>
> Im just new to the rabbit platform, and i am trying to make macro's to
> set pins and clear them.
>
> Ive created this three Macro's to set or get the value from a pin:
>   #define setPin(p,b,highval)   BitWrPortI(p,& ## p ##
> Shadow,highval,b)
>   #define clearPin(p,b,highval) BitWrPortI(p,& ## p ## Shadow,highval
> ^ 1,b)
>   #define getPin(p,b)   BitRdPortI(p,b)
>
> If i use the macro's manually the SetPin and ClearPin work perfectly,
> but i want to put the pins in a define.
> I've given pin Names (like DO_0, DI_1, DO_4), they are defined as
> following:
>         #define DO_1    PEDR,4,1
>         #define DO_2    PEDR,5,1
>         #define DO_3    PEDR,6,1
>         #define DO_4    PEDR,7,1
>         #define DO_5    PEDR,3,1
>
> when i execute the macro's with DO_1 as argument the compiler gives
> the following error:: "Wrong number of arguments in macro call."
>
> What do i need to adjust to get this working?
>
> Thanks in advantage,
>
> Michiel

Try this
#define setPinHelper(p,b,highval) BitWrPortI(p,& ## p ##
Shadow,highval,b)
#define setPin(v) setPinHelper(v)

setPin(DO_1)

Macro arguments don't get expanded until after the macro has been
invoked.