On Nov 16, 2005, at 11:18 AM, David Moss wrote:

** Pointers are the way to go... for passing back a lot of data at once.

Again, I've never used an MDA300, but if you're passing back only one piece
of data at a time, Michael's ADC example is a good one to follow.

David


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David Moss
Sent: Wednesday, November 16, 2005 12:12 PM
To: 'Philippe Habib'; [email protected]
Subject: RE: [Tinyos-help] Events and data passing


I've never used an MDA300, but data passing techniques are used everywhere.

Here's one possible strategy:

First, setup your interface to the component that will allow other
components to read from the MDA300, here's an example:


//////////////////////////////////////////////////////
interface MDA300 {

  /**
   * Request a read
   */
  command result_t read();

  /**
* Here's the data to read, after some asynchronous time has passed to * perform the read. Void because we don't care what happens on the other
end.
   */
  event void readDone(void *data, uint8_t len, result_t result);
}
//////////////////////////////////////////////////////


If you're passing large amounts of data around, pointers are the best solution (e.g., passing a TOS_Msg by value is, well, inefficient :)).

The one thing to be careful of when using pointers is making sure that only one component thinks it "owns" the pointer at any time. This prevents components from stomping on each other's memory and also prevents pointers from being lost.

This latter point means that in the suggested interface, a component that handles the readDone event shouldn't hold onto the void*, as other components might be doing the same thing, and the MDA300 component is going to need to reuse it. Rather, they should copy out the parts that they need into their local storage.

Phil

-------

"We shall not cease from exploration
And the end of all our exploring
Will be to arrive where we started
And know the place for the first time."

- T. S. Eliot,  'Little Gidding'


_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to