@@ -25,20 +25,20 @@ Rv3028Manager ::~Rv3028Manager() {}
2525void Rv3028Manager ::timeGetPort_handler (FwIndexType portNum, Fw::Time& time) {
2626 // Check device readiness
2727 if (!device_is_ready (this ->rv3028 )) {
28- Fw::Logger::log (" Rv2038 not ready" );
28+ // Use logger instead of events since this fn is in a critical path for FPrime
29+ // to get time. Events require time, if this method fails an event will fail.
30+ Fw::Logger::log (" RV2038 not ready" );
2931 return ;
3032 }
3133
32- // Fetch time from RTC
33- struct rtc_time time_rtc = {};
34- rtc_get_time (this ->rv3028 , &time_rtc);
35-
36- // Convert time to POSIX time_t format
37- struct tm * time_tm = rtc_time_to_tm (&time_rtc);
38- time_t time_posix = timeutil_timegm (time_tm);
34+ I32 posix_time = this ->getPosixTime ();
35+ if (posix_time < 0 ) {
36+ Fw::Logger::log (" getPosixTime returned invalid time" );
37+ return ;
38+ }
3939
4040 // Set FPrime time object
41- time.set (TimeBase::TB_WORKSTATION_TIME, 0 , static_cast <U32>(time_posix ), 0 );
41+ time.set (TimeBase::TB_WORKSTATION_TIME, 0 , static_cast <U32>(posix_time ), 0 );
4242}
4343
4444U32 Rv3028Manager ::timeRead_handler (FwIndexType portNum) {
@@ -47,16 +47,16 @@ U32 Rv3028Manager ::timeRead_handler(FwIndexType portNum) {
4747 this ->log_WARNING_HI_DeviceNotReady ();
4848 return 0 ;
4949 }
50+ this ->log_WARNING_HI_DeviceNotReady_ThrottleClear ();
5051
51- // Fetch time from RTC
52- struct rtc_time time_rtc = {};
53- rtc_get_time (this ->rv3028 , &time_rtc);
54-
55- // Convert time to POSIX time_t format
56- struct tm * time_tm = rtc_time_to_tm (&time_rtc);
57- time_t time_posix = timeutil_timegm (time_tm);
52+ I32 posix_time = this ->getPosixTime ();
53+ if (posix_time < 0 ) {
54+ this ->log_WARNING_HI_InvalidTime ();
55+ return 0 ;
56+ }
57+ this ->log_WARNING_HI_InvalidTime_ThrottleClear ();
5858
59- return time_posix ;
59+ return static_cast <U32>(posix_time) ;
6060}
6161
6262void Rv3028Manager ::timeSet_handler (FwIndexType portNum, const Drv::TimeData& t) {
@@ -65,20 +65,24 @@ void Rv3028Manager ::timeSet_handler(FwIndexType portNum, const Drv::TimeData& t
6565 this ->log_WARNING_HI_DeviceNotReady ();
6666 return ;
6767 }
68+ this ->log_WARNING_HI_DeviceNotReady_ThrottleClear ();
6869
6970 // Populate rtc_time structure from TimeData
7071 const struct rtc_time time_rtc = {
7172 .tm_sec = 0 ,
72- .tm_min = t.get_Minute (),
73- .tm_hour = t.get_Hour (),
74- .tm_mday = t.get_Day (),
75- .tm_mon = t.get_Month () - 1 , // month [0-11]
76- .tm_year = t.get_Year () - 1900 , // year since 1900
73+ .tm_min = static_cast < int >( t.get_Minute () ),
74+ .tm_hour = static_cast < int >( t.get_Hour () ),
75+ .tm_mday = static_cast < int >( t.get_Day () ),
76+ .tm_mon = static_cast < int >( t.get_Month () - 1 ) , // month [0-11]
77+ .tm_year = static_cast < int >( t.get_Year () - 1900 ) , // year since 1900
7778 .tm_wday = 0 ,
7879 .tm_yday = 0 ,
7980 .tm_isdst = 0 ,
8081 };
8182
83+ // Event current time to correlate prior events when new time is set
84+ this ->log_ACTIVITY_HI_TimeGet (this ->getPosixTime ());
85+
8286 // Set time on RTC
8387 const int status = rtc_set_time (this ->rv3028 , &time_rtc);
8488
@@ -90,4 +94,24 @@ void Rv3028Manager ::timeSet_handler(FwIndexType portNum, const Drv::TimeData& t
9094 }
9195}
9296
97+ // ----------------------------------------------------------------------
98+ // Private helper methods
99+ // ----------------------------------------------------------------------
100+ I32 Rv3028Manager ::getPosixTime () {
101+ struct rtc_time time_rtc = {};
102+ rtc_get_time (this ->rv3028 , &time_rtc);
103+
104+ // Convert time to POSIX time_t format
105+ struct tm * time_tm = rtc_time_to_tm (&time_rtc);
106+
107+ errno = 0 ;
108+ time_t posix_time = timeutil_timegm (time_tm);
109+ if (errno == ERANGE) {
110+ Fw::Logger::log (" RV2038 returned invalid time" );
111+ return -1 ;
112+ }
113+
114+ return posix_time;
115+ }
116+
93117} // namespace Drv
0 commit comments