best code organization to read multiple sensors
Posted: Fri Jul 04, 2014 1:11 pm
Hi,
this is a bit more architecture than chibios dependant, but here the question;
if you have to read multiple sensor, maybe on different bus, witch may or may not be work togheder, and read may be from an external interrupt or from a polling, how would you do?
i've done this: interrupt set the "sensor read variable", as VirtualTimer do for polling sensor. Ther the "read thread" sequentialli read all sensor.
This is not the best; i was thinking use a "read thread" for every bus (i2c, spi, and so on); or maybe one for every sensor, with a fixed "grid" with tell witch sensor may run parallel respect each others.
Is this a good idea? would you use dinamic thread allocation (maybe with pool) and kill it when read is over? as far as i know i can't stop/restart thead, unless using some lock-trick, and trigger this lock-trick instead of setting a flag and polling it.
i'm asking here because maybe someone has thinked about it and there are ready solution, or special case i'm not taking into account.
this is a bit more architecture than chibios dependant, but here the question;
if you have to read multiple sensor, maybe on different bus, witch may or may not be work togheder, and read may be from an external interrupt or from a polling, how would you do?
i've done this: interrupt set the "sensor read variable", as VirtualTimer do for polling sensor. Ther the "read thread" sequentialli read all sensor.
This is not the best; i was thinking use a "read thread" for every bus (i2c, spi, and so on); or maybe one for every sensor, with a fixed "grid" with tell witch sensor may run parallel respect each others.
Is this a good idea? would you use dinamic thread allocation (maybe with pool) and kill it when read is over? as far as i know i can't stop/restart thead, unless using some lock-trick, and trigger this lock-trick instead of setting a flag and polling it.
i'm asking here because maybe someone has thinked about it and there are ready solution, or special case i'm not taking into account.