Skip to content

Commit

Permalink
Review millisDiff
Browse files Browse the repository at this point in the history
Found out here, Libelium/waspmoteapi#15 that
this could be much more simple.

If I have not removed the function enterily it's because it would take
more program memory, something I want to avoid now (we run out of
program memory). That's why the function is declared noinline.
  • Loading branch information
jdavid committed Sep 13, 2017
1 parent 78d90a8 commit 5b95eb5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 5 additions & 6 deletions libraries/Coroutines/Coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,15 @@ char* strnjoin_F(char* dst, size_t size, const __FlashStringHelper* delimiter, c
/*
* Functions to calculate the distance between two calls to millis(), taking
* into account overflow.
*
* XXX We could just remove this function and use millis() - t0 everywhere, but
* it would use more program memory, which we want to avoid, at least for now.
* That's why we declare the function noinline in the header file.
*/

uint32_t Loop::millisDiff(uint32_t t0, uint32_t t1)
{
return (t1 >= t0) ? t1 - t0: (ULONG_MAX - t0) + t1;
}

uint32_t Loop::millisDiff(uint32_t t0)
{
return millisDiff(t0, millis());
return millis() - t0;
}

/*
Expand Down
3 changes: 1 addition & 2 deletions libraries/Coroutines/Coroutines.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ class Loop
// millisDiff is to calculate the difference between two calls to millis(),
// but taking into account overflow. This is only needed if the device runs
// without sleep for longer than 49 days.
uint32_t millisDiff(uint32_t t0, uint32_t t1);
uint32_t millisDiff(uint32_t t0);
uint32_t millisDiff(uint32_t t0) __attribute__((noinline));

// Printing to USB done right. The print functions takes a formatted
// string, either a regular string (char*) or one stored in the program
Expand Down

0 comments on commit 5b95eb5

Please sign in to comment.