Skip to content

Commit 83987a0

Browse files
committed
Merge branch 'feat-watchdog' into 'dev'
feat: WDT: added WDT demo application Closes zephyrproject-rtos#15 See merge request blik/embedded/zephyr!25
2 parents ef1190f + 085100a commit 83987a0

File tree

7 files changed

+152
-1
lines changed

7 files changed

+152
-1
lines changed

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,32 @@ 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+
#if defined(CONFIG_WDT_MKW4XZ_32MS)
118+
/* 1kHz LPC clock, 2^5 cycles = 32ms */
119+
SIM->COPC = SIM_COPC_COPCLKSEL(00) | SIM_COPC_COPCLKS(0) | SIM_COPC_COPT(01);
120+
#elif defined(CONFIG_WDT_MKW4XZ_256MS)
121+
/* 1kHz LPC clock, 2^8 cycles = 256ms */
122+
SIM->COPC = SIM_COPC_COPCLKSEL(00) | SIM_COPC_COPCLKS(0) | SIM_COPC_COPT(10);
123+
#elif defined(CONFIG_WDT_MKW4XZ_1024MS)
124+
/* 1kHz LPC clock, 2^10 cycles = 1024ms */
125+
SIM->COPC = SIM_COPC_COPCLKSEL(00) | SIM_COPC_COPCLKS(0) | SIM_COPC_COPT(11);
126+
#elif defined(CONFIG_WDT_MKW4XZ_8192MS)
127+
/* 1kHz LPC clock, 2^13 cycles = 8192ms */
128+
SIM->COPC = SIM_COPC_COPCLKSEL(00) | SIM_COPC_COPCLKS(1) | SIM_COPC_COPT(01);
129+
#elif defined(CONFIG_WDT_MKW4XZ_65536MS)
130+
/* 1kHz LPC clock, 2^16 cycles = 65536ms */
131+
SIM->COPC = SIM_COPC_COPCLKSEL(00) | SIM_COPC_COPCLKS(1) | SIM_COPC_COPT(10);
132+
#elif defined(CONFIG_WDT_MKW4XZ_262144MS)
133+
/* 1kHz LPC clock, 2^18 cycles = 262144ms */
134+
SIM->COPC = SIM_COPC_COPCLKSEL(00) | SIM_COPC_COPCLKS(1) | SIM_COPC_COPT(11);
135+
#else
136+
#error "Unknown Watchdog Timer timeout period"
137+
#endif
138+
#else
116139
SIM->COPC = 0;
140+
#endif
117141

118142
/* Initialize system clock to 40 MHz */
119143
clkInit();

drivers/watchdog/Kconfig

+2
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ source "drivers/watchdog/Kconfig.esp32"
3030

3131
source "drivers/watchdog/Kconfig.sam0"
3232

33+
source "drivers/watchdog/Kconfig.mkwx"
34+
3335
endif

drivers/watchdog/Kconfig.mkwx

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Kconfig - NXP Kinetis KWx WDT configuration
2+
#
3+
# Copyright (c) 2018 blik GmbH
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
choice WDT_MKW4XZ
7+
bool
8+
depends on SOC_PART_NUMBER_MKW41Z512VHT4
9+
prompt "MKW41Z Watchdog Timer Timeout Setting"
10+
config WDT_MKW4XZ_32MS
11+
bool "32 ms"
12+
config WDT_MKW4XZ_256MS
13+
bool "256 ms"
14+
config WDT_MKW4XZ_1024MS
15+
bool "1024 ms"
16+
config WDT_MKW4XZ_8192MS
17+
bool "8192 ms"
18+
config WDT_MKW4XZ_65536MS
19+
bool "65536 ms"
20+
config WDT_MKW4XZ_262144MS
21+
bool "262144 ms"
22+
help
23+
The Kinetis MKW4xZ Watchdog Timer can be configured once at power-up.
24+
The timeout period must therefore be pre-selected here.
25+
endchoice

samples/watchdog/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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)

samples/watchdog/prj.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
CONFIG_WATCHDOG=y
3+
CONFIG_WDT_MKW4XZ_8192MS=y

samples/watchdog/sample.yaml

+18
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

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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() do { \
42+
SIM->SRVCOP = SIM_SRVCOP_SRVCOP(0x55); \
43+
SIM->SRVCOP = SIM_SRVCOP_SRVCOP(0xAA); \
44+
} while(0)
45+
#else
46+
#define WDT_RELOAD()
47+
#endif
48+
49+
/**
50+
* @brief Switch defining whether watchdog timer is reloaded or not in this
51+
* sample.
52+
*
53+
* If this variable is '0' "Hello blik!" should be printed to STDOUT every
54+
* 8.192 seconds.
55+
*/
56+
#define RELOAD_WATCHDOG 0
57+
58+
59+
/**
60+
* @brief Function for Main thread
61+
*/
62+
void main(void) {
63+
// Print what this sample is about
64+
printk("Hello blik!\n");
65+
66+
while(RELOAD_WATCHDOG)
67+
{
68+
WDT_RELOAD();
69+
70+
k_sleep(1000);
71+
}
72+
73+
return;
74+
}

0 commit comments

Comments
 (0)