Skip to content

Commit 9be7c15

Browse files
committed
[sam] Fixed wrap-around bug in delay() (Mark Tillotson)
Fixes arduino#1736
1 parent 202e0e6 commit 9be7c15

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cores/arduino/wiring.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" {
2525
uint32_t millis( void )
2626
{
2727
// todo: ensure no interrupts
28-
return GetTickCount() ;
28+
return GetTickCount() ;
2929
}
3030

3131
// Interrupt-compatible version of micros
@@ -74,9 +74,12 @@ uint32_t micros( void )
7474

7575
void delay( uint32_t ms )
7676
{
77-
uint32_t end = GetTickCount() + ms;
78-
while (GetTickCount() < end)
79-
yield();
77+
if (ms == 0)
78+
return;
79+
uint32_t start = GetTickCount();
80+
do {
81+
yield();
82+
} while (GetTickCount() - start < ms);
8083
}
8184

8285
#if defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */

0 commit comments

Comments
 (0)