2
\$\begingroup\$

I was looking at contiki how it defines port direction for telob/sky: https://github.com/contiki-os/contiki/blob/master/cpu/msp430/dev/hwconf.h and am buffled.

I mean, in plain msp430 jurgon you could do this

P1DIR = 0x01;

to set up, for example, port 1 or

P1SEL &= (~BIT0);    // Set P1.0 SEL for GPIO 

Now, the contiki master programmer has something like:

#define HWCONF_PIN(name, port, bit) \
static CC_INLINE void name##_SELECT() {P##port##SEL &= ~(1 << bit);} 

and so on..

to make programming the port easier but I can't figure out how this enternally gets executed.

For example, how is this " name##_SELECT()" called?

I know it's a newbie question but bear with me. Thanx

\$\endgroup\$
  • \$\begingroup\$ What's telob/sky? \$\endgroup\$ – m.Alin Jul 21 '14 at 13:30
  • \$\begingroup\$ google.gr/… \$\endgroup\$ – Nick_K Jul 21 '14 at 13:41
  • 1
    \$\begingroup\$ This isn't an electronics question, it's a C programming question. Specifically, the ## operator is how you concatentate the values of symbols in the C preprocessor. Once you understand that, you should be able to work out what the macro actually does. \$\endgroup\$ – Dave Tweed Jul 21 '14 at 13:53
  • \$\begingroup\$ @DaveTweed Thanx for the hint. I was stuck at figuring out how's concatenation is defined in C preprocessor. Now, I can find out how this macro works. \$\endgroup\$ – Nick_K Jul 22 '14 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.