source: rtems/c/src/lib/libbsp/arm/lpc176x/rtc/rtc-config.c @ 1c0663b4

4.115
Last change on this file since 1c0663b4 was d4edbdbc, checked in by Sebastian Huber <sebastian.huber@…>, on 03/20/15 at 13:09:26

Replace www.rtems.com with www.rtems.org

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup lpc176x
5 *
6 * @brief RTC configuration.
7 */
8
9/*
10 * Copyright (c) 2008
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.org/license/LICENSE.
20 */
21
22#include <libchip/rtc.h>
23#include <bsp/io.h>
24
25#define LPC176X_RTC_NUMBER 1U
26
27void bsp_rtc_initialize( void );
28int bsp_rtc_get_time( rtems_time_of_day *tod );
29int bsp_rtc_set_time( const rtems_time_of_day *tod );
30bool bsp_rtc_probe( void );
31
32/**
33 * @brief Initialize the rtc device.
34 */
35void bsp_rtc_initialize( void )
36{
37  /* Enable module power */
38  lpc176x_module_enable( LPC176X_MODULE_RTC, LPC176X_MODULE_PCLK_DEFAULT );
39
40  /* Enable the RTC and use external clock */
41  RTC_CCR = RTC_CCR_CLKEN | RTC_CCR_CLKSRC;
42
43  /* Disable interrupts */
44  RTC_CIIR = 0U;
45  RTC_CISS = 0U;
46  RTC_AMR = 0xFFU;
47
48  /* Clear interrupts */
49  RTC_ILR = RTC_ILR_RTCCIF | RTC_ILR_RTCALF | RTC_ILR_RTSSF;
50}
51
52/**
53 * @brief Gets the information according to the current time.
54 *
55 * @param  tod Value to be modified.
56 * @return  0
57 */
58int bsp_rtc_get_time( rtems_time_of_day *tod )
59{
60  tod->ticks = 0;
61  tod->second = RTC_SEC;
62  tod->minute = RTC_MIN;
63  tod->hour = RTC_HOUR;
64  tod->day = RTC_DOM;
65  tod->month = RTC_MONTH;
66  tod->year = RTC_YEAR;
67
68  return 0;
69}
70
71/**
72 * @brief Sets the information according to the current time.
73 *
74 * @param  tod Value to get the new information.
75 * @return  0
76 */
77int bsp_rtc_set_time( const rtems_time_of_day *tod )
78{
79  RTC_SEC = tod->second;
80  RTC_MIN = tod->minute;
81  RTC_HOUR = tod->hour;
82  RTC_DOM = tod->day;
83  RTC_MONTH = tod->month;
84  RTC_YEAR = tod->year;
85
86  return 0;
87}
88
89/**
90 * @brief Used to probe. At the moment is not used.
91 *
92 * @return true.
93 */
94bool bsp_rtc_probe( void )
95{
96  return true;
97}
98
99/**
100 * @brief Represents the real time clock options.
101 */
102const rtc_fns lpc176x_rtc_ops = {
103  .deviceInitialize = (void *) bsp_rtc_initialize,
104  .deviceGetTime = (void *) bsp_rtc_get_time,
105  .deviceSetTime = (void *) bsp_rtc_set_time
106};
107
108size_t RTC_Count = LPC176X_RTC_NUMBER;
109
110rtems_device_minor_number RTC_Minor = 0;
111
112/**
113 * @brief Table to describes the rtc device.
114 */
115rtc_tbl RTC_Table[ LPC176X_RTC_NUMBER ] = {
116  {
117    .sDeviceName = "/dev/rtc",
118    .deviceType = RTC_CUSTOM,
119    .pDeviceFns = &lpc176x_rtc_ops,
120    .deviceProbe = (void *) bsp_rtc_probe,
121    .pDeviceParams = NULL,
122    .ulCtrlPort1 = 0,
123    .ulDataPort = 0,
124    .getRegister = NULL,
125    .setRegister = NULL
126  }
127};
Note: See TracBrowser for help on using the repository browser.