| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Samd21/Drv/RtcDriver/RawTime.hpp | ||
| 3 | // \brief Realtime clock implementation for Os::RawTime | ||
| 4 | // ====================================================================== | ||
| 5 | #ifndef OS_DRV_RTC_RAWTIME_HPP | ||
| 6 | #define OS_DRV_RTC_RAWTIME_HPP | ||
| 7 | |||
| 8 | #include "Os/RawTime.hpp" | ||
| 9 | |||
| 10 | namespace Os { | ||
| 11 | namespace Samd21 { | ||
| 12 | |||
| 13 | struct Samd21RawTimeHandle : public RawTimeHandle { | ||
| 14 | U32 m_seconds = 0; | ||
| 15 | U32 m_micros = 0; | ||
| 16 | }; | ||
| 17 | |||
| 18 | //! Get the current raw time handle by reading the realtime clock and tick counter | ||
| 19 | Samd21RawTimeHandle timeNow(); | ||
| 20 | |||
| 21 | //! \brief stub implementation of Os::RawTime | ||
| 22 | //! | ||
| 23 | //! Stub implementation of `RawTimeInterface`. | ||
| 24 | //! | ||
| 25 | class Samd21RawTime : public RawTimeInterface { | ||
| 26 | public: | ||
| 27 | //! \brief constructor | ||
| 28 | //! | ||
| 29 | 4 | Samd21RawTime() = default; | |
| 30 | |||
| 31 | //! \brief destructor | ||
| 32 | //! | ||
| 33 | 8 | ~Samd21RawTime() override = default; | |
| 34 | |||
| 35 | //! \brief return the underlying RawTime handle (implementation specific) | ||
| 36 | //! \return internal RawTime handle representation | ||
| 37 | RawTimeHandle* getHandle() override; | ||
| 38 | |||
| 39 | // ------------------------------------------------------------ | ||
| 40 | // Implementation-specific RawTime overrides | ||
| 41 | // ------------------------------------------------------------ | ||
| 42 | //! \brief Get the current time. | ||
| 43 | //! | ||
| 44 | //! This function retrieves the current time and stores it in the RawTime object. | ||
| 45 | //! Each implementation should define its RawTimeHandle type for storing the time. | ||
| 46 | //! | ||
| 47 | //! \return Status indicating the result of the operation. | ||
| 48 | Status now() override; | ||
| 49 | |||
| 50 | //! \brief Calculate the time interval between this and another raw time. | ||
| 51 | //! | ||
| 52 | //! This function calculates the time interval between the current raw time and another | ||
| 53 | //! specified raw time. The result is stored in the provided (output) interval object. | ||
| 54 | //! | ||
| 55 | //! \param other The other RawTimeHandle to compare against. | ||
| 56 | //! \param interval Output parameter to store the calculated time interval. | ||
| 57 | //! \return Status indicating the result of the operation. | ||
| 58 | Status getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const override; | ||
| 59 | |||
| 60 | //! \brief Serialize the contents of the RawTimeInterface object into a buffer. | ||
| 61 | //! | ||
| 62 | //! This function serializes the contents of the RawTimeInterface object into the provided | ||
| 63 | //! buffer. | ||
| 64 | //! | ||
| 65 | //! \note The serialization must fit within `FW_RAW_TIME_SERIALIZATION_MAX_SIZE` bytes. This value is | ||
| 66 | //! defined in FpConfig.h. For example, Posix systems use a pair of U32 (sec, nanosec) and can therefore | ||
| 67 | //! serialize in 8 bytes. Should an OSAL implementation require more than this, the project must increase | ||
| 68 | //! that value in its config/ folder. | ||
| 69 | //! | ||
| 70 | //! \param buffer The buffer to serialize the contents into. | ||
| 71 | //! \param mode Endianness to use when serializing to buffer. | ||
| 72 | //! \return Fw::SerializeStatus indicating the result of the serialization. | ||
| 73 | Fw::SerializeStatus serializeTo(Fw::SerialBufferBase& buffer, | ||
| 74 | Fw::Endianness mode = Fw::Endianness::BIG) const override; | ||
| 75 | |||
| 76 | //! \brief Deserialize the contents of the RawTimeInterface object from a buffer. | ||
| 77 | //! | ||
| 78 | //! This function deserializes the contents of the RawTimeInterface object from the provided | ||
| 79 | //! buffer. | ||
| 80 | //! | ||
| 81 | //! \note The serialization must fit within `FW_RAW_TIME_SERIALIZATION_MAX_SIZE` bytes. This value is | ||
| 82 | //! defined in FpConfig.h. For example, Posix systems use a pair of U32 (sec, nanosec) and can therefore | ||
| 83 | //! serialize in 8 bytes. Should an OSAL implementation require more than this, the project must increase | ||
| 84 | //! that value in its config/ folder. | ||
| 85 | //! | ||
| 86 | //! \param buffer The buffer to deserialize the contents from. | ||
| 87 | //! \param mode Endianness to use when deserializing from the buffer. | ||
| 88 | //! \return Fw::SerializeStatus indicating the result of the deserialization. | ||
| 89 | Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase& buffer, | ||
| 90 | Fw::Endianness mode = Fw::Endianness::BIG) override; | ||
| 91 | |||
| 92 | private: | ||
| 93 | //! Handle for StubRawTime | ||
| 94 | Samd21RawTimeHandle m_handle; | ||
| 95 | }; | ||
| 96 | |||
| 97 | } // namespace Samd21 | ||
| 98 | } // namespace Os | ||
| 99 | #endif // OS_STUB_RAWTIME_HPP | ||
| 100 |