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
To enable the sensor data aggregator module,select the CONFIG_CAF_SENSOR_DATA_AGGREGATOR
Kconfig 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 = <240>; sample_size = <3>; status = "okay"; }; agg1: agg1 { compatible = "caf,aggregator"; sensor_descr = "void_test_sensor"; buf_data_length = <80>; sample_size = <1>; 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.buf_data_length
- This parameter represents the length of the buffer in bytes. Its default value is120
. You should set the value as a multiple of sensor sample size times the size ofsensor_value
(i*sample_size*sizeof(struct sensor_value)
).sample_size
- This parameter represents the sensor sample size and is expressed insensor_value
per sample. Its default value is1
.buf_count
- 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.