]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/wallclock/arm/lpc2xxx/v2_0/src/lpc2xxx_wallclock.cxx
Merge branch 'master' of git+ssh://git.kernelconcepts.de/karo-tx-redboot
[karo-tx-redboot.git] / packages / devs / wallclock / arm / lpc2xxx / v2_0 / src / lpc2xxx_wallclock.cxx
1 //==========================================================================
2 //
3 //      lpc2xxx_wallclock.cxx
4 //
5 //      Wallclock implementation for LPC2xxx
6 //
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
14 //
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.
18 //
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
22 // for more details.
23 //
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.
27 //
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.
34 //
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####
41 //
42 // Author(s):     Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
43 // Contributors:  
44 // Date:          2007-06-19
45 // Purpose:       Wallclock driver for LPC2xxx
46 //
47 //####DESCRIPTIONEND####
48 //
49 //==========================================================================
50
51 #include <pkgconf/hal.h>
52 #include <pkgconf/wallclock.h>
53 #include <pkgconf/devices_wallclock_arm_lpc2xxx.h>
54
55 #include <cyg/hal/hal_io.h>
56 #include <cyg/hal/hal_intr.h>
57 #include <cyg/infra/cyg_type.h>
58
59 #include <cyg/io/wallclock.hxx>
60 #include <cyg/io/wallclock/wallclock.inl>
61
62 /*
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.
66  */
67
68 struct time {
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;
77 };
78
79 struct rtcdev {
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];
86   struct time time;
87   cyg_uint32 dummy[8];
88   struct time alarm;
89   volatile cyg_uint32 preint;
90   volatile cyg_uint32 prefrac;
91 };
92
93 static struct rtcdev * const rtc = 
94   (struct rtcdev *) CYGARC_HAL_LPC2XXX_REG_RTC_BASE;
95
96 void
97 Cyg_WallClock::init_hw_seconds(void)
98 {
99   /* halt clock, disable interrupts, disable alarm */
100   rtc->ccr  = 0x2;
101   rtc->ciir = 0x0;
102   rtc->amr  = 0xf;
103   
104   /* initialize prescaler */
105   rtc->preint  = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT;
106   rtc->prefrac = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREFRAC;
107   
108 #ifndef CYGSEM_WALLCLOCK_SET_GET_MODE
109   /* reset time to the Unix Epoch */
110   rtc->time.year  = 1970;
111   rtc->time.month = 1;
112   rtc->time.dom   = 1;
113   rtc->time.doy   = 1;
114   rtc->time.dow   = 4;
115   rtc->time.hour  = 0;
116   rtc->time.min   = 0;
117   rtc->time.sec   = 0;
118 #endif
119   
120   /* reset alarm */
121   rtc->alarm.year = rtc->alarm.month = rtc->alarm.dom = rtc->alarm.doy =
122     rtc->alarm.dow = rtc->alarm.hour = rtc->alarm.min = 
123     rtc->alarm.sec = 0;
124   
125   /* start clock */
126   rtc->ccr = 0x1;
127 }
128
129 cyg_uint32
130 Cyg_WallClock::get_hw_seconds(void)
131 {
132   return _simple_mktime(rtc->time.year,
133                         rtc->time.month,
134                         rtc->time.dom,
135                         rtc->time.hour,
136                         rtc->time.min,
137                         rtc->time.sec);
138 }
139
140 #ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
141 void
142 Cyg_WallClock::set_hw_seconds(cyg_uint32 secs)
143 {
144   cyg_uint32 year, month, dom, hour, min, sec;
145   
146   /* halt clock, reset counter */
147   rtc->ccr = 0x2;
148   
149   /* set time */
150   _simple_mkdate(secs, &year, &month, &dom, &hour, &min, &sec);
151   rtc->time.year  = year;
152   rtc->time.month = month;
153   rtc->time.dom   = dom;
154   rtc->time.hour  = hour;
155   rtc->time.min   = min;
156   rtc->time.sec   = sec;
157   
158   /* restart clock */
159   rtc->ccr = 0x1;
160 }
161 #endif