b-parasite-esp32/code/nrf-connect/samples/zigbee/src/restart_handler.c
rbaron 509350457f [ZigBee sample] Introduce debug counters
In the effort to increse reliability of the Zigbee sample, #126 and #130
introduced handling for possibly rare, hard-to-debug events that may be
occurring. While these changes seem to help in practive, we don't know
exactly how often, if ever, they are triggered.

This PR introduces debug_counters in hope to add some visilibty in these
hard-to-debug, rare conditions.

Calling `prst_debug_counters_increment("some_counter")` will increment a
value stored in flash. These values are then dumped via logging when the
device boots. Moving forward we can also consider exposing these values
via a ZigBee cluster.
2023-06-07 08:08:34 +02:00

34 lines
1 KiB
C

#include "restart_handler.h"
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zigbee/zigbee_app_utils.h>
#include "debug_counters.h"
LOG_MODULE_REGISTER(restart_handler, CONFIG_LOG_DEFAULT_LEVEL);
void callback_work_handler(struct k_work *work) {
LOG_INF("Running restart callback_work_handler.");
prst_debug_counters_increment("steering_watchdog_restart");
// If the device is not commissioned, the rejoin procedure is started.
user_input_indicate();
}
K_WORK_DEFINE(callback_work, callback_work_handler);
// Runs in an ISR context. We offload the actual work to a workqueue.
static void restart_network_steering_cb(struct k_timer *timer) {
LOG_INF("Triggered restart_network_steering_cb. Offloading work.");
k_work_submit(&callback_work);
}
K_TIMER_DEFINE(restart_timer, restart_network_steering_cb, NULL);
void prst_restart_watchdog_start() {
k_timer_start(&restart_timer, K_SECONDS(CONFIG_PRST_ZB_RESTART_WATCHDOG_TIMEOUT_SEC), K_MSEC(0));
}
void prst_restart_watchdog_stop() {
k_timer_stop(&restart_timer);
}