Hi Johny,
First, the #define works because it is simple text substitution. So if
you look at the resultant app.c you will see
error_t foo(nx_uint16_t val)
when using the define.
So of course it works.
If you compile Blink say for the telosb and then take a look at app.c you
can see where the nx types are defined. Search for nx_uint16.
you'll see something like:
typedef struct { unsigned char nxdata[2]; } __attribute__((packed))
nx_uint16_t; typedef uint16_t __nesc_nxbase_nx_uint16_t ;
And from nesc_nx.h:
typedef uint16_t nx_uint16_t __attribute__((nx_base_be(uint16)));
I'm not sure how all this interacts.
You tried:
typedef nx_uint16_t my_type16_t;
I agree it looks like it should work.
I'm wondering if the magic nx_ prefix tells nesc something special about
it......
(/usr/lib/ncc/nesc_nx.h holds many things that help make the nx stuff work).
First, there is a way to tell nesc to just write out the application code
(app.c) and then quite. Start there and see what the app.c file looks
like.
To see what it looks like, first do a "make verbose telosb" or what ever
platform. That will show you all the commands. look for where ncc or
nesc shows up to get the flavor.
Adding -conly should do the trick. Then you can see what it is actually
generating.
Maybe adding a nx_ prefix to your type would help.
On Mon, Feb 11, 2013 at 3:12 AM, Johny Mattsson <[email protected]>wrote:
> Hi list,
>
> I've run into an unexpected problem which I can't figure out how to solve
> properly. It seems to me to be impossible to typedef an "nx" (external)
> type to a new name for some strange reason. I can't find anything in the
> documentation that mentions this as a limitation, so I'm posting here in
> hope of some enlightenment.
>
>
> If I try to build an app with a function taking a typedef'd nx type as an
> argument, I get this error:
>
> $ make micaz
> mkdir -p build/micaz
> compiling TestNxTypedefC to a micaz binary
> ncc -o build/micaz/main.exe -Os -fnesc-separator=__ -Wall -Wshadow
> -Wnesc-all -target=micaz -fnesc-cfile=build/micaz/app.c -board=micasb
> -DDEFINED_TOS_AM_GROUP=0x22 --param max-inline-insns-single=100000
> -DIDENT_APPNAME=\"TestNxTypedefC\" -DIDENT_USERNAME=\"johny\"
> -DIDENT_HOSTNAME=\"silence\" -DIDENT_USERHASH=0x4027b159L
> -DIDENT_TIMESTAMP=0x5118d006L -DIDENT_UIDHASH=0x666c09d5L
> -fnesc-dump=wiring -fnesc-dump='interfaces(!abstract())'
> -fnesc-dump='referenced(interfacedefs, components)'
> -fnesc-dumpfile=build/micaz/wiring-check.xml TestNxTypedefC.nc -lm
> TestNxTypedefP.nc:14:85: error: expected ‘)’ before ‘val’
> TestNxTypedefP.nc:14:85: error: expected ‘)’ before ‘val’
> TestNxTypedefP.nc: In function ‘TestNxTypedefP__Init__init’:
> TestNxTypedefP.nc:21:3: warning: implicit declaration of function
> ‘TestNxTypedefP__foo’
> make: *** [exe0] Error 1
>
>
> Yet, if I simply change the typedef to a #define instead, the app compiles
> without even a warning. I thought it might be because I hadn't updated my
> toolchain (I was still using hinrg repo), but even after switching to
> tinyprod I get the same error.
>
>
> Minimal test app as follows:
>
> ==== Makefile ====
>
> COMPONENT=TestNxTypedefC
> include $(MAKERULES)
>
>
> ==== TestNxTypedefC ====
>
> configuration TestNxTypedefC
> {
> }
> implementation
> {
> components TestNxTypedefP, MainC;
> MainC.SoftwareInit -> TestNxTypedefP;
> }
>
>
> ==== TestNxTypedefP ====
>
> module TestNxTypedefP
> {
> provides interface Init;
> }
> implementation
> {
> #if 1
> /* This fails - why? */
> typedef nx_uint16_t my_type16_t;
> #else
> /* This works, ugly though it is */
> #define my_type16_t nx_uint16_t
> #endif
>
> error_t foo (my_type16_t val)
> {
> return (val == 1234) ? SUCCESS : FAIL;
> }
>
> command error_t Init.init (void)
> {
> return foo (1234);
> }
> }
>
>
> First encountered with this toolchain:
> $ ncc --version
> ncc: 1.2.4
> nescc: 1.3.1
> gcc: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
> Copyright (C) 2011 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> Still encountered with this toolchain:
> $ ncc --version
> ncc: 1.4.2
> nescc: 1.3.4
> gcc: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
> Copyright (C) 2011 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
>
> Thanks in advance,
> /Johny*
> *
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
--
Eric B. Decker
Senior (over 50 :-) Researcher
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help