Skip to content

Commit

Permalink
Re-enable the watchdog for Zigbee
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Oct 31, 2024
1 parent 8f1b771 commit 59e1039
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/zigbee_ncp/config/zigbee_watchdog_periodic_refresh_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/***************************************************************************//**
* @brief Sample watchdog refresh event component configuration header.
********************************************************************************
* # License
* <b>Copyright 2022 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* 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 >>>

// <h>Zigbee Watchdog reset component configuration

// <e SL_ZIGBEE_WATCHDOG_PERIODIC_REFRESH_ENABLE> Enable periodic watchdog refresh
// <i> Default: TRUE
// <i> This allows for enabling or disabling periodic watchdog refresh
#define SL_ZIGBEE_WATCHDOG_PERIODIC_REFRESH_ENABLE 1

// <o SL_ZIGBEE_WATCHDOG_REFRESH_DURATION_MS> Watchdog refresh duration <50-5000>
// <i> Default: 1000
// <i> Defines the periodic interval at which the watchdog timer is reset in the application
#define SL_ZIGBEE_WATCHDOG_REFRESH_DURATION_MS 1000

// </e>
// </h>

// <<< end of configuration section >>>
59 changes: 59 additions & 0 deletions src/zigbee_ncp/sl_zigbee_watchdog_periodic_refresh.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/***************************************************************************//**
* @file
* @brief Sample watchdog refresh event implementation and related configuration
*******************************************************************************
* # License
* <b>Copyright 2022 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* 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)
9 changes: 9 additions & 0 deletions src/zigbee_ncp/zigbee_ncp.slcp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59e1039

Please sign in to comment.