diff --git a/src/zigbee_ncp/config/zigbee_watchdog_periodic_refresh_config.h b/src/zigbee_ncp/config/zigbee_watchdog_periodic_refresh_config.h new file mode 100644 index 00000000..e317fedb --- /dev/null +++ b/src/zigbee_ncp/config/zigbee_watchdog_periodic_refresh_config.h @@ -0,0 +1,34 @@ +/***************************************************************************//** + * @brief Sample watchdog refresh event component configuration header. + ******************************************************************************** + * # License + * Copyright 2022 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. + * + ******************************************************************************/ + +// <<< Use Configuration Wizard in Context Menu >>> + +// Zigbee Watchdog reset component configuration + +// Enable periodic watchdog refresh +// Default: TRUE +// This allows for enabling or disabling periodic watchdog refresh +#define SL_ZIGBEE_WATCHDOG_PERIODIC_REFRESH_ENABLE 1 + +// Watchdog refresh duration <50-5000> +// Default: 1000 +// Defines the periodic interval at which the watchdog timer is reset in the application +#define SL_ZIGBEE_WATCHDOG_REFRESH_DURATION_MS 1000 + +// +// + +// <<< end of configuration section >>> diff --git a/src/zigbee_ncp/sl_zigbee_watchdog_periodic_refresh.c b/src/zigbee_ncp/sl_zigbee_watchdog_periodic_refresh.c new file mode 100644 index 00000000..e3251c3c --- /dev/null +++ b/src/zigbee_ncp/sl_zigbee_watchdog_periodic_refresh.c @@ -0,0 +1,59 @@ +/***************************************************************************//** + * @file + * @brief Sample watchdog refresh event implementation and related configuration + ******************************************************************************* + * # License + * Copyright 2022 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. + * + ******************************************************************************/ +#include PLATFORM_HEADER +#include "hal.h" +#include "ember.h" +#include "zigbee_app_framework_event.h" +#include "zigbee_app_framework_common.h" +#include "zigbee_watchdog_periodic_refresh_config.h" + +#if (SL_ZIGBEE_WATCHDOG_PERIODIC_REFRESH_ENABLE == 1) + +static sl_zigbee_event_t watchdog_refresh_event; +static void watchdog_refresh_event_handler(sl_zigbee_event_t *event); + +// Initialization of watchdog refresh event +void sli_zigbee_watchdog_refresh_handler_init(uint8_t init_level) +{ + switch (init_level) { + case SL_ZIGBEE_INIT_LEVEL_EVENT: + { + sl_zigbee_event_init(&watchdog_refresh_event, watchdog_refresh_event_handler); + sl_zigbee_event_set_active(&watchdog_refresh_event); + break; + } + default: + break; + } +} + +// In RTOS-based applications, the Zigbee task refreshes the watchdog. +// However, when the node is not on a network the Zigbee task does not run. +// Therefore, there needs to be a way to ensure that the watchdog does not fire +// and reset the node unnecessarily. Below we provide an example of an application +// event that periodically resets the watchdog. +// Note, such a periodic event gets the node out of EM1/EM2 low power modes, +// which may result in unnecessary energy consumption. +// The application should ultimately own the refreshing of the watchdog and tailor +// it based on the specific use case. +// In the bare-metal case, this is done in the zigbee stack and app framework ticks +static void watchdog_refresh_event_handler(sl_zigbee_event_t *event) +{ + halResetWatchdog(); + sl_zigbee_event_set_delay_ms(&watchdog_refresh_event, SL_ZIGBEE_WATCHDOG_REFRESH_DURATION_MS); +} +#endif //(SL_ZIGBEE_WATCHDOG_PERIODIC_REFRESH_ENABLE == 1) diff --git a/src/zigbee_ncp/zigbee_ncp.slcp b/src/zigbee_ncp/zigbee_ncp.slcp index 5ac2ad92..ca6b87cd 100644 --- a/src/zigbee_ncp/zigbee_ncp.slcp +++ b/src/zigbee_ncp/zigbee_ncp.slcp @@ -60,19 +60,28 @@ configuration: value: 1 - name: EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_ALL_PACKETS value: 1 + - name: SL_LEGACY_HAL_DISABLE_WATCHDOG + value: 0 + - name: SL_ZIGBEE_WATCHDOG_PERIODIC_REFRESH_ENABLE + value: 1 source: - path: main.c - path: app.c + - path: sl_zigbee_watchdog_periodic_refresh.c config_file: - path: config/xncp_config.h file_id: xncp_config + - path: config/zigbee_watchdog_periodic_refresh_config.h template_contribution: - name: zigbee_stack_callback priority: -9999 value: {callback_type: override_append_source_route, function_name: nc_zigbee_override_append_source_route} +- name: zigbee_af_callback + value: {callback_type: event_init, function_name: sli_zigbee_watchdog_refresh_handler_init} + filter: - name: Wireless Technology