| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/RawTimeInterface.hpp | ||
| 3 | // \brief Os::RawTimeHandle and Os::RawTimeInterface definitions | ||
| 4 | // ====================================================================== | ||
| 5 | #ifndef OS_RAWTIMEINTERFACE_HPP_ | ||
| 6 | #define OS_RAWTIMEINTERFACE_HPP_ | ||
| 7 | |||
| 8 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 9 | #include <Fw/Time/TimeInterval.hpp> | ||
| 10 | #include <Fw/Types/Serializable.hpp> | ||
| 11 | #include <Os/Os.hpp> | ||
| 12 | #include "config/OsDelegateRawTime.hpp" | ||
| 13 | #include "config/RawTimeSource.hpp" | ||
| 14 | |||
| 15 | namespace Os { | ||
| 16 | |||
| 17 | struct RawTimeHandle {}; | ||
| 18 | |||
| 19 | class RawTimeInterface : public Fw::Serializable { | ||
| 20 | public: | ||
| 21 | // Serialization size for RawTime objects, configured in config/FpConfig.h | ||
| 22 | static const FwSizeType SERIALIZED_SIZE = FW_RAW_TIME_SERIALIZATION_MAX_SIZE; | ||
| 23 | |||
| 24 | enum Status { | ||
| 25 | OP_OK, //!< Operation was successful | ||
| 26 | OP_OVERFLOW, //!< Operation result caused an overflow | ||
| 27 | INVALID_PARAMS, //!< Parameters invalid for current platform | ||
| 28 | NOT_SUPPORTED, //!< RawTime does not support operation | ||
| 29 | OTHER_ERROR //!< All other errors | ||
| 30 | }; | ||
| 31 | |||
| 32 | //! \brief default constructor | ||
| 33 | 12 | RawTimeInterface() = default; | |
| 34 | |||
| 35 | //! \brief default virtual destructor | ||
| 36 | 24 | virtual ~RawTimeInterface() = default; | |
| 37 | |||
| 38 | //! \brief return the underlying RawTime handle (implementation specific) | ||
| 39 | //! \return internal RawTime handle representation | ||
| 40 | virtual RawTimeHandle* getHandle() = 0; | ||
| 41 | |||
| 42 | //! \brief provide a pointer to a RawTime delegate object | ||
| 43 | //! \param aligned_new_memory: aligned memory to fill | ||
| 44 | //! \param to_copy: pointer to copy-constructor input | ||
| 45 | //! \param source: timer source selection (defaults to RAWTIME_DEFAULT) | ||
| 46 | //! \return: pointer to delegate | ||
| 47 | static RawTimeInterface* getDelegate(RawTimeHandleStorage& aligned_new_memory, | ||
| 48 | const RawTimeInterface* to_copy = nullptr, | ||
| 49 | RawTimeSource source = RAWTIME_DEFAULT); | ||
| 50 | |||
| 51 | // ------------------------------------------------------------------ | ||
| 52 | // RawTime operations to be implemented by an OSAL implementation | ||
| 53 | // ------------------------------------------------------------------ | ||
| 54 | |||
| 55 | //! \brief Get the current time. | ||
| 56 | //! | ||
| 57 | //! This function retrieves the current time and stores it in the RawTime object. | ||
| 58 | //! Each implementation should define its RawTimeHandle type for storing the time. | ||
| 59 | //! | ||
| 60 | //! \return Status indicating the result of the operation. | ||
| 61 | virtual Status now() = 0; | ||
| 62 | |||
| 63 | //! \brief Calculate the time interval between this and another raw time. | ||
| 64 | //! | ||
| 65 | //! This function calculates the time interval between the current raw time and another | ||
| 66 | //! specified raw time. The result is stored in the provided (output) interval object. | ||
| 67 | //! | ||
| 68 | //! \param other The other RawTimeHandle to compare against. | ||
| 69 | //! \param interval Output parameter to store the calculated time interval. | ||
| 70 | //! \return Status indicating the result of the operation. | ||
| 71 | virtual Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const = 0; | ||
| 72 | |||
| 73 | //! \brief Serialize the contents of the RawTimeInterface object into a buffer. | ||
| 74 | //! | ||
| 75 | //! This function serializes the contents of the RawTimeInterface object into the provided | ||
| 76 | //! buffer. | ||
| 77 | //! | ||
| 78 | //! \note The serialization must fit within `FW_RAW_TIME_SERIALIZATION_MAX_SIZE` bytes. This value is | ||
| 79 | //! defined in FpConfig.h. For example, Posix systems use a pair of U32 (sec, nanosec) and can therefore | ||
| 80 | //! serialize in 8 bytes. Should an OSAL implementation require more than this, the project must increase | ||
| 81 | //! that value in its config/ folder. | ||
| 82 | //! | ||
| 83 | //! \param buffer The buffer to serialize the contents into. | ||
| 84 | //! \param mode Endianness to use when serializing to buffer. | ||
| 85 | //! \return Fw::SerializeStatus indicating the result of the serialization. | ||
| 86 | virtual Fw::SerializeStatus serializeTo(Fw::SerialBufferBase& buffer, | ||
| 87 | Fw::Endianness mode = Fw::Endianness::BIG) const = 0; | ||
| 88 | |||
| 89 | //! \brief Deserialize the contents of the RawTimeInterface object from a buffer. | ||
| 90 | //! | ||
| 91 | //! This function deserializes the contents of the RawTimeInterface object from the provided | ||
| 92 | //! buffer. | ||
| 93 | //! | ||
| 94 | //! \note The serialization must fit within `FW_RAW_TIME_SERIALIZATION_MAX_SIZE` bytes. This value is | ||
| 95 | //! defined in FpConfig.h. For example, Posix systems use a pair of U32 (sec, nanosec) and can therefore | ||
| 96 | //! serialize in 8 bytes. Should an OSAL implementation require more than this, the project must increase | ||
| 97 | //! that value in its config/ folder. | ||
| 98 | //! | ||
| 99 | //! \param buffer The buffer to deserialize the contents from. | ||
| 100 | //! \param mode Endianness to use when deserializing from the buffer. | ||
| 101 | //! \return Fw::SerializeStatus indicating the result of the deserialization. | ||
| 102 | virtual Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase& buffer, | ||
| 103 | Fw::Endianness mode = Fw::Endianness::BIG) = 0; | ||
| 104 | |||
| 105 | // ------------------------------------------------------------------ | ||
| 106 | // Common virtual functions built on top of OS-specific functions | ||
| 107 | // ------------------------------------------------------------------ | ||
| 108 | |||
| 109 | //! \brief Calculate the difference in microseconds between two RawTime objects. | ||
| 110 | //! | ||
| 111 | //! This function calculates the difference in microseconds between the current RawTime object | ||
| 112 | //! and another RawTime object provided as a parameter. | ||
| 113 | //! | ||
| 114 | //! \warning This function will return Status::OP_OVERFLOW if the time difference is too large to fit in a U32. | ||
| 115 | //! \warning This means the largest time difference that can be measured is 2^32 microseconds (about 71 minutes). | ||
| 116 | //! \warning Users should prefer getTimeInterval() for larger intervals. | ||
| 117 | //! | ||
| 118 | //! \param other The other RawTime object to compare against. | ||
| 119 | //! \param result A reference to a U32 variable where the result will be stored. | ||
| 120 | //! \return Status indicating the result of the operation. | ||
| 121 | virtual Status getDiffUsec(const RawTime& other, U32& result) const; | ||
| 122 | |||
| 123 | //! \brief Compare whether two RawTime objects are the same (i.e. refer to the same microsecond) | ||
| 124 | virtual bool operator==(const RawTime& other) const; | ||
| 125 | }; | ||
| 126 | } // namespace Os | ||
| 127 | |||
| 128 | #endif // OS_RAWTIMEINTERFACE_HPP_ | ||
| 129 |