Mercurial > ecos-v3_0-branch
changeset 2503:a5a6b95de3dc
* lpc2xxx: driver for on-chip RTC unit
| author | asl |
|---|---|
| date | Sat, 12 Jul 2008 15:54:31 +0000 |
| parents | 7b16b2d61ef3 |
| children | b5595b55da6a |
| files | packages/devs/wallclock/arm/lpc2xxx/current/ChangeLog packages/devs/wallclock/arm/lpc2xxx/current/cdl/lpc2xxx_wallclock.cdl packages/devs/wallclock/arm/lpc2xxx/current/src/lpc2xxx_wallclock.cxx |
| diffstat | 3 files changed, 284 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/packages/devs/wallclock/arm/lpc2xxx/current/ChangeLog @@ -0,0 +1,37 @@ +2007-07-12 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> + + * lpc2xxx: driver for on-chip RTC unit + +//=========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc. +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//=========================================================================== + +
new file mode 100644 --- /dev/null +++ b/packages/devs/wallclock/arm/lpc2xxx/current/cdl/lpc2xxx_wallclock.cdl @@ -0,0 +1,86 @@ +# ==================================================================== +# +# lpc2xxx_wallclock.cdl +# +# eCos configuration data for LPC2xxx internal RTC +# +# ==================================================================== +#####ECOSGPLCOPYRIGHTBEGIN#### +## ------------------------------------------- +## This file is part of eCos, the Embedded Configurable Operating System. +## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +## Copyright (C) 2003 Gary Thomas +## Copyright (C) 2004 eCosCentric Ltd +## +## eCos is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free +## Software Foundation; either version 2 or (at your option) any later version. +## +## eCos is distributed in the hope that it will be useful, but WITHOUT ANY +## WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +## for more details. +## +## You should have received a copy of the GNU General Public License along +## with eCos; if not, write to the Free Software Foundation, Inc., +## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +## +## As a special exception, if other files instantiate templates or use macros +## or inline functions from this file, or you compile this file and link it +## with other works to produce a work based on this file, this file does not +## by itself cause the resulting work to be covered by the GNU General Public +## License. However the source code for this file must still be made available +## in accordance with section (3) of the GNU General Public License. +## +## This exception does not invalidate any other reasons why a work based on +## this file might be covered by the GNU General Public License. +## ------------------------------------------- +#####ECOSGPLCOPYRIGHTEND#### +# ==================================================================== +######DESCRIPTIONBEGIN#### +# +# Author(s): Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> +# Contributors: jskov +# Date: 2007-06-19 +# +#####DESCRIPTIONEND#### +# +# ==================================================================== + +cdl_package CYGPKG_DEVICES_WALLCLOCK_ARM_LPC2XXX { + display "LPC2xxx Real-time clock" + description "RTC driver for the LPC2xxx controller" + + parent CYGPKG_IO_WALLCLOCK + active_if CYGPKG_IO_WALLCLOCK + active_if CYGPKG_HAL_ARM_LPC2XXX + + requires { CYGHWR_HAL_ARM_LPC2XXX_IDLE_PWRSAVE == 0 } + compile lpc2xxx_wallclock.cxx + + implements CYGINT_WALLCLOCK_HW_IMPLEMENTATIONS + active_if CYGIMP_WALLCLOCK_HARDWARE + implements CYGINT_WALLCLOCK_SET_GET_MODE_SUPPORTED + + cdl_option CYGIMP_WALLCLOCK_HARDWARE { + parent CYGPKG_IO_WALLCLOCK_IMPLEMENTATION + display "Hardware wallclock" + default_value 1 + implements CYGINT_WALLCLOCK_IMPLEMENTATIONS + } + + cdl_option CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT { + display "RTC prescaler integer portion" + flavor data + calculated { ((CYGNUM_HAL_ARM_LPC2XXX_CLOCK_SPEED / + CYGNUM_HAL_ARM_LPC2XXX_VPBDIV) / 32768) - 1 } + } + + cdl_option CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREFRAC { + display "RTC prescaler fractional portion" + flavor data + calculated { ((CYGNUM_HAL_ARM_LPC2XXX_CLOCK_SPEED / + CYGNUM_HAL_ARM_LPC2XXX_VPBDIV) - + ((CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT + 1) * 32768)) } + } +}
new file mode 100644 --- /dev/null +++ b/packages/devs/wallclock/arm/lpc2xxx/current/src/lpc2xxx_wallclock.cxx @@ -0,0 +1,161 @@ +//========================================================================== +// +// lpc2xxx_wallclock.cxx +// +// Wallclock implementation for LPC2xxx +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2003 Gary Thomas +// Copyright (C) 2004 eCosCentric Ltd +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> +// Contributors: +// Date: 2007-06-19 +// Purpose: Wallclock driver for LPC2xxx +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/hal.h> +#include <pkgconf/wallclock.h> +#include <pkgconf/devices_wallclock_arm_lpc2xxx.h> + +#include <cyg/hal/hal_io.h> +#include <cyg/hal/hal_intr.h> +#include <cyg/infra/cyg_type.h> + +#include <cyg/io/wallclock.hxx> +#include <cyg/io/wallclock/wallclock.inl> + +/* + * I don't like to write LOTS OF CAPITALIZED TEXT. + * This code is intended for LPC2xxx processors _only_, so there is nothing + * wrong with accessing this device directly without using the HAL macros. + */ + +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; + volatile cyg_uint32 preint; + volatile cyg_uint32 prefrac; +}; + +static struct rtcdev * const rtc = + (struct rtcdev *) CYGARC_HAL_LPC2XXX_REG_RTC_BASE; + +void +Cyg_WallClock::init_hw_seconds(void) +{ + /* halt clock, disable interrupts, disable alarm */ + rtc->ccr = 0x2; + rtc->ciir = 0x0; + rtc->amr = 0xf; + + /* initialize prescaler */ + rtc->preint = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREINT; + rtc->prefrac = CYGNUM_HAL_ARM_LPC2XXX_RTCDEV_PREFRAC; + +#ifndef CYGSEM_WALLCLOCK_SET_GET_MODE + /* reset time to the Unix Epoch */ + rtc->time.year = 1970; + rtc->time.month = 1; + rtc->time.dom = 1; + rtc->time.doy = 1; + rtc->time.dow = 4; + rtc->time.hour = 0; + rtc->time.min = 0; + rtc->time.sec = 0; +#endif + + /* reset alarm */ + rtc->alarm.year = rtc->alarm.month = rtc->alarm.dom = rtc->alarm.doy = + rtc->alarm.dow = rtc->alarm.hour = rtc->alarm.min = + rtc->alarm.sec = 0; + + /* start clock */ + rtc->ccr = 0x1; +} + +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); +} + +#ifdef CYGSEM_WALLCLOCK_SET_GET_MODE +void +Cyg_WallClock::set_hw_seconds(cyg_uint32 secs) +{ + cyg_uint32 year, month, dom, hour, min, sec; + + /* halt clock, reset counter */ + rtc->ccr = 0x2; + + /* set time */ + _simple_mkdate(secs, &year, &month, &dom, &hour, &min, &sec); + rtc->time.year = year; + rtc->time.month = month; + rtc->time.dom = dom; + rtc->time.hour = hour; + rtc->time.min = min; + rtc->time.sec = sec; + + /* restart clock */ + rtc->ccr = 0x1; +} +#endif
