Using nPM1300 Watchdog
This application note describes how to configure nPM1300 Watchdog in Zephyr BSP and use it in the user application.
The nPM1300 Watchdog device is declared in nrf9151som_nrf9151_ns.dts as a child node of the npm1300_pmic device:
npm1300_pmic: pmic@6b {
compatible = "nordic,npm1300";
...
npm1300_wdt: npm1300_wdt {
compatible = "nordic,npm1300-wdt";
};
...
};The devicetree node configures the following parameters:
Parameter | Value | Description |
|---|---|---|
|
| Enables the |
The Customized Asset Tracker v2 application implements the following C-binding helper API for nPM1300 watchdog, defined in watchdog_app.* files:
Function | Description | Comments |
| Initialize and start application watchdog module. | Returns zero on success, otherwise a negative error code is returned. |
| Register handler to receive watchdog callback events. |
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. |
| Stop watchdog feed. |
Calling this function will cause power cycle when the nPM1300 WDT timeout expires. |
The Customized Asset Tracker v2 application implements several static functions, which are used by the watchdog workqueue thread:
Function | Description | Comments |
| This function is being called by SYS_INIT at Zephyr boot to initialize the watchdog thread. | Returns zero on success, otherwise a negative error code is returned. |
| System workqueue handler, used to disable the nPM1300 watchdog. |
|
| System workqueue handler, used to enable the nPM1300 watchdog. |
|
| System workqueue handler, used to feed the nPM1300 watchdog. |
Calls |
| Configure and start nPM1300 watchdog. | Calls |
| Disable the watchdog. | Calls |
| Start the watchdog. | Calls |
| Configure the watchdog timeout. | Calls |
The static functions are defined in watchdog_app.c file and make use of the Zephyr watchdog driver API.
The Customized Asset Tracker v2 application implements a separate workqueue thread for nPM1300 operations, which prevents other threads from interfering with the watchdog initialization sequence and feed cycle. The watchdog workqueue thread operates in the following sequence:
SYS_INIT()initializes the watchdog workqueue thread by callingwatchdog_init_and_start()at Zephyr boot.The watchdog workqueue thread calls
watchdog_enable_worker(), which calls configures and starts the watchdog by callingwatchdog_timeout_install()andwatchdog_start(). Watchdog timeout is specified by theCONFIG_WATCHDOG_APPLICATION_TIMEOUT_MSconfiguration parameter.After initializing the watchdog, the workqueue thread periodically calls
watchdog_feed_worker().When
watchdog_stop_feed()is called, the watchdog thread stops callingwatchdog_feed_worker(), which in turn causes board reset performed by the nPM1300 PMIC.
The Customized Asset Tracker v2 application provides a set of Zephyr shell commands for nPM1300 watchdog, defined in the watchdog_app.c file:
Command | Comments |
| Enable the watchdog. |
| Disable the watchdog. |
| Prints watchdog status in the following format: uart:~$ watchdog status
Watchdog status: <enabled|disabled>
Watchdog stop requested: <yes|no>
Watchdog feed period: <feed period> ms
Watchdog timeout: <timeout> ms
|
| Stop feeding the watchdog. Calling this command will cause watchdog reset when the watchdog timeout expires. |