samples: drivers: watchdog: Handle watchdog event
Also modified to timeout to 1000ms in order to support watchdogs like WWDG with smaller timeouts. Signed-off-by: Ioannis Konstantelias <ikonstadel@gmail.com>
This commit is contained in:
parent
4bda345685
commit
e8b0f5644f
3 changed files with 46 additions and 9 deletions
11
samples/drivers/watchdog/nucleo_l496zg.conf
Normal file
11
samples/drivers/watchdog/nucleo_l496zg.conf
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# 2MHz system clock
|
||||||
|
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=2000000
|
||||||
|
|
||||||
|
# SYSCLK selection
|
||||||
|
CONFIG_CLOCK_STM32_SYSCLK_SRC_MSI=y
|
||||||
|
# produce 2MHz clock at MSI RC output
|
||||||
|
CONFIG_CLOCK_STM32_MSI_RANGE=5
|
||||||
|
# select buses prescalers
|
||||||
|
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
|
||||||
|
CONFIG_CLOCK_STM32_APB1_PRESCALER=1
|
||||||
|
CONFIG_CLOCK_STM32_APB2_PRESCALER=1
|
|
@ -13,3 +13,18 @@ tests:
|
||||||
- "Waiting for reset..."
|
- "Waiting for reset..."
|
||||||
- "Watchdog sample application"
|
- "Watchdog sample application"
|
||||||
depends_on: watchdog
|
depends_on: watchdog
|
||||||
|
platform_exclude: nucleo_l496zg nucleo_f401re
|
||||||
|
sample.driver.window_watchdog_nucleo_l496zg:
|
||||||
|
tags: drivers
|
||||||
|
harness: console
|
||||||
|
harness_config:
|
||||||
|
type: multi_line
|
||||||
|
ordered: true
|
||||||
|
regex:
|
||||||
|
- "Watchdog sample application"
|
||||||
|
- "Feeding watchdog..."
|
||||||
|
- "Waiting for reset..."
|
||||||
|
- "Watchdog sample application"
|
||||||
|
depends_on: watchdog
|
||||||
|
platform_whitelist: nucleo_l496zg
|
||||||
|
extra_args: CONF_FILE="prj.conf;nucleo_l496zg.conf"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015 Intel Corporation
|
* Copyright (c) 2015 Intel Corporation
|
||||||
* Copyright (c) 2018 Nordic Semiconductor
|
* Copyright (c) 2018 Nordic Semiconductor
|
||||||
|
* Copyright (c) 2019 Centaur Analytics, Inc
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -9,6 +10,7 @@
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <drivers/watchdog.h>
|
#include <drivers/watchdog.h>
|
||||||
#include <sys/printk.h>
|
#include <sys/printk.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define WDT_FEED_TRIES 5
|
#define WDT_FEED_TRIES 5
|
||||||
|
|
||||||
|
@ -16,16 +18,25 @@
|
||||||
#ifdef CONFIG_WDT_0_NAME
|
#ifdef CONFIG_WDT_0_NAME
|
||||||
#define WDT_DEV_NAME CONFIG_WDT_0_NAME
|
#define WDT_DEV_NAME CONFIG_WDT_0_NAME
|
||||||
#else
|
#else
|
||||||
|
#ifdef CONFIG_WWDG_STM32
|
||||||
|
#define WDT_DEV_NAME DT_WWDT_0_NAME
|
||||||
|
#else
|
||||||
#define WDT_DEV_NAME DT_WDT_0_NAME
|
#define WDT_DEV_NAME DT_WDT_0_NAME
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static void wdt_callback(struct device *wdt_dev, int channel_id)
|
static void wdt_callback(struct device *wdt_dev, int channel_id)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(wdt_dev);
|
static bool handled_event;
|
||||||
ARG_UNUSED(channel_id);
|
|
||||||
/* Watchdog timer expired. Handle it here.
|
if (handled_event) {
|
||||||
* Remember that SoC reset will be done soon.
|
return;
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
wdt_feed(wdt_dev, channel_id);
|
||||||
|
|
||||||
|
printk("Handled things..ready to reset\n");
|
||||||
|
handled_event = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
|
@ -46,9 +57,9 @@ void main(void)
|
||||||
/* Reset SoC when watchdog timer expires. */
|
/* Reset SoC when watchdog timer expires. */
|
||||||
wdt_config.flags = WDT_FLAG_RESET_SOC;
|
wdt_config.flags = WDT_FLAG_RESET_SOC;
|
||||||
|
|
||||||
/* Expire watchdog after 5000 milliseconds. */
|
/* Expire watchdog after 1000 milliseconds. */
|
||||||
wdt_config.window.min = 0U;
|
wdt_config.window.min = 0U;
|
||||||
wdt_config.window.max = 5000U;
|
wdt_config.window.max = 1000U;
|
||||||
|
|
||||||
/* Set up watchdog callback. Jump into it when watchdog expired. */
|
/* Set up watchdog callback. Jump into it when watchdog expired. */
|
||||||
wdt_config.callback = wdt_callback;
|
wdt_config.callback = wdt_callback;
|
||||||
|
@ -75,12 +86,12 @@ void main(void)
|
||||||
for (int i = 0; i < WDT_FEED_TRIES; ++i) {
|
for (int i = 0; i < WDT_FEED_TRIES; ++i) {
|
||||||
printk("Feeding watchdog...\n");
|
printk("Feeding watchdog...\n");
|
||||||
wdt_feed(wdt, wdt_channel_id);
|
wdt_feed(wdt, wdt_channel_id);
|
||||||
k_sleep(1000);
|
k_sleep(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Waiting for the SoC reset. */
|
/* Waiting for the SoC reset. */
|
||||||
printk("Waiting for reset...\n");
|
printk("Waiting for reset...\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
k_yield();
|
k_yield();
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue