Basic System Monitor Example

Use a system monitor to enable ZentriOS to supervise app behaviour.

API Features Demonstrated

Platforms

This app works on:

Requirements and Prerequisites

This app requires a ZentriOS device.

Description

The system monitor provides a way for ZentriOS to ensure that an application does not hang.

A system monitor is registered to trip a watchdog alarm if it is not updated within a specified time.

The app creates a system monitor update event to update the system monitor within the specified time, as long as the app is working properly.

If the app fails to update the system monitor, the alarm goes off and the watchdog reboots the system.

In this demonstration, the app ensures that the system monitor update only works three times.

Output is similar to the following:

Updating system monitor
Updating system monitor
Updating system monitor
Simulating system lock up, watchdog will be triggered in 7 seconds ...
1: Watchdog Exception, uhandle:00 bhandle:37 PC:0x1A009CC8 LR:0x1A01CC27

Implementation

The app registers a system monitor by calling zn_register_system_monitor, specifying a maximum time between updates of MAX_DELAY milliseconds.

Once the monitor is registered, zn_update_system_monitor must be called before MAX_DELAY milliseconds expires, otherwise a watchdog fault will occur, causing a system reset.

The call to zn_event_register_periodic registers a periodic update handler to be called every MAX_DELAY/2 milliseconds. This should ensure timely updates of the system monitor.

However the handler update_system_monitor_event_handler ensures that the update does not occur, by de-registering the monitor update periodic event after the third update.

Note: De-registering the update event is intended to demonstrate the triggering of the watchdog, rather than to serve as an example of best practice system monitor event handling.

In zn_app_deinit a call to zn_unregister_system_monitor unregisters the monitor event.

Source

See: