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 RTEMSBSPsARMLPC176X
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 #include <bsp/io.h>
0037 
0038 #define LPC176X_RTC_NUMBER 1U
0039 
0040 void bsp_rtc_initialize( void );
0041 int bsp_rtc_get_time( rtems_time_of_day *tod );
0042 int bsp_rtc_set_time( const rtems_time_of_day *tod );
0043 bool bsp_rtc_probe( void );
0044 
0045 /**
0046  * @brief Initialize the rtc device.
0047  */
0048 void bsp_rtc_initialize( void )
0049 {
0050   /* Enable module power */
0051   lpc176x_module_enable( LPC176X_MODULE_RTC, LPC176X_MODULE_PCLK_DEFAULT );
0052 
0053   /* Enable the RTC and use external clock */
0054   RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC;
0055 
0056   /* Disable interrupts */
0057   RTC_CIIR = 0U;
0058   RTC_CISS = 0U;
0059   RTC_AMR = 0xFFU;
0060 
0061   /* Clear interrupts */
0062   RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF;
0063 }
0064 
0065 /**
0066  * @brief Gets the information according to the current time.
0067  *
0068  * @param  tod Value to be modified.
0069  * @return  0
0070  */
0071 int bsp_rtc_get_time( rtems_time_of_day *tod )
0072 {
0073   tod->ticks = 0;
0074   tod->second = RTC_SEC;
0075   tod->minute = RTC_MIN;
0076   tod->hour = RTC_HOUR;
0077   tod->day = RTC_DOM;
0078   tod->month = RTC_MONTH;
0079   tod->year = RTC_YEAR;
0080 
0081   return 0;
0082 }
0083 
0084 /**
0085  * @brief Sets the information according to the current time.
0086  *
0087  * @param  tod Value to get the new information.
0088  * @return  0
0089  */
0090 int bsp_rtc_set_time( const rtems_time_of_day *tod )
0091 {
0092   RTC_SEC = tod->second;
0093   RTC_MIN = tod->minute;
0094   RTC_HOUR = tod->hour;
0095   RTC_DOM = tod->day;
0096   RTC_MONTH = tod->month;
0097   RTC_YEAR = tod->year;
0098 
0099   return 0;
0100 }
0101 
0102 /**
0103  * @brief Used to probe. At the moment is not used.
0104  *
0105  * @return true.
0106  */
0107 bool bsp_rtc_probe( void )
0108 {
0109   return true;
0110 }
0111 
0112 /**
0113  * @brief Represents the real time clock options.
0114  */
0115 const rtc_fns lpc176x_rtc_ops = {
0116   .deviceInitialize = (void *) bsp_rtc_initialize,
0117   .deviceGetTime = (void *) bsp_rtc_get_time,
0118   .deviceSetTime = (void *) bsp_rtc_set_time
0119 };
0120 
0121 size_t RTC_Count = LPC176X_RTC_NUMBER;
0122 
0123 /**
0124  * @brief Table to describes the rtc device.
0125  */
0126 rtc_tbl RTC_Table[ LPC176X_RTC_NUMBER ] = {
0127   {
0128     .sDeviceName = "/dev/rtc",
0129     .deviceType = RTC_CUSTOM,
0130     .pDeviceFns = &lpc176x_rtc_ops,
0131     .deviceProbe = (void *) bsp_rtc_probe,
0132     .pDeviceParams = NULL,
0133     .ulCtrlPort1 = 0,
0134     .ulDataPort = 0,
0135     .getRegister = NULL,
0136     .setRegister = NULL
0137   }
0138 };