Skip to content

Commit bff42ea

Browse files
committed
add watchdog module
Add support for the windowed watchdog. Signed-off-by: Michael Walle <[email protected]>
1 parent 647d550 commit bff42ea

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LDFLAGS = -T linker.ld -mcpu=cortex-m0plus -mlittle-endian -g -nostdlib -mthumb
1818
LIBS += -lgcc
1919

2020
OBJECTS = startup.o main.o miniprintf.o uart.o systick.o adc.o vref.o misc.o
21-
OBJECTS += iomux.o sysctl.o gpio.o cp.o i2c.o nvic.o nvm.o config.o
21+
OBJECTS += iomux.o sysctl.o gpio.o cp.o i2c.o nvic.o nvm.o config.o wdt.o
2222

2323
DEPS := $(shell find -name '*.d')
2424

wdt.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: BSD-2-Clause
2+
/*
3+
* Copyright (c) 2025 Kontron Europe GmbH
4+
*/
5+
6+
#include "misc.h"
7+
#include "wdt.h"
8+
9+
#define WWDT_BASE 0x40080000
10+
11+
#define WWDT_PWREN (WWDT_BASE + 0x0800)
12+
#define PWREN_KEY 0x26000000
13+
#define PWREN_ENABLE BIT(0)
14+
15+
#define WWDT_WWDTCTL0 (WWDT_BASE + 0x1100)
16+
#define WWDTCTL0_KEY 0xc9000000
17+
#define WWDTCTL0_CLKDIV(n) ((n) << 0)
18+
#define WWDTCTL0_PER(n) ((n) << 4)
19+
20+
#define WWDT_WWDTCNTRST (WWDT_BASE + 0x1108)
21+
#define WWDTCNTRST_RESTART 0xa7
22+
23+
void wdt_init(void)
24+
{
25+
iow(WWDT_PWREN, PWREN_KEY | PWREN_ENABLE);
26+
27+
/* set watchdog timeout to 1s */
28+
iow(WWDT_WWDTCTL0, WWDTCTL0_KEY | WWDTCTL0_CLKDIV(0) | WWDTCTL0_PER(3));
29+
}
30+
31+
void wdt_kick(void)
32+
{
33+
iow(WWDT_WWDTCNTRST, WWDTCNTRST_RESTART);
34+
}

wdt.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: BSD-2-Clause
2+
/*
3+
* Copyright (c) 2025 Kontron Europe GmbH
4+
*/
5+
6+
#ifndef __WDT_H
7+
#define __WDT_H
8+
9+
void wdt_init(void);
10+
void wdt_kick(void);
11+
12+
#endif /* __WDT_H */

0 commit comments

Comments
 (0)