Skip to content

Commit 8230f2c

Browse files
slaffd-a-v
authored andcommitted
Changed the delay function to call wdt_reset for intervals that are bigger than the max-safe-delay period. (#1154)
1 parent 20854f8 commit 8230f2c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Sming/SmingCore/Clock.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "../SmingCore/Clock.h"
99
#include "../Wiring/WiringFrameworkIncludes.h"
1010

11+
#define MAX_SAFE_DELAY 1000
12+
1113
unsigned long millis(void)
1214
{
1315
return system_get_time() / 1000UL;
@@ -20,7 +22,18 @@ unsigned long micros(void)
2022

2123
void delay(uint32_t time)
2224
{
23-
os_delay_us(time * 1000);
25+
int quotient = time / MAX_SAFE_DELAY;
26+
int remainder = time % MAX_SAFE_DELAY;
27+
for(int i=0, max = quotient + 1; i < max ; i++) {
28+
if(i == quotient) {
29+
os_delay_us(remainder * 1000);
30+
}
31+
else {
32+
os_delay_us(MAX_SAFE_DELAY * 1000);
33+
}
34+
35+
system_soft_wdt_feed ();
36+
}
2437
}
2538

2639
void delayMicroseconds(uint32_t time)

0 commit comments

Comments
 (0)