avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] Determine defined port


From: Harald Kipp
Subject: [avr-libc-dev] Determine defined port
Date: Sun, 22 Aug 2004 17:46:37 +0200

Hi all,

I stumbled over the following pre-processor problem.

Somewhere in an include file there's a macro

  #define MY_PORT  PORTC

User's should be able to adapt the program to their hardware
be simply changing this include file.

To make the code independent from the specified port,
I need something like

  #if (MY_PORT == PORTC)
  /* Do something PORTC specific, like disabling XMEM */
  #endif
  sbi(MY_PORT, 7);

Obviously this won't work, because PORTC is an already dereferenced
volatile pointer. No chance to retrieve the pointer address, right?

I could enumerate the ports by

  #define GPIO_A  1
...
  #define GPIO_C  3

... and replace the macro MY_PORT in the configuration header by

  /* Please use GPIO_A for PORTA, GPIO_B for PORTB etc. */
  #define MY_GPIO GPIO_C

and further define

  #if (MY_GPIO == GPIO_C)
  #define MY_PORT  PORTC
  #endif

for any port available, so finally

  /* GPIO_C refers to PORTC */
  #if (MY_GPIO == GPIO_C)
  /* Do something PORTC specific, like disabling XMEM */
  #endif
  sbi(MY_PORT, 7);

will give the expected result. Any ideas for a simpler and less
confusing method?

Thanks for your time,

Harald

P.S.: I just recognized I sent an empty message to this list some time
ago. I'm sorry for that.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]