I was unable to allow the dog to sleep. Had to find the bug or I was not going to be able to sleep.
After a few more occurances, I had enough data to give me reason to suspect I was going out of range on the GPS receiver buffer. So I instrumented that section of code and let it run. An hour later, the code triggered and I had my answer. The GPS decided to send me a message I had not registered. It was larger than the buffer size I had allocated based on the messages I had registered for. To make matters worst, I had an error in the code that checked that the message would fit in the buffer. Made the correction and let it run all night. No errors!
Now its time to start logging the GPS data to the SD card.
The symptoms — or at least red herring while debugging — reminded me of those experienced in my very brief foray into RTOS programming on the mbed. Too-small stack, in my case, and quite reproducible, however. I’ve lost my naiveté regarding printf library calls in an RTOS environment…
Based on the implementation, printf often uses malloc. Malloc is not often implemented as multithread safe. So bad news. On this project I have been using precious few of the built in functions. I do not use the native snprintf but rather wrote my own ‘format’ routine such that I could inforce safe RTOS programing. But of course, it introduces more lines of code where you can make a mistake.