Optimize sensors data path

Description

State estimation code installs sensorUpdatedCb handler on number of sensors objects, including high rate Gyro and Accel. Traditionally, callbacks are triggered from eventdispatcher (which is in turn run as callbackscheduler task), to ensure isolation from calling thread (I think, correct me if I'm wrong here).

However, as sensorUpdatedCb() is not doing pretty much anything other than setting flags and requesting callbackscheduler to dispatch StateEstimationCb, making a shortcut and skipping the eventdispatcher saves some cpu cycles and reduces latency with no side effects (given the simplicity of sensorUpdatedCb handler).

Also, similar place is in innerloop.c where GyroState callback only gets to request dispatching of stabilizationInnerloopTask().

Suggested improvement is to replace calls to

stateestimation.c

1 2 3 4 5 6 7 8 GyroSensorConnectCallback(&sensorUpdatedCb); AccelSensorConnectCallback(&sensorUpdatedCb); MagSensorConnectCallback(&sensorUpdatedCb); BaroSensorConnectCallback(&sensorUpdatedCb); AirspeedSensorConnectCallback(&sensorUpdatedCb); AuxMagSensorConnectCallback(&sensorUpdatedCb); GPSVelocitySensorConnectCallback(&sensorUpdatedCb); GPSPositionSensorConnectCallback(&sensorUpdatedCb);

and
innerloop.c

1 GyroStateConnectCallback(GyroStateUpdatedCb);

With xConnectFastCallback() versions, those which invoke callback directly, and not through eventdispatcher.

This improvement reduces overall CPU usage by 5% on F3 targets.

Status

Assignee

Vladimir Zidar

Reporter

Vladimir Zidar

Labels

None

Components

Fix versions

Priority

Medium