typus_fugit
typus_fugitprovides a comprehensive library ofDurationandInstantfor the handling of time in embedded systems, using compile-time types to represent values.
This library began as a fork of fugit, which is, in turn, a heavily inspired of std::chrono's Duration from C++ which does all it can at compile time.
The decision to fork was due to the desire to replace const-generics values represented in the type system. This provides:
- Specification of legal values within the type system
- Evaluation of values within the type system
- Erasure of machine representation of values until needed at execution time
Initial implementation uses typenum for type-level values and evaluation. There is an intent to migrate to type_eval when it's ready.
Aims
- Try to stay in sync with
fugit- If users wish to switch between the two, the process should be low-friction and relatively reliable
- If
fugitdecides to migrate to types instead of consts, the result should not look very different totypus_fugit
no_stdlibrary with goals of user-friendliness and performance first- Priority placed on type-level evaluation
- When type-level evaluation isn't available, use
const fnwhere the possible. - All timebase operations performed using type-level evaluation
- Support for both
u32andu64backing storage with efficient instruction lowering on MCUs- On Cortex-M3 and up: no soft-impls pulled in for both
u32andu64except when changing base onu64 - Comparisons on
u32andu64do not use division, only changing base with all constants calculated at compile time
- On Cortex-M3 and up: no soft-impls pulled in for both
- Selection of base happens at compile time, within the type-system.
- A common problem is that run time changing of base robs us of a lot of optimization opportunities, but since types are used here, bases are evaluated at compile time.