properly implemented getDataAndTime

This commit is contained in:
Robin Müller 2021-03-04 23:24:57 +01:00
parent cb514e7493
commit 2d069896a5

View File

@ -105,20 +105,28 @@ ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
/* For all but the last field, the struct will be filled with the correct values */
rtems_time_of_day* timeRtems = reinterpret_cast<rtems_time_of_day*>(time);
rtems_status_code status = rtems_clock_get_tod(timeRtems);
/* The last field now contains the RTEMS ticks of the seconds from 0
to rtems_clock_get_ticks_per_second() minus one. We calculate the microseconds accordingly */
timeRtems->ticks = static_cast<float>(timeRtems->ticks) /
rtems_clock_get_ticks_per_second() * 1e6;
rtems_time_of_day timeRtems;
rtems_status_code status = rtems_clock_get_tod(&timeRtems);
switch (status) {
case RTEMS_SUCCESSFUL:
case RTEMS_SUCCESSFUL: {
/* The last field now contains the RTEMS ticks of the seconds from 0
to rtems_clock_get_ticks_per_second() minus one.
We calculate the microseconds accordingly */
time->day = timeRtems.day;
time->hour = timeRtems.hour;
time->minute = timeRtems.minute;
time->month = timeRtems.month;
time->second = timeRtems.second;
time->usecond = static_cast<float>(timeRtems.ticks) /
rtems_clock_get_ticks_per_second() * 1e6;
time->year = timeRtems.year;
return HasReturnvaluesIF::RETURN_OK;
}
case RTEMS_NOT_DEFINED:
//system date and time is not set
/* System date and time is not set */
return HasReturnvaluesIF::RETURN_FAILED;
case RTEMS_INVALID_ADDRESS:
//time_buffer is NULL
/* time_buffer is NULL */
return HasReturnvaluesIF::RETURN_FAILED;
default:
return HasReturnvaluesIF::RETURN_FAILED;