1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// lpc2xxx_wallclock.cxx
|
4 |
|
|
//
|
5 |
|
|
// Wallclock implementation for LPC2xxx and LPC17xx CPUs
|
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, 2003, 2004 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on 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: Uwe Kindler <uwe_kindler@web.de, ilijak
|
44 |
|
|
// Date: 2007-06-19
|
45 |
|
|
// Purpose: Wallclock driver for LPC2xxx and LPC17xx CPUs
|
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 |
|
|
// The LPC2xxx variant HAL provides the CPU clock and the peripheral divider
|
64 |
|
|
// VPBDIV. The LPC24xx variant HAL provides the RTC clock directly be means
|
65 |
|
|
// of CYGNUM_HAL_ARM_LPC24XX_RTC_CLK.
|
66 |
|
|
//
|
67 |
|
|
#ifdef CYGNUM_HAL_ARM_LPC2XXX_VPBDIV
|
68 |
|
|
#define LPC2XXX_RTC_CLK (CYGNUM_HAL_ARM_LPC2XXX_CLOCK_SPEED / \
|
69 |
|
|
CYGNUM_HAL_ARM_LPC2XXX_VPBDIV)
|
70 |
|
|
#endif // CYGNUM_HAL_ARM_LPC2XXX_VPBDIV
|
71 |
|
|
|
72 |
|
|
#ifdef CYGNUM_HAL_ARM_LPC24XX_RTC_CLK
|
73 |
|
|
#define LPC2XXX_RTC_CLK (CYGNUM_HAL_ARM_LPC24XX_RTC_CLK)
|
74 |
|
|
#endif // CYGNUM_HAL_ARM_LPC2XXX_VPBDIV
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
#define CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT \
|
78 |
|
|
((LPC2XXX_RTC_CLK / 32768) - 1)
|
79 |
|
|
|
80 |
|
|
#define CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREFRAC \
|
81 |
|
|
(LPC2XXX_RTC_CLK - \
|
82 |
|
|
((CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT + 1) * 32768))
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/*
|
87 |
|
|
* I don't like to write LOTS OF CAPITALIZED TEXT.
|
88 |
|
|
* This code is intended for LPC2xxx processors _only_, so there is nothing
|
89 |
|
|
* wrong with accessing this device directly without using the HAL macros.
|
90 |
|
|
*/
|
91 |
|
|
|
92 |
|
|
struct time {
|
93 |
|
|
volatile cyg_uint32 sec;
|
94 |
|
|
volatile cyg_uint32 min;
|
95 |
|
|
volatile cyg_uint32 hour;
|
96 |
|
|
volatile cyg_uint32 dom;
|
97 |
|
|
volatile cyg_uint32 dow;
|
98 |
|
|
volatile cyg_uint32 doy;
|
99 |
|
|
volatile cyg_uint32 month;
|
100 |
|
|
volatile cyg_uint32 year;
|
101 |
|
|
};
|
102 |
|
|
|
103 |
|
|
struct rtcdev {
|
104 |
|
|
volatile cyg_uint32 ilr;
|
105 |
|
|
volatile cyg_uint32 ctc;
|
106 |
|
|
volatile cyg_uint32 ccr;
|
107 |
|
|
volatile cyg_uint32 ciir;
|
108 |
|
|
volatile cyg_uint32 amr;
|
109 |
|
|
volatile cyg_uint32 ctime[3];
|
110 |
|
|
struct time time;
|
111 |
|
|
cyg_uint32 dummy[8];
|
112 |
|
|
struct time alarm;
|
113 |
|
|
#ifndef CYGHWR_HAL_LPC_RTC_32768HZ
|
114 |
|
|
volatile cyg_uint32 preint;
|
115 |
|
|
volatile cyg_uint32 prefrac;
|
116 |
|
|
#endif
|
117 |
|
|
};
|
118 |
|
|
|
119 |
|
|
static struct rtcdev * const rtc =
|
120 |
|
|
(struct rtcdev *) CYGARC_HAL_LPC2XXX_REG_RTC_BASE;
|
121 |
|
|
|
122 |
|
|
void
|
123 |
|
|
Cyg_WallClock::init_hw_seconds(void)
|
124 |
|
|
{
|
125 |
|
|
/* halt clock, disable interrupts, disable alarm */
|
126 |
|
|
rtc->ccr = 0x2;
|
127 |
|
|
rtc->ciir = 0x0;
|
128 |
|
|
rtc->amr = 0xf;
|
129 |
|
|
|
130 |
|
|
// initialize prescaler - if the RTC id driven by an external 32.768 crystal
|
131 |
|
|
// clock then initializing the prescaler is not required but writing the
|
132 |
|
|
// registers here should not cause any trouble
|
133 |
|
|
#ifndef CYGHWR_HAL_LPC_RTC_32768HZ
|
134 |
|
|
rtc->preint = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT;
|
135 |
|
|
rtc->prefrac = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREFRAC;
|
136 |
|
|
#endif
|
137 |
|
|
|
138 |
|
|
#ifndef CYGSEM_WALLCLOCK_SET_GET_MODE
|
139 |
|
|
/* reset time to the Unix Epoch */
|
140 |
|
|
rtc->time.year = 1970;
|
141 |
|
|
rtc->time.month = 1;
|
142 |
|
|
rtc->time.dom = 1;
|
143 |
|
|
rtc->time.doy = 1;
|
144 |
|
|
rtc->time.dow = 4;
|
145 |
|
|
rtc->time.hour = 0;
|
146 |
|
|
rtc->time.min = 0;
|
147 |
|
|
rtc->time.sec = 0;
|
148 |
|
|
#endif
|
149 |
|
|
|
150 |
|
|
/* reset alarm */
|
151 |
|
|
rtc->alarm.year = rtc->alarm.month = rtc->alarm.dom = rtc->alarm.doy =
|
152 |
|
|
rtc->alarm.dow = rtc->alarm.hour = rtc->alarm.min =
|
153 |
|
|
rtc->alarm.sec = 0;
|
154 |
|
|
|
155 |
|
|
/* start clock */
|
156 |
|
|
rtc->ccr = 0x1;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
cyg_uint32
|
160 |
|
|
Cyg_WallClock::get_hw_seconds(void)
|
161 |
|
|
{
|
162 |
|
|
return _simple_mktime(rtc->time.year,
|
163 |
|
|
rtc->time.month,
|
164 |
|
|
rtc->time.dom,
|
165 |
|
|
rtc->time.hour,
|
166 |
|
|
rtc->time.min,
|
167 |
|
|
rtc->time.sec);
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE
|
171 |
|
|
void
|
172 |
|
|
Cyg_WallClock::set_hw_seconds(cyg_uint32 secs)
|
173 |
|
|
{
|
174 |
|
|
cyg_uint32 year, month, dom, hour, min, sec;
|
175 |
|
|
|
176 |
|
|
/* halt clock, reset counter */
|
177 |
|
|
rtc->ccr = 0x2;
|
178 |
|
|
|
179 |
|
|
/* set time */
|
180 |
|
|
_simple_mkdate(secs, &year, &month, &dom, &hour, &min, &sec);
|
181 |
|
|
rtc->time.year = year;
|
182 |
|
|
rtc->time.month = month;
|
183 |
|
|
rtc->time.dom = dom;
|
184 |
|
|
rtc->time.hour = hour;
|
185 |
|
|
rtc->time.min = min;
|
186 |
|
|
rtc->time.sec = sec;
|
187 |
|
|
|
188 |
|
|
/* restart clock */
|
189 |
|
|
rtc->ccr = 0x1;
|
190 |
|
|
}
|
191 |
|
|
#endif // CYGSEM_WALLCLOCK_SET_GET_MODE
|
192 |
|
|
|
193 |
|
|
//==========================================================================
|
194 |
|
|
// EOF lpc2xxx_wallclock.cxx
|