Skip to content

Commit 4b42cc4

Browse files
committed
Simplify RTC Manager
1 parent a454a07 commit 4b42cc4

File tree

17 files changed

+383
-672
lines changed

17 files changed

+383
-672
lines changed

FprimeZephyrReference/Components/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv")
44
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler")
55
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
6-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/RtcManager/")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Rv3028Manager")
1+
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/RtcManager")

FprimeZephyrReference/Components/Drv/Rv3028Manager/Rv3028Manager.cpp renamed to FprimeZephyrReference/Components/Drv/RtcManager/RtcManager.cpp

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// ======================================================================
2-
// \title Rv3028Manager.cpp
3-
// \brief cpp file for Rv3028Manager component implementation class
2+
// \title RtcManager.cpp
3+
// \brief cpp file for RtcManager component implementation class
44
// ======================================================================
55

6-
#include "FprimeZephyrReference/Components/Drv/Rv3028Manager/Rv3028Manager.hpp"
6+
#include "FprimeZephyrReference/Components/Drv/RtcManager/RtcManager.hpp"
77

88
namespace Drv {
99

1010
// ----------------------------------------------------------------------
1111
// Component construction and destruction
1212
// ----------------------------------------------------------------------
1313

14-
Rv3028Manager ::Rv3028Manager(const char* const compName) : Rv3028ManagerComponentBase(compName) {
14+
RtcManager ::RtcManager(const char* const compName) : RtcManagerComponentBase(compName) {
1515
// Initialize device
16-
this->rv3028 = device_get_binding("RV3028");
16+
this->dev = device_get_binding("RV3028");
1717
}
1818

19-
Rv3028Manager ::~Rv3028Manager() {}
19+
RtcManager ::~RtcManager() {}
2020

2121
// ----------------------------------------------------------------------
22-
// Handler implementations for commands
22+
// Handler implementations for typed input ports
2323
// ----------------------------------------------------------------------
2424

25-
void Rv3028Manager ::timeGetPort_handler(FwIndexType portNum, Fw::Time& time) {
25+
void RtcManager ::timeGetPort_handler(FwIndexType portNum, Fw::Time& time) {
2626
// Check device readiness
27-
if (!device_is_ready(this->rv3028)) {
27+
if (!device_is_ready(this->dev)) {
2828
// Use logger instead of events since this fn is in a critical path for FPrime
2929
// to get time. Events require time, if this method fails an event will fail.
3030
Fw::Logger::log("RV2038 not ready");
@@ -40,25 +40,13 @@ void Rv3028Manager ::timeGetPort_handler(FwIndexType portNum, Fw::Time& time) {
4040
time.set(TimeBase::TB_WORKSTATION_TIME, 0, posix_time, u_secs);
4141
}
4242

43-
U32 Rv3028Manager ::timeGet_handler(FwIndexType portNum) {
44-
// Check device readiness
45-
if (!device_is_ready(this->rv3028)) {
46-
this->log_WARNING_HI_DeviceNotReady();
47-
return 0;
48-
}
49-
this->log_WARNING_HI_DeviceNotReady_ThrottleClear();
50-
51-
// Get time from RTC
52-
U32 posix_time;
53-
U32 u_secs;
54-
this->getTime(posix_time, u_secs);
55-
56-
return posix_time;
57-
}
43+
// ----------------------------------------------------------------------
44+
// Handler implementations for commands
45+
// ----------------------------------------------------------------------
5846

59-
void Rv3028Manager ::timeSet_handler(FwIndexType portNum, const Drv::TimeData& t) {
47+
void RtcManager ::TIME_SET_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Drv::TimeData t) {
6048
// Check device readiness
61-
if (!device_is_ready(this->rv3028)) {
49+
if (!device_is_ready(this->dev)) {
6250
this->log_WARNING_HI_DeviceNotReady();
6351
return;
6452
}
@@ -77,27 +65,38 @@ void Rv3028Manager ::timeSet_handler(FwIndexType portNum, const Drv::TimeData& t
7765
.tm_isdst = 0,
7866
};
7967

68+
// Store current time for logging
69+
U32 posix_time;
70+
U32 u_secs;
71+
this->getTime(posix_time, u_secs);
72+
8073
// Set time on RTC
81-
const int status = rtc_set_time(this->rv3028, &time_rtc);
82-
83-
// Report whether setting the time was successful
84-
if (status == 0) {
85-
U32 posix_time;
86-
U32 u_secs;
87-
this->getTime(posix_time, u_secs);
88-
this->log_ACTIVITY_HI_TimeSet(posix_time);
89-
} else {
74+
const int status = rtc_set_time(this->dev, &time_rtc);
75+
76+
if (status != 0) {
77+
// Emit time not set event
9078
this->log_WARNING_HI_TimeNotSet();
79+
80+
// Send command response
81+
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
82+
return;
9183
}
84+
85+
// Emit time set event, include previous time for reference
86+
this->log_ACTIVITY_HI_TimeSet(posix_time, u_secs);
87+
88+
// Send command response
89+
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
9290
}
9391

9492
// ----------------------------------------------------------------------
9593
// Private helper methods
9694
// ----------------------------------------------------------------------
97-
void Rv3028Manager ::getTime(U32& posix_time, U32& u_secs) {
95+
96+
void RtcManager ::getTime(U32& posix_time, U32& u_secs) {
9897
// Read time from RTC
9998
struct rtc_time time_rtc = {};
100-
rtc_get_time(this->rv3028, &time_rtc);
99+
rtc_get_time(this->dev, &time_rtc);
101100

102101
// Convert time to POSIX time_t format
103102
struct tm* time_tm = rtc_time_to_tm(&time_rtc);
@@ -109,7 +108,7 @@ void Rv3028Manager ::getTime(U32& posix_time, U32& u_secs) {
109108
return;
110109
}
111110

112-
// Get microsecond part from system clock cycles
111+
// Get microseconds from system clock cycles
113112
// Note: RV3028 does not provide sub-second precision, so this is
114113
// just an approximation based on system cycles.
115114
// FPrime expects microseconds in the range [0, 999999]

FprimeZephyrReference/Components/Drv/Rv3028Manager/Rv3028Manager.fpp renamed to FprimeZephyrReference/Components/Drv/RtcManager/RtcManager.fpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,45 @@ module Drv {
1818

1919
module Drv {
2020
@ Manages the real time clock
21-
passive component Rv3028Manager {
21+
passive component RtcManager {
2222
import Svc.Time
2323

24-
@ timeSet port to set the time on the RTC
25-
sync input port timeSet: TimeSet
26-
27-
@ timeGet port to get the time from the RTC
28-
sync input port timeGet: TimeGet
24+
@ TIME_SET command to set the time on the RTC
25+
sync command TIME_SET(
26+
t: Drv.TimeData @< Set the time
27+
) opcode 0
2928

3029
##############################################################################
3130
#### Uncomment the following examples to start customizing your component ####
3231
##############################################################################
3332

34-
@ DeviceNotReady event indicates that the RV3028 is not ready
35-
event DeviceNotReady() severity warning high id 0 format "RV3028 not ready" throttle 5
33+
@ DeviceNotReady event indicates that the RTC is not ready
34+
event DeviceNotReady() severity warning high id 0 format "RTC not ready" throttle 5
3635

3736
@ TimeSet event indicates that the time was set successfully
3837
event TimeSet(
39-
t: U32 @< POSIX time read from RTC
40-
) severity activity high id 3 format "Time set on RV3028, previous time: {}"
38+
pt: U32 @< POSIX time in seconds
39+
u: U32 @< Microseconds
40+
) severity activity high id 3 format "Time set on RTC, previous time: {}.{}"
4141

4242
@ TimeNotSet event indicates that the time was not set successfully
43-
event TimeNotSet() severity warning high id 4 format "Time not set on RV3028"
43+
event TimeNotSet() severity warning high id 4 format "Time not set on RTC"
4444

4545
###############################################################################
4646
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
4747
###############################################################################
4848
@ Port for requesting the current time
4949
time get port timeCaller
5050

51+
@ Port for sending command registrations
52+
command reg port cmdRegOut
53+
54+
@ Port for receiving commands
55+
command recv port cmdIn
56+
57+
@ Port for sending command responses
58+
command resp port cmdResponseOut
59+
5160
@ Port for sending textual representation of events
5261
text event port logTextOut
5362

FprimeZephyrReference/Components/Drv/Rv3028Manager/Rv3028Manager.hpp renamed to FprimeZephyrReference/Components/Drv/RtcManager/RtcManager.hpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// ======================================================================
2-
// \title Rv3028Manager.hpp
3-
// \brief hpp file for Rv3028Manager component implementation class
2+
// \title RtcManager.hpp
3+
// \brief hpp file for RtcManager component implementation class
44
// ======================================================================
55

6-
#ifndef Components_Rv3028Manager_HPP
7-
#define Components_Rv3028Manager_HPP
6+
#ifndef Components_RtcManager_HPP
7+
#define Components_RtcManager_HPP
88

9-
#include "FprimeZephyrReference/Components/Drv/Rv3028Manager/Rv3028ManagerComponentAc.hpp"
9+
#include "FprimeZephyrReference/Components/Drv/RtcManager/RtcManagerComponentAc.hpp"
1010

1111
#include <cerrno>
1212

@@ -20,22 +20,22 @@
2020

2121
namespace Drv {
2222

23-
class Rv3028Manager final : public Rv3028ManagerComponentBase {
23+
class RtcManager final : public RtcManagerComponentBase {
2424
public:
2525
// ----------------------------------------------------------------------
2626
// Component construction and destruction
2727
// ----------------------------------------------------------------------
2828

29-
//! Construct Rv3028Manager object
30-
Rv3028Manager(const char* const compName //!< The component name
29+
//! Construct RtcManager object
30+
RtcManager(const char* const compName //!< The component name
3131
);
3232

33-
//! Destroy Rv3028Manager object
34-
~Rv3028Manager();
33+
//! Destroy RtcManager object
34+
~RtcManager();
3535

3636
private:
3737
// ----------------------------------------------------------------------
38-
// Handler implementations for commands
38+
// Handler implementations for typed input ports
3939
// ----------------------------------------------------------------------
4040

4141
//! Handler implementation for timeGetPort
@@ -45,19 +45,18 @@ class Rv3028Manager final : public Rv3028ManagerComponentBase {
4545
Fw::Time& time //!< Reference to Time object
4646
) override;
4747

48-
//! Handler implementation for timeGet
49-
//!
50-
//! timeGet port to get the time from the RTC
51-
//! Requirement Rv3028Manager-002
52-
U32 timeGet_handler(FwIndexType portNum //!< The port number
53-
) override;
48+
private:
49+
// ----------------------------------------------------------------------
50+
// Handler implementations for commands
51+
// ----------------------------------------------------------------------
5452

55-
//! Handler implementation for timeSet
53+
//! Handler implementation for command TIME_SET
5654
//!
57-
//! timeSet port to set the time on the RTC
58-
//! Requirement Rv3028Manager-001
59-
void timeSet_handler(FwIndexType portNum, //!< The port number
60-
const Drv::TimeData& time) override;
55+
//! TIME_SET command to set the time on the RTC
56+
void TIME_SET_cmdHandler(FwOpcodeType opCode, //!< The opcode
57+
U32 cmdSeq, //!< The command sequence number
58+
Drv::TimeData t //!< Set the time
59+
) override;
6160

6261
// ----------------------------------------------------------------------
6362
// Private helper methods
@@ -66,8 +65,8 @@ class Rv3028Manager final : public Rv3028ManagerComponentBase {
6665
//! Helper method to get time from RTC
6766
void getTime(U32& posix_time, U32& u_secs);
6867

69-
//! Zephyr device stores the initialized RV2038 sensor
70-
const struct device* rv3028;
68+
//! device stores the initialized Zephyr RTC device
69+
const struct device* dev;
7170
};
7271

7372
} // namespace Drv

0 commit comments

Comments
 (0)