Why is OUT defined?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Why is OUT defined?

Rolf Freitag

Hi,

i tried to use these macros for simplified port definitions
because i want to change only one line when i change the port (PANIC_PORT):


// standard macros (K&R A.12, C-FAQs 11.17)
#   define mc_CAT(x, y) x ## y
#   define mc_XCAT(x, y) mc_CAT(x, y)

#   define PANIC_PORT P3
#   define  PANIC_PORT_DIR mc_XCAT(PANIC_PORT,DIR)
#   define  PANIC_PORT_SEL mc_XCAT(PANIC_PORT,SEL)
#   define  PANIC_PORT_OUT mc_XCAT(PANIC_PORT,OUT) // line 35


and it almost works, but not for the out port, because OUT is defined as 0x0004:

> msp430-gcc -mmcu=msp430x168 -O2 -Wall -g -c -o tmp.o tmp.c
tmp.c: In function `kernel_panic':
signal.c:35: `P30x0004' undeclared (first use in this function)

Why is OUT defined?
And can
#undef OUT
cause problems?

Regards,

Rolf



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: Why is OUT defined?

Georg Ritter
Hi,

I remember vaguely the issue about "macro in macro" evaluation by the processor.
You must make the PreProc somehow to evalute the nested #def's. I can't remeber
exacly now, but I think I found the solution by: looking on the preproc'ed gcc
output (-E ??) and the preproc section of the gcc manual on gcc.gnu.org.

If it does not help I can try to look it up.

        G.

[hidden email] wrote:

> Hi,
>
> i tried to use these macros for simplified port definitions
> because i want to change only one line when i change the port (PANIC_PORT):
>
>
> // standard macros (K&R A.12, C-FAQs 11.17)
> #   define mc_CAT(x, y) x ## y
> #   define mc_XCAT(x, y) mc_CAT(x, y)
>
> #   define PANIC_PORT P3
> #   define  PANIC_PORT_DIR mc_XCAT(PANIC_PORT,DIR)
> #   define  PANIC_PORT_SEL mc_XCAT(PANIC_PORT,SEL)
> #   define  PANIC_PORT_OUT mc_XCAT(PANIC_PORT,OUT) // line 35
>
>
> and it almost works, but not for the out port, because OUT is defined as 0x0004:
>
>
>>msp430-gcc -mmcu=msp430x168 -O2 -Wall -g -c -o tmp.o tmp.c
>
> tmp.c: In function `kernel_panic':
> signal.c:35: `P30x0004' undeclared (first use in this function)
>
> Why is OUT defined?
> And can
> #undef OUT
> cause problems?
>
> Regards,
>
> Rolf
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________
> Mspgcc-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>
>



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: Why is OUT defined?

Chris Liechti
In reply to this post by Rolf Freitag
[hidden email] wrote:

> i tried to use these macros for simplified port definitions
> because i want to change only one line when i change the port (PANIC_PORT):
>
>
> // standard macros (K&R A.12, C-FAQs 11.17)
> #   define mc_CAT(x, y) x ## y
> #   define mc_XCAT(x, y) mc_CAT(x, y)
>
> #   define PANIC_PORT P3
> #   define  PANIC_PORT_DIR mc_XCAT(PANIC_PORT,DIR)
> #   define  PANIC_PORT_SEL mc_XCAT(PANIC_PORT,SEL)
> #   define  PANIC_PORT_OUT mc_XCAT(PANIC_PORT,OUT) // line 35

instead of that, you could duplicate the "sfr" definitions of the ports
in msp430/gpio.h. and use "P3IN_" as refenece (the header files define
the constants with underlines to the address of the coresponding
peripheral register)

or you could use the "port" structs. see msp430/iostructures.h
that way you have only one name and can access the ports as structure
like "port3.out.pin1 = 0;"

> and it almost works, but not for the out port, because OUT is defined as 0x0004:
...
> Why is OUT defined?

the timer capture/compare controls (CCTL1...) have a bit with that name.

> And can
> #undef OUT
> cause problems?

not if you dont intend to use that constant. but it may have unexpected
effects if someone else later takes your code and want to use the timer
in compare mode ;-)

chris


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: Why is OUT defined?

Rolf Freitag
In reply to this post by Rolf Freitag

Hi,

> > i tried to use these macros for simplified port definitions
> > because i want to change only one line when i change the port (PANIC_PORT):
> >
> >
> > // standard macros (K&R A.12, C-FAQs 11.17)
> > #   define mc_CAT(x, y) x ## y
> > #   define mc_XCAT(x, y) mc_CAT(x, y)
> >
> > #   define PANIC_PORT P3
> > #   define  PANIC_PORT_DIR mc_XCAT(PANIC_PORT,DIR)
> > #   define  PANIC_PORT_SEL mc_XCAT(PANIC_PORT,SEL)
> > #   define  PANIC_PORT_OUT mc_XCAT(PANIC_PORT,OUT) // line 35
>
> instead of that, you could duplicate the "sfr" definitions of the ports
> in msp430/gpio.h. and use "P3IN_" as refenece (the header files define
> the constants with underlines to the address of the coresponding
> peripheral register)

ok, now i'm using:

#   define mc_PORT_u8(x)  (*(volatile u8*)(x))
#   define  PANIC_PORT_OUT mc_PORT_u8(mc_XCAT(PANIC_PORT,OUT_))

but i think i have to use different macros for other compilers.

Regards,

Rolf



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users