From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14530 invoked by alias); 31 May 2012 17:16:58 -0000 Received: (qmail 14516 invoked by uid 22791); 31 May 2012 17:16:57 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from hagrid.ecoscentric.com (HELO mail.ecoscentric.com) (212.13.207.197) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 31 May 2012 17:16:44 +0000 Received: from localhost (hagrid.ecoscentric.com [127.0.0.1]) by mail.ecoscentric.com (Postfix) with ESMTP id 370422F78005 for ; Thu, 31 May 2012 18:16:43 +0100 (BST) Received: from mail.ecoscentric.com ([127.0.0.1]) by localhost (hagrid.ecoscentric.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r+iM8W1UNUs0; Thu, 31 May 2012 18:16:41 +0100 (BST) From: bugzilla-daemon@bugs.ecos.sourceware.org To: ecos-bugs@ecos.sourceware.org Subject: [Bug 1001603] New: LPC2XXX/17XX HW RTC driver can report wrong time/date data X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: eCos X-Bugzilla-Component: Wallclock X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bernard.fouche@kuantic.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: low X-Bugzilla-Assigned-To: unassigned@bugs.ecos.sourceware.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://bugs.ecos.sourceware.org/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Thu, 31 May 2012 17:16:00 -0000 Mailing-List: contact ecos-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: ecos-bugs-owner@sourceware.org X-SW-Source: 2012/txt/msg00982.txt.bz2 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.