Data Logger BLE Cellular Board
Loading...
Searching...
No Matches
watchdog_app.c File Reference

Watchdog application wrapper for initializing, starting, and feeding the watchdog timer using Zephyr watchdog APIs. More...

#include "../jfet_files/jfet_common.h"
#include <zephyr/device.h>
#include <zephyr/drivers/watchdog.h>
#include <zephyr/kernel.h>
#include "watchdog_app.h"
#include <zephyr/logging/log.h>

Go to the source code of this file.

Classes

struct  wdt_config_storage
 Watchdog configuration storage. More...
 
struct  wdt_data_storage
 Watchdog runtime data storage. More...
 

Macros

#define WDT_FEED_WORKER_DELAY_MS   ((CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC * 1000) / 2)
 
#define WATCHDOG_TIMEOUT_MSEC   (CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC * 1000)
 

Functions

 LOG_MODULE_REGISTER (watchdog_app)
 
static void watchdog_notify_event (const struct watchdog_evt *evt)
 Notify the registered watchdog event handler of an event.
 
static void primary_feed_worker (struct k_work *work_desc)
 Primary watchdog feeding work handler.
 
static int watchdog_timeout_install (const struct wdt_config_storage *config, struct wdt_data_storage *data)
 Installs a watchdog timeout configuration and registers it with the WDT device.
 
static int watchdog_start (const struct wdt_config_storage *config)
 Starts the watchdog timer hardware instance.
 
static int watchdog_feed_enable (const struct wdt_config_storage *config, struct wdt_data_storage *data)
 Enable periodic feeding of the hardware watchdog.
 
static int watchdog_enable (const struct wdt_config_storage *config, struct wdt_data_storage *data)
 Enable and initialize the watchdog: verify device readiness, install the timeout, start the watchdog hardware, and enable periodic feeding.
 
int watchdog_init_and_start (void)
 Initialize and start the watchdog timer.
 
void watchdog_register_handler (watchdog_evt_handler_t evt_handler)
 Register handler to receive watchdog callback events.
 

Variables

static watchdog_evt_handler_t app_evt_handler
 Registered application event handler.
 
static bool init_and_start
 Flag set when the library has been initialized and started. *‍/.
 
static const struct wdt_config_storage wdt_config
 Watchdog device configuration storage.
 
static struct wdt_data_storage wdt_data
 

Detailed Description

Watchdog application wrapper for initializing, starting, and feeding the watchdog timer using Zephyr watchdog APIs.

Note
SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

Definition in file watchdog_app.c.

Macro Definition Documentation

◆ WATCHDOG_TIMEOUT_MSEC

#define WATCHDOG_TIMEOUT_MSEC   (CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC * 1000)

Definition at line 25 of file watchdog_app.c.

◆ WDT_FEED_WORKER_DELAY_MS

#define WDT_FEED_WORKER_DELAY_MS   ((CONFIG_WATCHDOG_APPLICATION_TIMEOUT_SEC * 1000) / 2)

Definition at line 24 of file watchdog_app.c.

Function Documentation

◆ LOG_MODULE_REGISTER()

LOG_MODULE_REGISTER ( watchdog_app )

◆ primary_feed_worker()

static void primary_feed_worker ( struct k_work * work_desc)
static

Primary watchdog feeding work handler.

This work handler feeds the watchdog timer periodically unless the stopWDTFeed flag is set. If feeding succeeds, the work is rescheduled after WDT_FEED_WORKER_DELAY_MS. If the flag is set, the function returns early to allow the watchdog to timeout.

Parameters
work_descPointer to the work item descriptor.

Definition at line 85 of file watchdog_app.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watchdog_enable()

static int watchdog_enable ( const struct wdt_config_storage * config,
struct wdt_data_storage * data )
static

Enable and initialize the watchdog: verify device readiness, install the timeout, start the watchdog hardware, and enable periodic feeding.

Parameters
configpointer to watchdog configuration storage (wdt device and params)
datapointer to watchdog runtime data storage (channel id, workqueue, etc.)
Returns
0 on success or a negative errno on failure.

Definition at line 223 of file watchdog_app.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watchdog_feed_enable()

static int watchdog_feed_enable ( const struct wdt_config_storage * config,
struct wdt_data_storage * data )
static

Enable periodic feeding of the hardware watchdog.

Parameters
configPointer to the stored watchdog configuration (must not be NULL).
dataPointer to runtime watchdog data (must not be NULL).

This function initializes a delayed work item which will periodically call primary_feed_worker to feed the watchdog and schedules the first invocation. It also performs an immediate feed to ensure the watchdog does not expire while setup completes and notifies interested subsystems about the feed event.

Returns
0 on success, or a negative errno on failure.

Definition at line 182 of file watchdog_app.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watchdog_init_and_start()

int watchdog_init_and_start ( void )

Initialize and start the watchdog timer.

Initialize and start application watchdog module.

Returns
0 on success, or a negative error code on failure.

Definition at line 258 of file watchdog_app.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watchdog_notify_event()

static void watchdog_notify_event ( const struct watchdog_evt * evt)
static

Notify the registered watchdog event handler of an event.

Parameters
evtPointer to the watchdog event data.

Definition at line 59 of file watchdog_app.c.

Here is the caller graph for this function:

◆ watchdog_register_handler()

void watchdog_register_handler ( watchdog_evt_handler_t evt_handler)

Register handler to receive watchdog callback events.

Note
The library only allows for one event handler to be registered at a time. A passed in event handler in this function will overwrite the previously set event handler.
Parameters
evt_handlerEvent handler. Handler is de-registered if parameter is NULL.

Definition at line 291 of file watchdog_app.c.

Here is the call graph for this function:

◆ watchdog_start()

static int watchdog_start ( const struct wdt_config_storage * config)
static

Starts the watchdog timer hardware instance.

Parameters
configPointer to watchdog configuration storage.
Returns
0 on success, or a negative errno on failure.

Definition at line 151 of file watchdog_app.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ watchdog_timeout_install()

static int watchdog_timeout_install ( const struct wdt_config_storage * config,
struct wdt_data_storage * data )
static

Installs a watchdog timeout configuration and registers it with the WDT device.

Parameters
configPointer to the watchdog configuration storage containing the WDT device.
dataPointer to the watchdog data storage where the channel ID will be stored.
Returns
0 on success, -EFAULT if timeout installation fails.

Definition at line 116 of file watchdog_app.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ app_evt_handler

watchdog_evt_handler_t app_evt_handler
static

Registered application event handler.

Definition at line 48 of file watchdog_app.c.

◆ init_and_start

bool init_and_start
static

Flag set when the library has been initialized and started. *‍/.

Definition at line 50 of file watchdog_app.c.

◆ wdt_config

const struct wdt_config_storage wdt_config
static
Initial value:
= {
.wdt = DEVICE_DT_GET(DT_NODELABEL(wdt)),
}

Watchdog device configuration storage.

Definition at line 68 of file watchdog_app.c.

◆ wdt_data

struct wdt_data_storage wdt_data
static

Definition at line 72 of file watchdog_app.c.