Again, bad style, but there's nothing really preventing you from just creating a c-style function in a header file, and then #including it in any component you wish to use it in.
You can even declare it in a header file, #include that file in any components you wish to use it, and then implement it within the body of one of your TinyOS modules so that it will have access to the variables defined in that module. To go this route, you need to add some nesC attributes to your function definition though. Take a look at the defintiion of uart_putchar() in tos/lib/printf/PrintfP.nc for an example. And take a look at chapter 9 of the TinyOS programming Manual to understand what these attributes are doing. http://csl.stanford.edu/~pal/pubs/tinyos-programming.pdf Kevin On Dec 14, 2007 8:12 AM, Greg Hackmann <[EMAIL PROTECTED]> wrote: > Michiel Konstapel wrote: > >> I'm wondering whether I can define global function. > >> The global function mean, I define a function in > >> component A, and I can call this function in component > >> B without using interface, just call the function directly? > > > > No, all interaction between components has to go through the commands > and > > events they define in their interfaces. Well, you could probably hack > your > > way there, but you're not really supposed to. > > Actually, you can have components provide and use commands and events > that aren't tied to any interfaces; e.g.: > > module SomeComponentP { > provides command bool someCommand(uint8_t param); > } > implementation { > command bool someCommand(uint8_t param) { > ... > } > } > > This feature is used in a handful of places in TinyOS 2.0, like the > TOSSIM ActiveMessage layer. See > tos/lib/tossim/ActiveMessageAddressC.nc and > tos/lib/tossim/TossimActiveMessageP.nc for an example. > > Doing this is arguably bad style, but it's possible nonetheless. > > Greg Hackmann > _______________________________________________ > Tinyos-help mailing list > [email protected] > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > -- ~Kevin
_______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
