From 2e7b6455715a5af1014366ea7b5678d382e6c5f1 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 14 Dec 2013 00:31:45 +0100 Subject: [PATCH] [sam] Fixed wrap-around bug in delay() (Mark Tillotson) Fixes #1736 --- build/shared/revisions.txt | 3 +++ hardware/arduino/sam/cores/arduino/wiring.c | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 6fd5eeec4..e0fdfc972 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -8,6 +8,9 @@ ARDUINO 1.5.6 BETA * TFT: warning messages in PImage class and strings inside examples now stored in flash to save RAM. * Ethernet: added operator == for EthernetClient class (Norbert Truchsess) +[core] +* sam: Fixed wrap-around bug in delay() (Mark Tillotson) + ARDUINO 1.5.5 BETA 2013.11.28 NOTICE: diff --git a/hardware/arduino/sam/cores/arduino/wiring.c b/hardware/arduino/sam/cores/arduino/wiring.c index 02fd04aac..f508f7c6b 100644 --- a/hardware/arduino/sam/cores/arduino/wiring.c +++ b/hardware/arduino/sam/cores/arduino/wiring.c @@ -25,7 +25,7 @@ extern "C" { uint32_t millis( void ) { // todo: ensure no interrupts - return GetTickCount() ; + return GetTickCount() ; } // Interrupt-compatible version of micros @@ -74,9 +74,12 @@ uint32_t micros( void ) void delay( uint32_t ms ) { - uint32_t end = GetTickCount() + ms; - while (GetTickCount() < end) - yield(); + if (ms == 0) + return; + uint32_t start = GetTickCount(); + do { + yield(); + } while (GetTickCount() - start < ms); } #if defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */