This is the mail archive of the ecos-bugs@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrongtime/date data


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]