I have a TOSThreads, TinyLD system, heavily based on the SerialLoaderFlash 
example.

I compile new functionality on the laptop as a dynamic threads module, transfer 
it to the mote where it gets stored in flash. When the module is loaded, it 
registers itself with the monolithic app on the mote by calling a function I 
exposed by adding it to: tos/lib/tosthreads/lib/tinyld/tosthread_slcs_types.h. 

So far so good.

This "registration" function takes a function pointer as an argument which is, 
if you like, the constructor of the module that just registered itself. 
Unfortunately, when the monolithic code calls this function nothing much 
happens. Far as I can tell, the function pointer being passed in by the loaded 
module becomes invalid as it enters the monolithic app.

The loaded module looks like this (simplified for clarity):

tosthread_t button_sensor_source;
tosthread_t button_sensor_source_registration;

Source alloc_button_sensor_source() {
  // whatever
}

void button_sensor_source_registration_thread(void* arg) {
  register_source(&alloc_button_sensor_source);
}

void tosthread_main(void* arg) {
  tosthread_create(&button_sensor_source_registration, 
button_sensor_source_registration_thread, NULL, 200);
}

When TinyLD does it's thing, "tosthread_main" gets invoked which creates a new 
thread that uses the "button_sensor_source_registration_thread" function as 
it's entry point and in there registers itself with the main app.

A simplistic version of the "Registration" function (the one in the monolithic 
app) looks like this:

void register_source(Source (*constructor)()) {
  Source source = constructor(); 
  // whatever
}

When I test this, the line that calls the function is executed, but the 
function "constructor" points to is not invoked.

Anyone know what's going wrong here? 

Is there anyway to make the constructor pointer valid in the main app? 

Does the loaded module become invalid when it's "tosthread_main" function exits?

FYI - This is a port of code that works flawlessly on Contiki, but I may simply 
be using the wrong paradigm for TinyOS/TOSThreads. If I am, please point me in 
the right direction!

Many thanks,

David Harrison
University College Dublin
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to