IWPengineering / IWP_Firmware_2.0_Beta

Rewrite of IWP Firmware for PIC24F32KA302 (3.3V version of previous micro)
0 stars 1 forks source link

Intermittent while-breaks in simulation #4

Closed Ken-Kok closed 8 years ago

Ken-Kok commented 8 years ago

During simulation of the code, I found that when everything is enabled, sometimes the simulator spontaneously resets.

I think this is probably because I am getting stack overflow errors due to the way the simulator and I2C drivers interact - I2C breaks lockups (which happen, because there are no physical pins in the simulator) by toggling pins, which it can't do, because its in the simulator. The way that the I2C drivers implement this is by recursive calling of break functions, which would normally change pin status bits and break up the problem. However, in the simulator, it doesn't work (the problem doesn't break).

This could easily cause stack-overflow errors (and does cause frequent lockups).

Even though this is probably not a problem, it is probably a good idea to implement another way the code can break out of I2C lockups than just overflowing the stack - if pins don't respond. This should probably be some kind of limit before it just gives up on getting the time, and makes sure to not update the day (so we don't accidentally send a midnight message).

Ken-Kok commented 8 years ago

I'm starting to get rid of recursive loops, replacing them with status checking loops in the I2C Drivers. I think this will fix any problem of this nature.

Ken-Kok commented 8 years ago

I believe I got rid of all the recursion in d23ce8b36c4bd5d106b3e3817fe30ec42bf14aee, will test functionally whenever I have hardware available.

Ken-Kok commented 8 years ago

This also had to do with an address error, but is fixed now.

Fixed in da981a70267cca2c0dcddd5b8d5779b90ddd2485