Skip to content

Commit

Permalink
Merge pull request #1 from dcorbeil/sleepms_uses_nanosleep
Browse files Browse the repository at this point in the history
Changed Zephyr's `z_sleep_ms` to allow for sleeps longer than 1 second
  • Loading branch information
cguimaraes authored Feb 2, 2023
2 parents 53baf73 + 751f3a3 commit 068df47
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/system/zephyr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wa
int z_sleep_us(unsigned int time) { return usleep(time); }

int z_sleep_ms(unsigned int time) {
for (unsigned int i = 0; i < time; i++) {
z_sleep_us(1000);
}
struct timespec ts;
ts.tv_sec = time / 1000ll;
ts.tv_nsec = (time - (ts.tv_sec * 1000)) * 1000 * 1000;

return nanosleep(&ts, NULL);

return 0;
}
Expand Down

0 comments on commit 068df47

Please sign in to comment.