diff options
author | Ewout van Bekkum <ewout@google.com> | 2021-01-28 18:58:03 -0800 |
---|---|---|
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2021-01-30 01:48:08 +0000 |
commit | 830d5d1ac09c300b7c268f7768e7187a3f4de74e (patch) | |
tree | 3b8aaaa1c2eddfdda141d86ad261383c4c54a416 /pw_chrono_threadx | |
parent | cddc5cda875b2eea7dc3fbf0a2be0c1a9edd2b3a (diff) | |
download | pigweed-830d5d1ac09c300b7c268f7768e7187a3f4de74e.tar.gz |
pw_chrono: Improve SystemClock C API
Changes the SystemClock C Api to:
1) Use a pw_chrono_SystemClock_Duration struct instead of aliasing
an int64_t under pw_chrono_SystemClock_TickCount which could
accidentally permit direct tick usage.
2) Add PW_SYSTEM_CLOCK_{MS,S,MIN,H} and
PW_SYSTEM_CLOCK_{MS,S,MIN,H}_CEIL to permit C API users to
create durations which round up to the nearest tick for deadlines
and timeouts, mirroring std::chrono::ceil.
3) Add PW_SYSTEM_CLOCK_{MS,S,MIN,H}_FLOOR to permit C API users to
create durations which round down to the nearest tick for oddball
corner cases, mirroring std::chrono::floor.
4) In order to enable said macros, the system_clock_config.h backend
config was changed to require the clock period as a preprocessor
defines instead of a std::ratio<>.
5) Renames pw_chrono_SystemClock_TimeDelta to
pw_chrono_SystemClock_TimeElapsed to make the argument ordering
make more sense.
6) Changes existing std::chrono::duration_cast usage to
std::chrono::ceil and std::chrono:floor to set a good example
to be explicit on rounding.
7) Renames pw_chrono_SystemClock_TickCountsToNsTruncate accordingly to
pw_chrono_SystemClock_DurationToNsFloor.
Requires: pigweed-internal:9340
Change-Id: Ia628dceac53f964eda7c4aacd3d790b8b0e92207
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31280
Commit-Queue: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
Diffstat (limited to 'pw_chrono_threadx')
-rw-r--r-- | pw_chrono_threadx/public/pw_chrono_threadx/config.h | 9 | ||||
-rw-r--r-- | pw_chrono_threadx/public/pw_chrono_threadx/system_clock_config.h | 20 |
2 files changed, 18 insertions, 11 deletions
diff --git a/pw_chrono_threadx/public/pw_chrono_threadx/config.h b/pw_chrono_threadx/public/pw_chrono_threadx/config.h index a4681c5a2..bfb21098d 100644 --- a/pw_chrono_threadx/public/pw_chrono_threadx/config.h +++ b/pw_chrono_threadx/public/pw_chrono_threadx/config.h @@ -31,8 +31,10 @@ #define PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR 100 #endif // PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR -static_assert(PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR >= 1); -static_assert(PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR >= 1); +static_assert(PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR >= 1, + "the numerator must be positive and cannot be fractional"); +static_assert(PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR >= 1, + "the denominator must be positive and cannot be fractional"); // Because the SystemClock::now() implementation requires the user to invoke it // more than once per overflow period, the max timeout is set to ensure that @@ -43,4 +45,5 @@ static_assert(PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR >= 1); #endif // PW_CHRONO_THREADX_CFG_MAX_TIMEOUT static_assert((PW_CHRONO_THREADX_CFG_MAX_TIMEOUT > 0) && - (PW_CHRONO_THREADX_CFG_MAX_TIMEOUT <= (TX_WAIT_FOREVER - 1))); + (PW_CHRONO_THREADX_CFG_MAX_TIMEOUT <= (TX_WAIT_FOREVER - 1)), + "the timeout must be greater than 0 and less than the sentinel"); diff --git a/pw_chrono_threadx/public/pw_chrono_threadx/system_clock_config.h b/pw_chrono_threadx/public/pw_chrono_threadx/system_clock_config.h index 3e8a676ba..6ab829aa6 100644 --- a/pw_chrono_threadx/public/pw_chrono_threadx/system_clock_config.h +++ b/pw_chrono_threadx/public/pw_chrono_threadx/system_clock_config.h @@ -13,18 +13,20 @@ // the License. #pragma once -#include <ratio> - -#include "pw_chrono/epoch.h" #include "pw_chrono_threadx/config.h" -namespace pw::chrono::backend { - // ThreadX does not have an API to determine the tick rate/period, instead // require the user to specify this through the configuration. -using SystemClockPeriodSecondsRatio = - std::ratio<PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR, - PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR>; +#define PW_CHRONO_SYSTEM_CLOCK_PERIOD_SECONDS_NUMERATOR \ + PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR +#define PW_CHRONO_SYSTEM_CLOCK_PERIOD_SECONDS_DENOMINATOR \ + PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR + +#ifdef __cplusplus + +#include "pw_chrono/epoch.h" + +namespace pw::chrono::backend { // The ThreadX clock starts at zero during initialization, approximately the // time since boot. @@ -37,3 +39,5 @@ constexpr inline bool kSystemClockNmiSafe = false; constexpr inline bool kSystemClockFreeRunning = false; } // namespace pw::chrono::backend + +#endif // __cplusplus |