Skip to content

Commit db1b2f7

Browse files
nordic-seglnordic-piks
authored andcommitted
tests: drivers: watchdog: wdt_soft_reset: Move common code
HW Info related code can be reused by other WDT test. Move common code to common/hw_info_helper.c Signed-off-by: Sebastian Głąb <[email protected]>
1 parent 4600f1d commit db1b2f7

File tree

4 files changed

+245
-208
lines changed

4 files changed

+245
-208
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/drivers/hwinfo.h>
9+
#include "hw_info_helper.h"
10+
11+
#include <zephyr/logging/log.h>
12+
LOG_MODULE_REGISTER(hw_info_helper, LOG_LEVEL_INF);
13+
14+
/**
15+
* @brief Print LOG delimiter.
16+
*/
17+
void print_bar(void)
18+
{
19+
LOG_INF("===================================================================");
20+
}
21+
22+
/**
23+
* @brief Get and print reset causes supported by the HW.
24+
*
25+
* @param supported Pointer to a variable that will be set with supported reset causes.
26+
*/
27+
void get_supported_reset_cause(uint32_t *supported)
28+
{
29+
int32_t ret;
30+
31+
ret = hwinfo_get_supported_reset_cause(supported);
32+
33+
if (ret == 0) {
34+
LOG_INF("Supported reset causes are:");
35+
if (*supported & RESET_PIN) {
36+
LOG_INF(" 0: RESET_PIN is supported");
37+
} else {
38+
LOG_INF(" 0: no support for RESET_PIN");
39+
}
40+
if (*supported & RESET_SOFTWARE) {
41+
LOG_INF(" 1: RESET_SOFTWARE is supported");
42+
} else {
43+
LOG_INF(" 1: no support for RESET_SOFTWARE");
44+
}
45+
if (*supported & RESET_BROWNOUT) {
46+
LOG_INF(" 2: RESET_BROWNOUT is supported");
47+
} else {
48+
LOG_INF(" 2: no support for RESET_BROWNOUT");
49+
}
50+
if (*supported & RESET_POR) {
51+
LOG_INF(" 3: RESET_POR is supported");
52+
} else {
53+
LOG_INF(" 3: no support for RESET_POR");
54+
}
55+
if (*supported & RESET_WATCHDOG) {
56+
LOG_INF(" 4: RESET_WATCHDOG is supported");
57+
} else {
58+
LOG_INF(" 4: no support for RESET_WATCHDOG");
59+
}
60+
if (*supported & RESET_DEBUG) {
61+
LOG_INF(" 5: RESET_DEBUG is supported");
62+
} else {
63+
LOG_INF(" 5: no support for RESET_DEBUG");
64+
}
65+
if (*supported & RESET_SECURITY) {
66+
LOG_INF(" 6: RESET_SECURITY is supported");
67+
} else {
68+
LOG_INF(" 6: no support for RESET_SECURITY");
69+
}
70+
if (*supported & RESET_LOW_POWER_WAKE) {
71+
LOG_INF(" 7: RESET_LOW_POWER_WAKE is supported");
72+
} else {
73+
LOG_INF(" 7: no support for RESET_LOW_POWER_WAKE");
74+
}
75+
if (*supported & RESET_CPU_LOCKUP) {
76+
LOG_INF(" 8: RESET_CPU_LOCKUP is supported");
77+
} else {
78+
LOG_INF(" 8: no support for RESET_CPU_LOCKUP");
79+
}
80+
if (*supported & RESET_PARITY) {
81+
LOG_INF(" 9: RESET_PARITY is supported");
82+
} else {
83+
LOG_INF(" 9: no support for RESET_PARITY");
84+
}
85+
if (*supported & RESET_PLL) {
86+
LOG_INF("10: RESET_PLL is supported");
87+
} else {
88+
LOG_INF("10: no support for RESET_PLL");
89+
}
90+
if (*supported & RESET_CLOCK) {
91+
LOG_INF("11: RESET_CLOCK is supported");
92+
} else {
93+
LOG_INF("11: no support for RESET_CLOCK");
94+
}
95+
if (*supported & RESET_HARDWARE) {
96+
LOG_INF("12: RESET_HARDWARE is supported");
97+
} else {
98+
LOG_INF("12: no support for RESET_HARDWARE");
99+
}
100+
if (*supported & RESET_USER) {
101+
LOG_INF("13: RESET_USER is supported");
102+
} else {
103+
LOG_INF("13: no support for RESET_USER");
104+
}
105+
if (*supported & RESET_TEMPERATURE) {
106+
LOG_INF("14: RESET_TEMPERATURE is supported");
107+
} else {
108+
LOG_INF("14: no support for RESET_TEMPERATURE");
109+
}
110+
if (*supported & RESET_BOOTLOADER) {
111+
LOG_INF("15: RESET_BOOTLOADER is supported");
112+
} else {
113+
LOG_INF("15: no support for RESET_BOOTLOADER");
114+
}
115+
if (*supported & RESET_FLASH) {
116+
LOG_INF("16: RESET_FLASH is supported");
117+
} else {
118+
LOG_INF("16: no support for RESET_FLASH");
119+
}
120+
} else if (ret == -ENOSYS) {
121+
LOG_INF("hwinfo_get_supported_reset_cause() is NOT supported");
122+
*supported = 0;
123+
} else {
124+
LOG_ERR("hwinfo_get_supported_reset_cause() failed (ret = %d)", ret);
125+
}
126+
print_bar();
127+
}
128+
129+
/**
130+
* @brief Get and print current value of reset cause.
131+
*
132+
* @param cause Pointer to a variable that will be set with current reset causes.
133+
*/
134+
void get_current_reset_cause(uint32_t *cause)
135+
{
136+
int32_t ret;
137+
138+
ret = hwinfo_get_reset_cause(cause);
139+
if (ret == 0) {
140+
LOG_INF("Current reset cause is:");
141+
if (*cause & RESET_PIN) {
142+
LOG_INF(" 0: reset due to RESET_PIN");
143+
}
144+
if (*cause & RESET_SOFTWARE) {
145+
LOG_INF(" 1: reset due to RESET_SOFTWARE");
146+
}
147+
if (*cause & RESET_BROWNOUT) {
148+
LOG_INF(" 2: reset due to RESET_BROWNOUT");
149+
}
150+
if (*cause & RESET_POR) {
151+
LOG_INF(" 3: reset due to RESET_POR");
152+
}
153+
if (*cause & RESET_WATCHDOG) {
154+
LOG_INF(" 4: reset due to RESET_WATCHDOG");
155+
}
156+
if (*cause & RESET_DEBUG) {
157+
LOG_INF(" 5: reset due to RESET_DEBUG");
158+
}
159+
if (*cause & RESET_SECURITY) {
160+
LOG_INF(" 6: reset due to RESET_SECURITY");
161+
}
162+
if (*cause & RESET_LOW_POWER_WAKE) {
163+
LOG_INF(" 7: reset due to RESET_LOW_POWER_WAKE");
164+
}
165+
if (*cause & RESET_CPU_LOCKUP) {
166+
LOG_INF(" 8: reset due to RESET_CPU_LOCKUP");
167+
}
168+
if (*cause & RESET_PARITY) {
169+
LOG_INF(" 9: reset due to RESET_PARITY");
170+
}
171+
if (*cause & RESET_PLL) {
172+
LOG_INF("10: reset due to RESET_PLL");
173+
}
174+
if (*cause & RESET_CLOCK) {
175+
LOG_INF("11: reset due to RESET_CLOCK");
176+
}
177+
if (*cause & RESET_HARDWARE) {
178+
LOG_INF("12: reset due to RESET_HARDWARE");
179+
}
180+
if (*cause & RESET_USER) {
181+
LOG_INF("13: reset due to RESET_USER");
182+
}
183+
if (*cause & RESET_TEMPERATURE) {
184+
LOG_INF("14: reset due to RESET_TEMPERATURE");
185+
}
186+
if (*cause & RESET_BOOTLOADER) {
187+
LOG_INF("15: reset due to RESET_BOOTLOADER");
188+
}
189+
if (*cause & RESET_FLASH) {
190+
LOG_INF("16: reset due to RESET_FLASH");
191+
}
192+
} else if (ret == -ENOSYS) {
193+
LOG_INF("hwinfo_get_reset_cause() is NOT supported");
194+
*cause = 0;
195+
} else {
196+
LOG_ERR("hwinfo_get_reset_cause() failed (ret = %d)", ret);
197+
}
198+
print_bar();
199+
}
200+
201+
/**
202+
* @brief Clear reset cause.
203+
*/
204+
void clear_reset_cause(void)
205+
{
206+
int32_t ret;
207+
208+
ret = hwinfo_clear_reset_cause();
209+
if (ret == 0) {
210+
LOG_INF("hwinfo_clear_reset_cause() was executed");
211+
} else if (ret == -ENOSYS) {
212+
LOG_INF("hwinfo_get_reset_cause() is NOT supported");
213+
} else {
214+
LOG_ERR("hwinfo_get_reset_cause() failed (ret = %d)", ret);
215+
}
216+
217+
/* Confirm all are cleared. */
218+
hwinfo_get_reset_cause(&ret);
219+
if (ret == 0) {
220+
LOG_INF("PASS: reset causes were cleared");
221+
} else {
222+
LOG_ERR("FAIL: reset case = %u while expected is 0", ret);
223+
}
224+
print_bar();
225+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
void print_bar(void);
8+
void get_supported_reset_cause(uint32_t *supported);
9+
void get_current_reset_cause(uint32_t *cause);
10+
void clear_reset_cause(void);

tests/drivers/watchdog/wdt_soft_reset/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ cmake_minimum_required(VERSION 3.20.0)
44
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
55
project(wdt_soft_reset)
66

7+
target_include_directories(app PRIVATE ../common/)
8+
target_sources(app PRIVATE ../common/hw_info_helper.c)
9+
710
FILE(GLOB app_sources src/*.c)
811
target_sources(app PRIVATE ${app_sources})

0 commit comments

Comments
 (0)