Skip to content

Commit a20385c

Browse files
author
Alexander Preißner
committed
feat: WDT: added WDT demo application
* Modified SoC init function configures COP WDT to time out after 8192ms if CONFIG_WATCHDOG is set. * A demo application shows how the WDT must be reloaded in order not to time out. * Closes zephyrproject-rtos#15
1 parent ef1190f commit a20385c

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed

arch/arm/soc/nxp_kinetis/kwx/soc_kw4xz.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,13 @@ static int kwx_init(struct device *arg)
112112
/* disable interrupts */
113113
oldLevel = irq_lock();
114114

115-
/* Disable the watchdog */
115+
/* Configure or disable the watchdog */
116+
#if defined(CONFIG_WATCHDOG)
117+
/* 1kHz LPC clock, 2^13 cycles = 8192ms */
118+
SIM->COPC = SIM_COPC_COPCLKSEL(00) | SIM_COPC_COPCLKS(1) | SIM_COPC_COPT(01);
119+
#else
116120
SIM->COPC = 0;
121+
#endif
117122

118123
/* Initialize system clock to 40 MHz */
119124
clkInit();

samples/watchdog/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
3+
project(NONE)
4+
5+
target_sources(app PRIVATE src/main.c)
6+
target_sources(app PRIVATE $ENV{ZEPHYR_BASE}/ext/hal/nxp/mcux/drivers/fsl_vref.c)

samples/watchdog/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
CONFIG_WATCHDOG=y

samples/watchdog/sample.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sample:
2+
description: Hello World sample, the simplest Zephyr
3+
application
4+
name: hello world
5+
platforms: all
6+
common:
7+
tags: samples
8+
harness: console
9+
harness_config:
10+
type: one_line
11+
regex:
12+
- "Hello World! (.*)"
13+
tests:
14+
singlethread:
15+
extra_args: CONF_FILE=prj_single.conf
16+
filter: not CONFIG_BT and not CONFIG_GPIO_SCH and ASSERT == 0
17+
test:
18+
tags: samples

samples/watchdog/src/main.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2018 blik GmbH
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file main.c
9+
*
10+
* @copyright 2018 blik GmbH
11+
*
12+
* @author Alexander Preißner <[email protected]>
13+
*
14+
* This is a sample application that demonstrates how to use the KW41Z
15+
* Watchdog Timer.
16+
*/
17+
18+
/*----------------------------------------------------------------------------*/
19+
/* HEADERS */
20+
/*----------------------------------------------------------------------------*/
21+
22+
#include <zephyr.h>
23+
24+
#include <misc/printk.h>
25+
26+
#include <fsl_common.h>
27+
#include <misc/util.h>
28+
29+
30+
/*----------------------------------------------------------------------------*/
31+
/* MACROS */
32+
/*----------------------------------------------------------------------------*/
33+
34+
/**
35+
* @brief Watchdog Timer reload sequence
36+
*
37+
* The exact sequence 0x55 and 0xAA MUST be written to the SRVCOP register
38+
* in order to reload the Watchdog Timer.
39+
*/
40+
#if defined(CONFIG_WATCHDOG)
41+
#define WDT_RELOAD() SIM->SRVCOP = SIM_SRVCOP_SRVCOP(0x55); \
42+
SIM->SRVCOP = SIM_SRVCOP_SRVCOP(0xAA)
43+
#else
44+
#define WDT_RELOAD()
45+
#endif
46+
47+
/**
48+
* @brief Switch defining whether watchdog timer is reloaded or not in this
49+
* sample.
50+
*
51+
* If this variable is '0' "Hello blik!" should be printed to STDOUT every
52+
* 8.192 seconds.
53+
*/
54+
#define RELOAD_WATCHDOG 0
55+
56+
57+
/**
58+
* @brief Function for Main thread
59+
*/
60+
void main(void) {
61+
// Print what this sample is about
62+
printk("Hello blik!\n");
63+
64+
while(RELOAD_WATCHDOG)
65+
{
66+
WDT_RELOAD();
67+
68+
k_sleep(1000);
69+
}
70+
71+
return;
72+
}

0 commit comments

Comments
 (0)