Hi,

I am writing a simulation for wireless sensor networks under TOSSIM.


I know TOSSIM keeps time track in terms of simulation ticks. I am using the 
following version of TinyOS, tinyos-2.1.0.  Under this version, I have 10^10 or 
100,00,00,00,00 simulation ticks per second. I get this value from 
/tos/lib/tossim/sim_tossim.c

sim_time_t sim_ticks_per_sec() __attribute__ ((C, spontaneous)) {
  return 10000000000ULL;
}

Now, coming to my question, how would I pause for a specific number of 
simulation ticks. 

Actually, I am simulating the behavior of a hardware board where there are 
different pauses involved. The pauses are in milliseconds or microseconds. 

I tried this problem several ways, but still I am not successful. 

First Approach: 

If I just use the C functions like usleep, or sleep. That does not serve the 
purpose, 

i.e. according to given configuration: 

1 milli second = 10^7 simulation ticks
1 micro second = 10^4 simulation ticks

For example if I have the following scenario: 

void main_function(){
        function_A();
       usleep(25);   // 25 micro seconds
        function_B();        
        usleep(25)
}  

Now, let us say, if current time as returned by sim_time() was 123456 after 
function_A(), Then it should be (123456 + 2500,00) in terms of simulation ticks 
after the usleep function is over. but it gives me the same time even after the 
usleep.

Second Approach: 

Next, I tried to enqueue an event for the corresponding function in the 
simulation queue with a timestamp equal to (current time + desired pause in 
simulation ticks). Still, I have a problem. Letus again consider the same 
scenario

I make a strucutre, 

struct funct{
    void(*fp)();   // The function to be executed.
    int node_id;
};

typedef funct funct_t;

void handle_last(void(*fp)()){
        fp();   
}

void sim_gain_handle(sim_event_t* evt){
    funct_t* f = (funct_t*)evt->data;
    handle_last(f->fp);
}

sim_event_t* allocate_event(long t, funct_t* g) {
    sim_time_t cT;
    sim_event_t* evt;

    cT = sim_time();
    
    evt = (sim_event_t*)malloc(sizeof(sim_event_t));
    evt->mote = sim_node();
    evt->time = cT+t;   // desired time stamp
    evt->handle = sim_gain_handle;
    evt->cleanup = sim_queue_cleanup_event;
    evt->cancelled = 0;
    evt->force = 0;
    evt->data = g;
    
    return evt;    
    }    

With the above scenario, I can now enqueue events in TOSSIM event queue with 
desired timestamps. Therefore, the following 

 void main_function(){

        function_A();

        usleep(25);   // 25 micro seconds

        function_B();        

        usleep(25)
        function_C();
}  

would look something like: 

void main_function(){

        function_A();
        evt = allocate_event(250000, function_B());        

        evt = allocate_event(250000, function_C());        
}  



Now the problem here is the following. 

1. I want that, function_C would be processed only after function_B is executed 
and done. But in the above scenario this does not happen, as main_function 
simply enqueues both function_B and function_C at about the same time. 

2. Since, at some later time, the handler will eventually call function_B, the 
control is not with the main function however, One solution could be that when 
function_B is done, I then enqueue the function_C, but that makes it a lot 
messy. Especially, If there are many nested function calls. 


If there was a something simpler like 
sim_pause(250000) // pause for 25 micro seconds, 

it would have been much easier. 

Any, help would be much appreciated. 

regards, 
Zahid Iqbal





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

Reply via email to