1 //==========================================================================
3 // lpc2xxx_wallclock.cxx
5 // Wallclock implementation for LPC2xxx
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // Copyright (C) 2003 Gary Thomas
13 // Copyright (C) 2004 eCosCentric Ltd
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
37 // -------------------------------------------
38 //####ECOSGPLCOPYRIGHTEND####
39 //==========================================================================
40 //#####DESCRIPTIONBEGIN####
42 // Author(s): Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
45 // Purpose: Wallclock driver for LPC2xxx
47 //####DESCRIPTIONEND####
49 //==========================================================================
51 #include <pkgconf/hal.h>
52 #include <pkgconf/wallclock.h>
53 #include <pkgconf/devices_wallclock_arm_lpc2xxx.h>
55 #include <cyg/hal/hal_io.h>
56 #include <cyg/hal/hal_intr.h>
57 #include <cyg/infra/cyg_type.h>
59 #include <cyg/io/wallclock.hxx>
60 #include <cyg/io/wallclock/wallclock.inl>
63 * I don't like to write LOTS OF CAPITALIZED TEXT.
64 * This code is intended for LPC2xxx processors _only_, so there is nothing
65 * wrong with accessing this device directly without using the HAL macros.
69 volatile cyg_uint32 sec;
70 volatile cyg_uint32 min;
71 volatile cyg_uint32 hour;
72 volatile cyg_uint32 dom;
73 volatile cyg_uint32 dow;
74 volatile cyg_uint32 doy;
75 volatile cyg_uint32 month;
76 volatile cyg_uint32 year;
80 volatile cyg_uint32 ilr;
81 volatile cyg_uint32 ctc;
82 volatile cyg_uint32 ccr;
83 volatile cyg_uint32 ciir;
84 volatile cyg_uint32 amr;
85 volatile cyg_uint32 ctime[3];
89 volatile cyg_uint32 preint;
90 volatile cyg_uint32 prefrac;
93 static struct rtcdev * const rtc =
94 (struct rtcdev *) CYGARC_HAL_LPC2XXX_REG_RTC_BASE;
97 Cyg_WallClock::init_hw_seconds(void)
99 /* halt clock, disable interrupts, disable alarm */
104 /* initialize prescaler */
105 rtc->preint = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT;
106 rtc->prefrac = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREFRAC;
108 #ifndef CYGSEM_WALLCLOCK_SET_GET_MODE
109 /* reset time to the Unix Epoch */
110 rtc->time.year = 1970;
121 rtc->alarm.year = rtc->alarm.month = rtc->alarm.dom = rtc->alarm.doy =
122 rtc->alarm.dow = rtc->alarm.hour = rtc->alarm.min =
130 Cyg_WallClock::get_hw_seconds(void)
132 return _simple_mktime(rtc->time.year,
140 #ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
142 Cyg_WallClock::set_hw_seconds(cyg_uint32 secs)
144 cyg_uint32 year, month, dom, hour, min, sec;
146 /* halt clock, reset counter */
150 _simple_mkdate(secs, &year, &month, &dom, &hour, &min, &sec);
151 rtc->time.year = year;
152 rtc->time.month = month;
154 rtc->time.hour = hour;