As well explained in Bill document the different tasks are executed at appropriate rate to have a well balanced code, allowing a lot of computations also with processors smaller then dsPIC33F. Increasing CPU clock frequency it is possible to get more power but, any case, it is a good programming technique to wonder accurately about the real needs. I've added the I2C communication with dsNAV, sharing the same bus with magnetometer, the communication is executed at the same 40Hz rate, after the robot attitude is computed an DCM is ready with new values. This 25ms period is a good compromise between processor load and refresh rate for navigation board.
IMU
Through the IMU all the navigation peripherals are connected to the HLS, so the communications of this board have to be well designed to not interfere with all interrupt-driven lino-UDB4 code.
UART1 is dedicated to talk with GPS @ 19200bps in binary mode. This is to have minimum latency on readings, otherwise, even if the update is as slow as 1Hz rate, it can replays also with some seconds delay.
UART2 is used for telemetry @ 57600bps for both test or real work.
All functions which name starts with "GO_" are my personal additions to the original MatrixPilot software, Vers. 3.3 R.1880 - Dec.26th 2012
I2C 1 module is dedicated to 24LC256 EEPROM installed on UDB4 board (not used in my code).
I2C 2 is used for communication with magnetometer and dsNav.
All the communication callback functions are triggered by peripherals interrupt, to avoid slowing down the program. The I2C bus, because it is shared among multiple devices, uses also a multi buffer mode to allow different devices to have their own EEPROM-like exchange sequence.
The read and write I2C functions are a very clever usage of pointers and Function Pointers. The different transmit or receive buffers are passed as reference and also the function to call next in case of success is referenced in the call, allowing an easy way of creating a Finite State Machine.
S : (r) Ref. speed and heading setting (mm/s and degrees)
T :
(w) Time details send (Year, Month, Day, Hour, Min, Sec)
G: (w) GPS service params request and receive (Sats., Quality)
b : (w) Speed, current and position details send (mm/s, mA, m)
K : (w) GPS and IMU details send (GPS and DCM)
After the communication successfully ends e very simple command parser starts executing the requested functions.
'w' = data written (IMU -> HLS)
'r' = data read (IMU <- HLS)