Does IMP runs multiple threads?

We are running a board with IMP as host controller and some sensors to collect the sensing data. One of the sensor is an Accelerometer, which is supposed to collect samples in multiple of thousands. Because of memory limitation in IMP, we are periodically sending the data to agent. say every 100 samples collected, We upload it to agent.
We are unaware if, wifi stack is running in separate thread or every thing is running sequentially.
For now in our case, when ​
accelerometer
​sampling frequency goes beyond say 800 Hz, my accelerometer says there is overflow in its internal FIFO since its not being read by host ​
fast enough
​. a snippet of code looks like this
`
while(count < this.num_samples)
{
for (i=0;i<other_sreg.len();i++)
{

        status = spi_read(other_sreg[i],1)
           if ((status[0] & other_sreg_mask[i]) == other_sreg_mask[i] )
           {
              error+=1;

// petasense_log(" register " + other_sreg[i] + " mask " +other_sreg_mask[i] + "read " +(status[0] ))
}
}
status = spi_read(fifo_sreg,1);
// petasense_log("fifo_ status "+ status[0])
status[0] = status[0] & 0x3f;

     if(status[0] > 0)
     {
        if((num_samples - count) < status[0])
        {
           status[0] = num_samples - count;
        }
        count += status[0];
        
        while(status[0]--)
        {
           read_val();
        }
        if ((data_x.len()/200)>=1)
        {
           this.upload_samples();
        }
     }

  }
  this.upload_samples();
  end_time = get_current_time();
  return [data_x,data_y,data_z];

}
`
Is there a possible way to get around this scenario and run the firmware along with meeting the timing requirements. Currently we are looking to scale up the system to ​
10000 Hz ​

There are multiple threads, yes, and wifi transmissions will happen in the “background”. Squirrel runs on a single thread only though, and if the TCP transmit buffer on the imp is full and you do an agent.send(), the squirrel code will block.

Things to bear in mind:

  • Make sure you are using WAIT_TIL_SENT vs WAIT_FOR_ACK in your connection policy. If you use WAIT_FOR_ACK your squirrel thread will not resume until the data has been ACKed by the imp server. Depending on your latency to the US west coast (where the development servers are), this will slow you down a lot.

  • You can also increase the amount of memory assigned to the TCP transmit buffers, which allows you to increase the upstream bandwidth (as this is determined by buffer size and latency, as the imp has to hold a copy of all data until it’s ACKed by the server). See http://electricimp.com/docs/api/imp/setsendbuffersize/

  • You should optimize your sample collection code above. You should be able to drain the FIFO in a single read operation, most likely. You should also reduce the amount of processing done on the imp if you can instead do this in the agent (eg de-interleaving samples etc).

Thanks Hugo,
seems like its an issue with SPI transaction. I’ve started another thread for it here
http://forums.electricimp.com/discussion/2857/time-interval-between-spi-transactions-is-too-high-400us#Item_3