Skip to content

Commit c848f14

Browse files
committed
use watchdog support in arduino headers
1 parent 78d7c8e commit c848f14

File tree

2 files changed

+14
-50
lines changed

2 files changed

+14
-50
lines changed

arduino

netboot.c

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <arduino/pins.h>
2323
#include <arduino/spi.h>
24+
#include <arduino/wdt.h>
2425

2526
#include "boot.h"
2627
#include "w5100.h"
@@ -108,48 +109,11 @@ mymemset(uint8_t *dst, uint8_t c, uint16_t len)
108109
*dst++ = c;
109110
}
110111

111-
static inline void
112-
watchdog_reset(void)
113-
{
114-
__asm__ __volatile__ ("wdr\n");
115-
}
116-
117-
static inline void
118-
watchdog_config(uint8_t v)
119-
{
120-
WDTCSR = _BV(WDCE) | _BV(WDE);
121-
WDTCSR = v;
122-
}
123-
124-
static inline void
125-
watchdog_noreset_500ms(void)
126-
{
127-
watchdog_config(_BV(WDIE) | _BV(WDP2) | _BV(WDP0));
128-
}
129-
130-
static inline void
131-
watchdog_off(void)
132-
{
133-
watchdog_config(0x00);
134-
}
135-
136-
static inline uint8_t
137-
watchdog_interrupt_flag(void)
138-
{
139-
return WDTCSR & _BV(WDIF);
140-
}
141-
142-
static inline void
143-
watchdog_interrupt_flag_clear(void)
144-
{
145-
WDTCSR |= _BV(WDIF);
146-
}
147-
148112
static void
149-
watchdog_wait(void)
113+
wdt_wait(void)
150114
{
151-
while(!watchdog_interrupt_flag());
152-
watchdog_interrupt_flag_clear();
115+
while(!wdt_interrupt_flag());
116+
wdt_interrupt_flag_clear();
153117
}
154118

155119
static void
@@ -262,8 +226,8 @@ static inline void debug_init(void) {}
262226
static inline int __attribute__((noreturn))
263227
exit_bootloader(void)
264228
{
265-
watchdog_reset();
266-
watchdog_off();
229+
wdt_reset();
230+
wdt_off();
267231
__asm__ __volatile__ ("jmp 0\n");
268232
__builtin_unreachable();
269233
}
@@ -318,7 +282,7 @@ exit_bootloader(void)
318282
printd("EXIT\r\n");
319283
while (1) {
320284
pin_toggle(LED);
321-
watchdog_wait();
285+
wdt_wait();
322286
}
323287
}
324288

@@ -433,16 +397,16 @@ eb_send(uint8_t (*check)(void))
433397
sock0_sendpacket();
434398

435399
i = next;
436-
watchdog_reset();
400+
wdt_reset();
437401
do {
438402
if (wiz_get_word(WIZ_Sn_RX_RSR(0)) > 0) {
439403
sock0_readpacket();
440404
if (check())
441405
return 0;
442406
}
443407

444-
if (watchdog_interrupt_flag()) {
445-
watchdog_interrupt_flag_clear();
408+
if (wdt_interrupt_flag()) {
409+
wdt_interrupt_flag_clear();
446410
printd(".");
447411
i--;
448412
}
@@ -672,8 +636,8 @@ int
672636
main(void)
673637
{
674638
MCUSR = 0; /* we don't care why the chip was reset */
675-
watchdog_reset();
676-
watchdog_noreset_500ms();
639+
wdt_reset();
640+
wdt_timer_500ms();
677641

678642
debug_init();
679643

@@ -697,7 +661,7 @@ main(void)
697661
wiz_set(WIZ_MR, 0x80);
698662

699663
/* wait for it to initialize */
700-
watchdog_wait();
664+
wdt_wait();
701665
printd("\r\n");
702666

703667
/* set MAC address */

0 commit comments

Comments
 (0)