Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:03

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsARMLPC24XX
0007  *
0008  * @brief RTC configuration.
0009  */
0010 
0011 /*
0012  * Copyright (c) 2008 embedded brains GmbH & Co. KG
0013  * Redistribution and use in source and binary forms, with or without
0014  * modification, are permitted provided that the following conditions
0015  * are met:
0016  * 1. Redistributions of source code must retain the above copyright
0017  *    notice, this list of conditions and the following disclaimer.
0018  * 2. Redistributions in binary form must reproduce the above copyright
0019  *    notice, this list of conditions and the following disclaimer in the
0020  *    documentation and/or other materials provided with the distribution.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032  * POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #include <libchip/rtc.h>
0036 
0037 #include <bsp/lpc24xx.h>
0038 #include <bsp/io.h>
0039 
0040 #define LPC24XX_RTC_NUMBER 1
0041 
0042 static void lpc24xx_rtc_initialize(int minor)
0043 {
0044   /* Enable module power */
0045   lpc24xx_module_enable(LPC24XX_MODULE_RTC, LPC24XX_MODULE_PCLK_DEFAULT);
0046 
0047   /* Enable the RTC and use external clock */
0048   RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC;
0049 
0050   /* Disable interrupts */
0051   RTC_CIIR = 0;
0052   RTC_CISS = 0;
0053   RTC_AMR = 0xff;
0054 
0055   /* Clear interrupts */
0056   RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF;
0057 }
0058 
0059 static int lpc24xx_rtc_get_time(int minor, rtems_time_of_day *tod)
0060 {
0061   tod->ticks = 0;
0062   tod->second = RTC_SEC;
0063   tod->minute = RTC_MIN;
0064   tod->hour = RTC_HOUR;
0065   tod->day = RTC_DOM;
0066   tod->month = RTC_MONTH;
0067   tod->year = RTC_YEAR;
0068 
0069   return 0;
0070 }
0071 
0072 static int lpc24xx_rtc_set_time(int minor, const rtems_time_of_day *tod)
0073 {
0074   RTC_SEC = tod->second;
0075   RTC_MIN = tod->minute;
0076   RTC_HOUR = tod->hour;
0077   RTC_DOM = tod->day;
0078   RTC_MONTH = tod->month;
0079   RTC_YEAR = tod->year;
0080 
0081   return 0;
0082 }
0083 
0084 static bool lpc24xx_rtc_probe(int minor)
0085 {
0086   return true;
0087 }
0088 
0089 const rtc_fns lpc24xx_rtc_ops = {
0090   .deviceInitialize = lpc24xx_rtc_initialize,
0091   .deviceGetTime = lpc24xx_rtc_get_time,
0092   .deviceSetTime = lpc24xx_rtc_set_time
0093 };
0094 
0095 size_t RTC_Count = LPC24XX_RTC_NUMBER;
0096 
0097 rtc_tbl RTC_Table [LPC24XX_RTC_NUMBER] = {
0098   {
0099     .sDeviceName = "/dev/rtc",
0100     .deviceType = RTC_CUSTOM,
0101     .pDeviceFns = &lpc24xx_rtc_ops,
0102     .deviceProbe = lpc24xx_rtc_probe,
0103     .pDeviceParams = NULL,
0104     .ulCtrlPort1 = 0,
0105     .ulDataPort = 0,
0106     .getRegister = NULL,
0107     .setRegister = NULL
0108   }
0109 };