CAF: Sensor data aggregator module
The sensor data aggregator module of the Common Application Framework (CAF) is a simple module responsible for aggregating sensor data in form of sensor_event
and passing them further in packages.
It can be used in both single-core and multi-core SoCs.
When used with multi-core SoCs, the sensor data aggregator module can reduce power consumption. One core gathers data from sensors and when there is sufficient data to analyze, the first core wakes up the other core and sends the aggregated data to that core.
Configuration
The sensor data aggregator module module can be enabled by selecting the CONFIG_CAF_SENSOR_DATA_AGGREGATOR
option.
To use the module, you must complete the following steps:
Enable the
CONFIG_CAF_SENSOR_DATA_AGGREGATOR
option.If you are using multi-core SoC and want to receive aggregated data on another core, on the second core enable the
CONFIG_CAF_SENSOR_DATA_AGGREGATOR_EVENTS
option.Enable aggregator in devicetree file that describes the aggregator parameters you can use for example app.overlay file. Each aggregator should be placed as a separate node. For example, the file content could look like follows:
agg0: agg0 { compatible = "caf,aggregator"; sensor_descr = "accel_sim_xyz"; buf_data_length = <120>; sensor_data_size = <12>; status = "okay"; }; agg1: agg1 { compatible = "caf,aggregator"; sensor_descr = "void_test_sensor"; buf_data_length = <80>; sensor_data_size = <8>; status = "okay"; };
Two aggregators are defined here and each one is responsible to handle data of the different sensors. The aggregator is defined as a separate node in the devicetree and consists of the following parameters:
compatible
- This is DTS binding and should be set tocaf,aggregator
.sensor_descr
- This parameter represents the description of the sensor and should be the same as the description in the CAF: Sensor manager module module.buf_data_length
- This parameter represents the length of the buffer in bytes. Its default value is120
. The value should be set as a multiple of sensor sample size.sensor_data_size
- This parameter represents the sensor sample size and is set in bytes. Its default value is4
.buf_coun
- This parameter represents the number of buffers in the aggregator. Its default value is2
.status
- This parameter represents the node status and should be set tookay
.
Implementation details
sensor data aggregator module subscribes to following sensor manager events:
The sensor data aggregator module gathers data from sensor_event
and stores the data in an active aggregator_buffer
.
When buffer is full, the sensor data aggregator module sends the buffer to sensor_data_aggregator_event
struct.
Then module searches for the next free aggregator_buffer
and sets it as an active buffer.
After changing the sensor state and receiving sensor_state_event
, the sensor data aggregator module sends the data that is gathered in the active buffer.
After receiving sensor_data_aggregator_release_buffer_event
, the sensor data aggregator module sets aggregator_buffer
to free state.
Several buffers can be reduced to one, in case of a situation where the sampling period is greater than the time needed to send and process sensor_data_aggregator_event
.
In the situation when sampling is much faster than the time needed to send and process sensor_data_aggregator_event
, the number of buffers should be increased.