source: rtems/c/src/lib/libbsp/arm/lpc32xx/rtc/rtc-config.c @ 3103d4cb

4.115
Last change on this file since 3103d4cb was 3103d4cb, checked in by Sebastian Huber <sebastian.huber@…>, on 06/23/10 at 08:27:57

2010-06-23 Sebastian Huber <sebastian.huber@…>

  • make/custom/lpc32xx_mzx_boot_int.cfg, startup/linkcmds.lpc32xx_mzx_boot_int: Removed files.
  • include/boot.h, include/emc.h, include/i2c.h, include/nand-mlc.h, make/custom/lpc32xx_mzx.cfg, make/custom/lpc32xx_mzx_stage_1.cfg, make/custom/lpc32xx_mzx_stage_2.cfg, misc/boot.c, misc/emc.c, misc/i2c.c, misc/nand-mlc.c, misc/nand-mlc-read-blocks.c, misc/nand-mlc-write-blocks.c, misc/restart.c, startup/linkcmds.lpc32xx, startup/linkcmds.lpc32xx_mzx, startup/linkcmds.lpc32xx_mzx_stage_1, startup/linkcmds.lpc32xx_mzx_stage_2: New files.
  • configure.ac, Makefile.am, preinstall.am: Reflect changes above.
  • include/bsp.h, include/lpc32xx.h, irq/irq.c, rtc/rtc-config.c, startup/bspstart.c, startup/bspstarthooks.c, startup/linkcmds.lpc32xx_phycore: Changes throughout.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc32xx
5 *
6 * @brief RTC configuration.
7 */
8
9/*
10 * Copyright (c) 2009
11 * embedded brains GmbH
12 * Obere Lagerstr. 30
13 * D-82178 Puchheim
14 * Germany
15 * <rtems@embedded-brains.de>
16 *
17 * The license and distribution terms for this file may be
18 * found in the file LICENSE in this distribution or at
19 * http://www.rtems.com/license/LICENSE.
20 */
21
22#include <libchip/rtc.h>
23
24#include <bsp.h>
25#include <bsp/lpc32xx.h>
26
27#define LPC32XX_RTC_COUNT 1U
28
29#define LPC32XX_RTC_COUNTER_DELTA 0xfffffffeU
30
31#define LPC32XX_RTC_KEY 0xb5c13f27U
32
33#define LPC32XX_RTC_CTRL_FORCE_ONSW (1U << 7)
34#define LPC32XX_RTC_CTRL_STOP (1U << 6)
35#define LPC32XX_RTC_CTRL_RESET (1U << 4)
36#define LPC32XX_RTC_CTRL_MATCH_1_ONSW (1U << 3)
37#define LPC32XX_RTC_CTRL_MATCH_0_ONSW (1U << 2)
38#define LPC32XX_RTC_CTRL_MATCH_1_INTR (1U << 1)
39#define LPC32XX_RTC_CTRL_MATCH_0_INTR (1U << 0)
40
41static void lpc32xx_rtc_set(uint32_t val)
42{
43  unsigned i = LPC32XX_ARM_CLK / LPC32XX_OSCILLATOR_RTC;
44
45  lpc32xx.rtc.ctrl |= LPC32XX_RTC_CTRL_STOP;
46  lpc32xx.rtc.ucount = val;
47  lpc32xx.rtc.dcount = LPC32XX_RTC_COUNTER_DELTA - val;
48  lpc32xx.rtc.ctrl &= ~LPC32XX_RTC_CTRL_STOP;
49
50  /* It needs some time before we can read the values back */
51  while (i != 0) {
52    asm volatile ("nop");
53    --i;
54  }
55}
56
57static void lpc32xx_rtc_reset(void)
58{
59  lpc32xx.rtc.ctrl = LPC32XX_RTC_CTRL_RESET;
60  lpc32xx.rtc.ctrl = 0;
61  lpc32xx.rtc.key = LPC32XX_RTC_KEY;
62  lpc32xx_rtc_set(0);
63}
64
65static void lpc32xx_rtc_initialize(int minor)
66{
67  uint32_t up_first = 0;
68  uint32_t up_second = 0;
69  uint32_t down_first = 0;
70  uint32_t down_second = 0;
71
72  if (lpc32xx.rtc.key != LPC32XX_RTC_KEY) {
73    lpc32xx_rtc_reset();
74  }
75
76  do {
77    up_first = lpc32xx.rtc.ucount;
78    down_first = lpc32xx.rtc.dcount;
79    up_second = lpc32xx.rtc.ucount;
80    down_second = lpc32xx.rtc.dcount;
81  } while (up_first != up_second || down_first != down_second);
82
83  if (up_first + down_first != LPC32XX_RTC_COUNTER_DELTA) {
84    lpc32xx_rtc_reset();
85  }
86}
87
88static int lpc32xx_rtc_get_time(int minor, rtems_time_of_day *tod)
89{
90  struct timeval now = {
91    .tv_sec = lpc32xx.rtc.ucount,
92    .tv_usec = 0
93  };
94  struct tm time;
95
96  gmtime_r(&now.tv_sec, &time);
97
98  tod->year   = time.tm_year + 1900;
99  tod->month  = time.tm_mon + 1;
100  tod->day    = time.tm_mday;
101  tod->hour   = time.tm_hour;
102  tod->minute = time.tm_min;
103  tod->second = time.tm_sec;
104  tod->ticks  = 0;
105
106  return RTEMS_SUCCESSFUL;
107}
108
109static int lpc32xx_rtc_set_time(int minor, const rtems_time_of_day *tod)
110{
111  lpc32xx_rtc_set(_TOD_To_seconds(tod));
112
113  return 0;
114}
115
116static bool lpc32xx_rtc_probe(int minor)
117{
118  return true;
119}
120
121const rtc_fns lpc32xx_rtc_ops = {
122  .deviceInitialize = lpc32xx_rtc_initialize,
123  .deviceGetTime = lpc32xx_rtc_get_time,
124  .deviceSetTime = lpc32xx_rtc_set_time
125};
126
127unsigned long RTC_Count = LPC32XX_RTC_COUNT;
128
129rtems_device_minor_number RTC_Minor = 0;
130
131rtc_tbl RTC_Table [LPC32XX_RTC_COUNT] = {
132  {
133    .sDeviceName = "/dev/rtc",
134    .deviceType = RTC_CUSTOM,
135    .pDeviceFns = &lpc32xx_rtc_ops,
136    .deviceProbe = lpc32xx_rtc_probe,
137    .pDeviceParams = NULL,
138    .ulCtrlPort1 = 0,
139    .ulDataPort = 0,
140    .getRegister = NULL,
141    .setRegister = NULL
142  }
143};
Note: See TracBrowser for help on using the repository browser.