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
88namespace 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]
0 commit comments