Skip to content

Commit a454a07

Browse files
committed
Fix FPrime microsecond range expectation
1 parent b7c3ddb commit a454a07

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

FprimeZephyrReference/Components/Drv/Rv3028Manager/Rv3028Manager.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ U32 Rv3028Manager ::timeGet_handler(FwIndexType portNum) {
5353
U32 u_secs;
5454
this->getTime(posix_time, u_secs);
5555

56-
return u_secs;
56+
return posix_time;
5757
}
5858

5959
void Rv3028Manager ::timeSet_handler(FwIndexType portNum, const Drv::TimeData& t) {
@@ -109,7 +109,11 @@ void Rv3028Manager ::getTime(U32& posix_time, U32& u_secs) {
109109
return;
110110
}
111111

112-
uint32_t time_usecs = k_cyc_to_us_near32(k_cycle_get_32());
112+
// Get microsecond part from system clock cycles
113+
// Note: RV3028 does not provide sub-second precision, so this is
114+
// just an approximation based on system cycles.
115+
// FPrime expects microseconds in the range [0, 999999]
116+
uint32_t time_usecs = k_cyc_to_us_near32(k_cycle_get_32()) % 1000000;
113117

114118
// Set output parameters
115119
posix_time = static_cast<U32>(time_pt);

FprimeZephyrReference/test/int/rtc_test.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,25 @@ def test_01_current_time_set(fprime_test_api: IntegrationTestAPI):
7272
pytest.approx(event_time, abs=30) == datetime.now(timezone.utc)
7373

7474

75-
def test_02_set_time_in_past(fprime_test_api: IntegrationTestAPI):
75+
def test_02_time_incrementing(fprime_test_api: IntegrationTestAPI):
76+
"""Test that time increments over time"""
77+
78+
# Fetch initial time
79+
initial_event_time = get_time(fprime_test_api)
80+
81+
# Wait for time to increment
82+
time.sleep(2.0)
83+
84+
# Fetch updated time
85+
updated_event_time = get_time(fprime_test_api)
86+
87+
# Assert time has increased
88+
assert updated_event_time > initial_event_time, (
89+
f"Time should increase. Initial: {initial_event_time}, Updated: {updated_event_time}"
90+
)
91+
92+
93+
def test_03_set_time_in_past(fprime_test_api: IntegrationTestAPI):
7694
"""Test that we can set the time to a past time"""
7795

7896
# Set time to Curiosity landing on Mars (7 minutes of terror! https://youtu.be/Ki_Af_o9Q9s)
@@ -90,34 +108,17 @@ def test_02_set_time_in_past(fprime_test_api: IntegrationTestAPI):
90108
event_previous_time_arg.val, tz=timezone.utc
91109
)
92110

111+
# Fetch FPrime time from event
112+
fp_time: TimeType = result.get_time()
113+
event_time = datetime.fromtimestamp(fp_time.seconds, tz=timezone.utc)
114+
93115
# Assert previously set time is within 30 seconds of now
94116
pytest.approx(previously_set_time, abs=30) == datetime.now(timezone.utc)
95117

96-
# Fetch newly set time from event
97-
event_time = get_time(fprime_test_api)
98-
99-
# Assert time is within 30 seconds of curiosity landing
118+
# Assert event time is within 30 seconds of curiosity landing
100119
pytest.approx(event_time, abs=30) == curiosity_landing
101120

102121

103-
def test_03_time_incrementing(fprime_test_api: IntegrationTestAPI):
104-
"""Test that time increments over time"""
105-
106-
# Fetch initial time
107-
initial_event_time = get_time(fprime_test_api)
108-
109-
# Wait for time to increment
110-
time.sleep(2.0)
111-
112-
# Fetch updated time
113-
updated_event_time = get_time(fprime_test_api)
114-
115-
# Assert time has increased
116-
assert updated_event_time > initial_event_time, (
117-
f"Time should increase. Initial: {initial_event_time}, Updated: {updated_event_time}"
118-
)
119-
120-
121122
def test_04_time_in_telemetry(fprime_test_api: IntegrationTestAPI):
122123
"""Test that we can get Time telemetry"""
123124

0 commit comments

Comments
 (0)