Yes, you have to use globals to pass arguments to tasks, so do something
like this and set the values in your async function before posting the task:
uint16_t *buf;
uint16_t buflen;
task void SendReadingsTask1() { ... }
You can't guarantee order of task execution, but you can sequence them
by posting a new task from the end of a previous one.
MS
John Griessen wrote:
I'm making a read-A2D-then-broadcast-send-data app.
The first thing to do in a sequence is async:
Msp430Adc12MultiChannel.dataReady(uint16_t *buf, uint16_t buflen) is the
next I need to do a sync function:
call AMSend.getPayload(&pkt)
and use buf and buflen to do some reads and writes,
then another sync function:
call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(MoistureSensorsMsg))
The compiler issues warnings about sync from async event, but finishes.
The TinyOS Programming guide says to use a task... but a task doesn't
seem to allow passing parameters... how would I use the buf and buflen
variables?
Would you first copy buf and buflen to global variables?
Is there a way to sequence small tasks to run in order?
Do they automatically run in order, so results of one are available to
the next if put in global variables?
Here's an attempt I made to use tasks that is broken -- buf is unknown
inside the function, parameters don't get passed to a task:
=======================================================
task void SendReadingsTask1(uint16_t *buf, uint16_t buflen)
{
MoistureSensorsMsg* rmspkt = (MoistureSensorsMsg*) (call
AMSend.getPayload(&pkt));
//cast result of .getPayload to pointer of nx_struct
MoistureSensorsMsg*
rmspkt->nodeid = TOS_NODEID;
rmspkt->timestamp = timestamp;
if ( buflen == 12 ) // 12 Adc values in a vector, len == 12
{
rmspkt->adc00 = buf[0];
rmspkt->adc01 = buf[1];
rmspkt->adc02 = buf[2];
rmspkt->adc03 = buf[3];
rmspkt->adc04 = buf[4];
rmspkt->adc05 = buf[5];
rmspkt->adc10 = buf[6];
rmspkt->adc11 = buf[7];
rmspkt->adc12 = buf[8];
rmspkt->adc13 = buf[9];
rmspkt->adc14 = buf[10];
rmspkt->adc15 = buf[11];
//rmspkt struct is now filled with new data.
if (call AMSend.send(AM_BROADCAST_ADDR, &pkt,
sizeof(MoistureSensorsMsg)) == SUCCESS) {
call Leds.led2On(); //debug aid
busy = TRUE; //the data is queued to go out.
}
}
else
.
.
.
======================================================
What is the right way to handle this?
Thanks,
John Griessen
--
Platform: WinXP/Cygwin
TinyOS version: 1.x, Boomerang
Programmer: MIB510
Device(s): Mica2, MicaZ, Tmote
Sensor board: homebrew
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help