system/system_monitor/main.c

/*******************************************************************************
* # License
* Copyright 2019 Silicon Laboratories Inc. www.silabs.com
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/* Documentation for this app is available online.
* See https://docs.silabs.com/gecko-os/4/standard/latest/sdk/examples/system/system-monitor
*/
#include "gos.h"
#define MAX_DELAY 7000
#define APPLICATION_START_LINE "\r\nSystem Monitor example starting ..."
static gos_system_monitor_t system_monitor;
static int counter;
/*************************************************************************************************/
void gos_app_init(void)
{
GOS_LOG(APPLICATION_START_LINE);
gos_register_system_monitor(&system_monitor, MAX_DELAY, NULL);
counter = 3;
// Register a periodic event to update the system monitor;
gos_event_register_periodic(update_system_monitor_event_handler, NULL, (MAX_DELAY / 2), 0);
}
/*************************************************************************************************/
void gos_app_deinit(void)
{
// MUST unregister the system monitor when we're done
}
/*************************************************************************************************/
static void update_system_monitor_event_handler(void *arg)
{
GOS_LOG("Updating system monitor");
// Update the monitor to indicate everything is working correctly
gos_update_system_monitor(&system_monitor, MAX_DELAY);
// Once the counter reaches 0, unregister the update event handler
// This simulates something locking up
// When the system monitor stops getting updated a watchdog will be triggered
if(--counter <= 0)
{
GOS_LOG("Simulating system lock up, watchdog will be triggered in %d seconds ...", (MAX_DELAY /1000));
gos_event_unregister(update_system_monitor_event_handler, NULL);
}
}