firmware
The last 6 weeks have been mainly taken up with an overhaul of the firmware (the code that runs on the CPUs that talk to the SRRs, XBee radio, battery management system, etc).
Because the radios have to work for an extended time on battery power, it’s important to use a very low power CPU (we are using an ARM M0). One of the consequences of this is that the hardware environment is very constrained - the biggest constraint is that we only have 20KB RAM, and a lot of this is used up by the heap and the stack. Only the remaining RAM is available for us to store data temporarily while we process it.
The previous versions of the software was using dynamic memory allocation - ie. we grab memory when we need it, and give it back when we’re done. But there are issues with this and also any bugs in this code can have catastrophic consequences. So - the overhaul has been mainly to convert to using static memory allocation; this gives us much better reliability and predicability.
The firmware is responsible for the following things:
- listening for any data coming in from the SRRs and very quickly storing it
- looking for any stored data from the SRRs and adding it to a list to process later
- processing this list by creating a payload and sending to the Xbee
- storing this sent data in a different list
- listening for any data from the XBee and storing it very quickly
- looking for any stored data from the XBee and adding it to a list to process later
- processing this list, eg. if the XBee told us that a payload was successfully sent, then removing it from the list
- checking lots of lists to make sure there’s been no timeout
- handling error conditions
- querying the state of the battery
- sending status information to meshO Prime
- etc, etc, etc!
The other big change has been to move from using UART to USB communication to the main port. USB allows us to have more that one logical port on the host PC, so one data stream can go to event software and another can go to monitoring the health of the network, for example.
All in all there’s now thousands of lines of code, but it’s all in the pursuit of having very reliable radios!
For example, each meshO Control can store 200 punches if the radio network is down. When the radio network comes back up, then it’ll send all those punches through as fast as it can.