Application Event Manager

The Application Event Manager sample demonstrates the functionality of the Application Event Manager subsystem. It uses an event-driven architecture, where different modules communicate through sending and processing events.

Overview

The sample application consists of three modules that communicate using events:

Sensor (sensor_simulated.c):

This module waits for a configuration event (which is sent by main.c). After receiving this event, it simulates measured data at constant intervals. Every time the data is updated, the module sends the current values as measurement event. When the module receives a control event from the Controller, it responds with an ACK event.

Controller (controller.c):

This module waits for measurement events from the sensor. Every time a measurement event is received, the module checks one of the measurement values that are transmitted as part of the event and, if the value exceeds a static threshold, sends a control event.

Statistics (stats.c):

This module waits for measurement events from the sensor. The module calculates and logs basic statistics about one of the measurement values that are transmitted as part of the event.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF9160 DK

PCA10090

nrf9160dk

nrf9160dk/nrf9160/ns

nRF54H20 DK

PCA10175

nrf54h20dk

nrf54h20dk/nrf54h20/cpuapp

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp/ns nrf5340dk/nrf5340/cpuapp

nRF52 DK

PCA10040

nrf52dk

nrf52dk/nrf52832

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

nRF21540 DK

PCA10112

nrf21540dk

nrf21540dk/nrf52840

When built for a board target with the */ns variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

Configuration

See Configuring and building for information about how to permanently or temporarily change the configuration.

Building and running

This sample can be found under samples/app_event_manager in the nRF Connect SDK folder structure.

When built as firmware image for a board target with the */ns variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). To read more about CMSE, see Processing environments.

To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

Testing

After programming the sample to your development kit, test it by performing the following steps:

  1. Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.

  2. Reset the kit.

  3. Observe that output similar to the following is logged on UART:

    ***** Booting Zephyr OS v1.13.99-ncs1-4741-g1d6219f *****
    [00:00:00.000,854] <inf> app_event_manager: e: config_event init_val_1=3
    [00:00:00.001,068] <inf> app_event_manager: e: measurement_event val1=3 val2=3 val3=3
    [00:00:00.509,063] <inf> app_event_manager: e: measurement_event val1=3 val2=6 val3=9
    [00:00:01.018,005] <inf> app_event_manager: e: measurement_event val1=3 val2=9 val3=18
    [00:00:01.526,947] <inf> app_event_manager: e: measurement_event val1=3 val2=12 val3=30
    [00:00:02.035,888] <inf> app_event_manager: e: measurement_event val1=3 val2=15 val3=45
    [00:00:02.035,949] <inf> app_event_manager: e: control_event
    [00:00:02.035,980] <inf> app_event_manager: e: ack_event
    [00:00:02.544,830] <inf> app_event_manager: e: measurement_event val1=-3 val2=12 val3=57
    [00:00:03.053,771] <inf> app_event_manager: e: measurement_event val1=-3 val2=9 val3=66
    [00:00:03.562,713] <inf> app_event_manager: e: measurement_event val1=-3 val2=6 val3=72
    [00:00:04.071,655] <inf> app_event_manager: e: measurement_event val1=-3 val2=3 val3=75
    [00:00:04.580,596] <inf> app_event_manager: e: measurement_event val1=-3 val2=0 val3=75
    [00:00:04.580,596] <inf> stats: Average value3: 45
    

Dependencies

This sample uses the following nRF Connect SDK subsystems:

In addition, it uses the following Zephyr subsystems:

The sample also uses the following secure firmware component: