Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wiring.c #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions cores/arduino/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,13 @@ unsigned long micros() {

void delay(unsigned long ms)
{
uint32_t start_time = micros(), delay_time = 1000*ms;
uint32_t start_time = micros();

/* Calculate future time to return */
uint32_t return_time = start_time + delay_time;

/* If return time overflows */
if(return_time < delay_time){
/* Wait until micros overflows */
while(micros() > return_time);
while (ms > 0) {
while (micros() - start_time < 1000) yield();
--ms;
start_time += 1000;
}

/* Wait until return time */
while(micros() < return_time);
}

/* Delay for the given number of microseconds. Assumes a 1, 8, 12, 16, 20 or 24 MHz clock. */
Expand Down Expand Up @@ -407,4 +401,4 @@ void init()
sei();
}

void setup_timers(void) __attribute__((weak));
void setup_timers(void) __attribute__((weak));