public inbox for ecos-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrong time/date data
@ 2012-05-31 17:16 bugzilla-daemon
  0 siblings, 0 replies; 2+ messages in thread
From: bugzilla-daemon @ 2012-05-31 17:16 UTC (permalink / raw)
  To: unassigned

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001603

           Summary: LPC2XXX/17XX HW RTC driver can report wrong time/date
                    data
           Product: eCos
           Version: CVS
          Platform: Other (please specify)
        OS/Version: Cortex-M
            Status: UNCONFIRMED
          Severity: normal
          Priority: low
         Component: Wallclock
        AssignedTo: unassigned@bugs.ecos.sourceware.org
        ReportedBy: bernard.fouche@kuantic.com
                CC: ecos-bugs@ecos.sourceware.org
             Class: Advice Request


I'm looking at the HW RTC driver for LPC2XXX/LP17XX and I see this:

struct time {
  volatile cyg_uint32 sec;
  volatile cyg_uint32 min;
  volatile cyg_uint32 hour;
  volatile cyg_uint32 dom;
  volatile cyg_uint32 dow;
  volatile cyg_uint32 doy;
  volatile cyg_uint32 month;
  volatile cyg_uint32 year;
};

struct rtcdev {
  volatile cyg_uint32 ilr;
  volatile cyg_uint32 ctc;
  volatile cyg_uint32 ccr;
  volatile cyg_uint32 ciir;
  volatile cyg_uint32 amr;
  volatile cyg_uint32 ctime[3];
  struct time time;
  cyg_uint32 dummy[8];
  struct time alarm;
#ifndef CYGHWR_HAL_LPC_RTC_32768HZ
  volatile cyg_uint32 preint;
  volatile cyg_uint32 prefrac;
#endif
};

static struct rtcdev * const rtc =
  (struct rtcdev *) CYGARC_HAL_LPC2XXX_REG_RTC_BASE;
...[snip]...

cyg_uint32
Cyg_WallClock::get_hw_seconds(void)
{
  return _simple_mktime(rtc->time.year,
                        rtc->time.month,
                        rtc->time.dom,
                        rtc->time.hour,
                        rtc->time.min,
                        rtc->time.sec);
}

The problem is:

- time data is spread in different HW registers that can't be read in a single
shot by the MCU.
- the code do not consider the case when unfortunately the RTC will change of
second exactly between different register reads.

For instance get_hw_seconds() is called at 23:59:59, a few ns before the RTC is
about to move to 00:00:00: the function can return 23:00:59, 00:59:00, 
anything is possible according to the way the compiler orders the processing of
the arguments before calling _simple_mktime() (the same for the date).

The solution is to read the whole set of registers twice: if they don't have
the same value, then read them again. If there are similar, then report the
result since it will be coherent.

  Bernard

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrong time/date data
@ 2012-05-31 17:16 bugzilla-daemon
  0 siblings, 0 replies; 2+ messages in thread
From: bugzilla-daemon @ 2012-05-31 17:16 UTC (permalink / raw)
  To: ecos-bugs

Please do not reply to this email. Use the web interface provided at:
http://bugs.ecos.sourceware.org/show_bug.cgi?id=1001603

           Summary: LPC2XXX/17XX HW RTC driver can report wrong time/date
                    data
           Product: eCos
           Version: CVS
          Platform: Other (please specify)
        OS/Version: Cortex-M
            Status: UNCONFIRMED
          Severity: normal
          Priority: low
         Component: Wallclock
        AssignedTo: unassigned@bugs.ecos.sourceware.org
        ReportedBy: bernard.fouche@kuantic.com
                CC: ecos-bugs@ecos.sourceware.org
             Class: Advice Request


I'm looking at the HW RTC driver for LPC2XXX/LP17XX and I see this:

struct time {
  volatile cyg_uint32 sec;
  volatile cyg_uint32 min;
  volatile cyg_uint32 hour;
  volatile cyg_uint32 dom;
  volatile cyg_uint32 dow;
  volatile cyg_uint32 doy;
  volatile cyg_uint32 month;
  volatile cyg_uint32 year;
};

struct rtcdev {
  volatile cyg_uint32 ilr;
  volatile cyg_uint32 ctc;
  volatile cyg_uint32 ccr;
  volatile cyg_uint32 ciir;
  volatile cyg_uint32 amr;
  volatile cyg_uint32 ctime[3];
  struct time time;
  cyg_uint32 dummy[8];
  struct time alarm;
#ifndef CYGHWR_HAL_LPC_RTC_32768HZ
  volatile cyg_uint32 preint;
  volatile cyg_uint32 prefrac;
#endif
};

static struct rtcdev * const rtc =
  (struct rtcdev *) CYGARC_HAL_LPC2XXX_REG_RTC_BASE;
...[snip]...

cyg_uint32
Cyg_WallClock::get_hw_seconds(void)
{
  return _simple_mktime(rtc->time.year,
                        rtc->time.month,
                        rtc->time.dom,
                        rtc->time.hour,
                        rtc->time.min,
                        rtc->time.sec);
}

The problem is:

- time data is spread in different HW registers that can't be read in a single
shot by the MCU.
- the code do not consider the case when unfortunately the RTC will change of
second exactly between different register reads.

For instance get_hw_seconds() is called at 23:59:59, a few ns before the RTC is
about to move to 00:00:00: the function can return 23:00:59, 00:59:00, 
anything is possible according to the way the compiler orders the processing of
the arguments before calling _simple_mktime() (the same for the date).

The solution is to read the whole set of registers twice: if they don't have
the same value, then read them again. If there are similar, then report the
result since it will be coherent.

  Bernard

-- 
Configure bugmail: http://bugs.ecos.sourceware.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-31 17:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-31 17:16 [Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrong time/date data bugzilla-daemon
2012-05-31 17:16 bugzilla-daemon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).