273 views
in System Integration by

Hi Gents,

 I've implemented EwBspGetTime() as seen below. However, unix time stamps are UTC. Is there a method to convert the UTC unix timestamp within EW? Or do I need to do this at the BSP layer with localtime() and such?

 

unsigned long EwBspGetTime( void )
{
    ppsys_rtc_read(); // mls    
    return (unsigned long) RTC_Data.unixepoch; // mls
}

 

1 Answer

0 votes
by

Hi Mike,

for an Embedded Wizard GUI application the current time is the local time - this means UTC plus time zone plus daylight saving time offset.

For that purpose, the Runtime Environment (RTE) function EwGetTime() is called. In case of Windows or Linux, the implementation of EwGetTime() is using some operating system functions to get the current local time.

In case of most embedded systems (MCUs) the function EwGetTime() calls the BSP interface function EwBspGetTime() in order to access the RTC of the hardware. This means, either your BSP handles the current time aspects - or you need to handle that within EwBspGetTime().

Does this answer your question?

Best regards,

Manfred.

by
I think so.

Your first statement indicates the GUI application is expecting a UTC time plus whatever offset is required for a time-zone.

And your last statement indicates, since I have a MCU based platform and not an OS, that I do need to modify EwBspGetTime() to accomplish this.

Thanks,

 Mike
by
In thinking about this... Unix Epoch is always UTC. And the GUI's Core::Time is always expecting to be passed Unix Epoch. So that sort of necessitates the conversion of Epoch to Local Time to happen at the GUI level.

Typically in C one has localtime() to accomplish this. So I guess that re-parses my original question... is there a localtime() function or referential bit of code to do this?

 

Mike
by

Oh, I just noticed EwBspClockGetTime() effectively has what localtime() does. Core::Time, while expecting an int long of seconds, isn't exactly expecting Epoch time. But an Epoch time like format.

by

Incase anyone else reads this thread. Typical solution for this:

 

unsigned long EwBspClockGetTime( void )
{
  /* mls
  snvs_hp_rtc_datetime_t rtcDateTime;
  SNVS_HP_RTC_GetDatetime( SNVS, &rtcDateTime );

  unsigned long   days;
  unsigned long   year   = rtcDateTime.year - 2000;
  unsigned long   month  = rtcDateTime.month;
  unsigned long   day    = rtcDateTime.day;
  unsigned long   hour   = rtcDateTime.hour;
  unsigned long   minute = rtcDateTime.minute;
  unsigned long   second = rtcDateTime.second;
  unsigned long   timeInSeconds;
  */

  time_t rawtime;
  struct tm *info;

  rawtime = EwBspGetTime(); // Unixepoch is UTC
  info = localtime( &rawtime ); // convert UTC to localtime

  unsigned long   days;
  unsigned long   year   = info->tm_year - 100;
  unsigned long   month  = info->tm_mon+1;
  unsigned long   day    = info->tm_mday;
  unsigned long   hour   = info->tm_hour;
  unsigned long   minute = info->tm_min;
  unsigned long   second = info->tm_sec;
  unsigned long   timeInSeconds;

  // year is the number of years since 2000
  // calculate number of days since 01.01.1970 until begin of current     year including the additional days of leap years

  days = (year + 30) * 365 + (year + 27) / 4;

  if (year & 0x3)
  {
    days += DaysToMonth[month - 1];
  }
  else
  {
    days += DaysToMonthInLeapYear[month - 1];
  }

  days += day;

  timeInSeconds =
    days   * RtcTicksPerDay +
    hour   * RtcTicksPerHour +
    minute * RtcTicksPerMinute +
    second;

  return timeInSeconds;
}

 

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...