source: rtems/bsps/arm/lpc24xx/rtc/rtc-config.c @ 445ddb3

Last change on this file since 445ddb3 was 445ddb3, checked in by Joel Sherrill <joel@…>, on 06/27/22 at 13:48:16

bsps/arm/lpc24xx: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSBSPsARMLPC24XX
7 *
8 * @brief RTC configuration.
9 */
10
11/*
12 * Copyright (c) 2008 embedded brains GmbH.  All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <libchip/rtc.h>
36
37#include <bsp/lpc24xx.h>
38#include <bsp/io.h>
39
40#define LPC24XX_RTC_NUMBER 1
41
42static void lpc24xx_rtc_initialize(int minor)
43{
44  /* Enable module power */
45  lpc24xx_module_enable(LPC24XX_MODULE_RTC, LPC24XX_MODULE_PCLK_DEFAULT);
46
47  /* Enable the RTC and use external clock */
48  RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC;
49
50  /* Disable interrupts */
51  RTC_CIIR = 0;
52  RTC_CISS = 0;
53  RTC_AMR = 0xff;
54
55  /* Clear interrupts */
56  RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF;
57}
58
59static int lpc24xx_rtc_get_time(int minor, rtems_time_of_day *tod)
60{
61  tod->ticks = 0;
62  tod->second = RTC_SEC;
63  tod->minute = RTC_MIN;
64  tod->hour = RTC_HOUR;
65  tod->day = RTC_DOM;
66  tod->month = RTC_MONTH;
67  tod->year = RTC_YEAR;
68
69  return 0;
70}
71
72static int lpc24xx_rtc_set_time(int minor, const rtems_time_of_day *tod)
73{
74  RTC_SEC = tod->second;
75  RTC_MIN = tod->minute;
76  RTC_HOUR = tod->hour;
77  RTC_DOM = tod->day;
78  RTC_MONTH = tod->month;
79  RTC_YEAR = tod->year;
80
81  return 0;
82}
83
84static bool lpc24xx_rtc_probe(int minor)
85{
86  return true;
87}
88
89const rtc_fns lpc24xx_rtc_ops = {
90  .deviceInitialize = lpc24xx_rtc_initialize,
91  .deviceGetTime = lpc24xx_rtc_get_time,
92  .deviceSetTime = lpc24xx_rtc_set_time
93};
94
95size_t RTC_Count = LPC24XX_RTC_NUMBER;
96
97rtc_tbl RTC_Table [LPC24XX_RTC_NUMBER] = {
98  {
99    .sDeviceName = "/dev/rtc",
100    .deviceType = RTC_CUSTOM,
101    .pDeviceFns = &lpc24xx_rtc_ops,
102    .deviceProbe = lpc24xx_rtc_probe,
103    .pDeviceParams = NULL,
104    .ulCtrlPort1 = 0,
105    .ulDataPort = 0,
106    .getRegister = NULL,
107    .setRegister = NULL
108  }
109};
Note: See TracBrowser for help on using the repository browser.