ChibiOS/HAL  6.1.0
hal_rtc_lld.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  Concepts and parts of this file have been contributed by Uladzimir Pylinsky
18  aka barthess.
19  */
20 
21 /**
22  * @file hal_rtc_lld.h
23  * @brief PLATFORM RTC subsystem low level driver header.
24  *
25  * @addtogroup RTC
26  * @{
27  */
28 
29 #ifndef HAL_RTC_LLD_H
30 #define HAL_RTC_LLD_H
31 
32 #if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
33 
34 /*===========================================================================*/
35 /* Driver constants. */
36 /*===========================================================================*/
37 
38 /**
39  * @name Implementation capabilities
40  */
41 /**
42  * @brief Callback support int the driver.
43  */
44 #define RTC_SUPPORTS_CALLBACKS TRUE
45 
46 /**
47  * @brief Number of alarms available.
48  */
49 #define RTC_ALARMS 2
50 
51 /**
52  * @brief Presence of a local persistent storage.
53  */
54 #define RTC_HAS_STORAGE FALSE
55 /** @} */
56 
57 /*===========================================================================*/
58 /* Driver pre-compile time settings. */
59 /*===========================================================================*/
60 
61 /**
62  * @name PLATFORM configuration options
63  * @{
64  */
65 /**
66  * @brief RTCD1 driver enable switch.
67  * @details If set to @p TRUE the support for RTC1 is included.
68  * @note The default is @p FALSE.
69  */
70 #if !defined(PLATFORM_RTC_USE_RTC1) || defined(__DOXYGEN__)
71 #define PLATFORM_RTC_USE_RTC1 FALSE
72 #endif
73 /** @} */
74 
75 /*===========================================================================*/
76 /* Derived constants and error checks. */
77 /*===========================================================================*/
78 
79 /*===========================================================================*/
80 /* Driver data structures and types. */
81 /*===========================================================================*/
82 
83 /**
84  * @brief FileStream specific methods.
85  */
86 #define _rtc_driver_methods \
87  _file_stream_methods
88 
89 /**
90  * @brief Type of an RTC alarm number.
91  */
92 typedef uint32_t rtcalarm_t;
93 
94 #if (RTC_SUPPORTS_CALLBACKS == TRUE) || defined(__DOXYGEN__)
95 /**
96  * @brief Type of an RTC event.
97  */
98 typedef enum {
99  RTC_EVENT_SECOND = 0 /** Triggered every second. */
100 } rtcevent_t;
101 
102 /**
103  * @brief Type of a generic RTC callback.
104  */
105 typedef void (*rtccb_t)(RTCDriver *rtcp, rtcevent_t event);
106 #endif
107 
108 /**
109  * @brief Type of a structure representing an RTC alarm time stamp.
110  */
111 typedef struct {
112  /* End of the mandatory fields.*/
113  uint32_t dummy;
114 } RTCAlarm;
115 
116 #if (RTC_HAS_STORAGE == TRUE) || defined(__DOXYGEN__)
117 /**
118  * @extends FileStream
119  *
120  * @brief @p RTCDriver virtual methods table.
121  */
122 struct RTCDriverVMT {
124 };
125 #endif
126 
127 /**
128  * @brief Structure representing an RTC driver.
129  */
130 struct RTCDriver {
131 #if (RTC_HAS_STORAGE == TRUE) || defined(__DOXYGEN__)
132  /**
133  * @brief Virtual Methods Table.
134  */
135  const struct RTCDriverVMT *vmt;
136 #endif
137  /* End of the mandatory fields.*/
138  uint32_t dummy;
139 };
140 
141 /*===========================================================================*/
142 /* Driver macros. */
143 /*===========================================================================*/
144 
145 /*===========================================================================*/
146 /* External declarations. */
147 /*===========================================================================*/
148 
149 #if (PLATFORM_RTC_USE_RTC1 == TRUE) && !defined(__DOXYGEN__)
150 extern RTCDriver RTCD1;
151 #endif
152 
153 #if (RTC_HAS_STORAGE == TRUE) && !defined(__DOXYGEN__)
154 extern struct RTCDriverVMT _rtc_lld_vmt;
155 #endif
156 
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160  void rtc_lld_init(void);
161  void rtc_lld_set_time(RTCDriver *rtcp, const RTCDateTime *timespec);
162  void rtc_lld_get_time(RTCDriver *rtcp, RTCDateTime *timespec);
163 #if RTC_ALARMS > 0
164  void rtc_lld_set_alarm(RTCDriver *rtcp,
165  rtcalarm_t alarm,
166  const RTCAlarm *alarmspec);
167  void rtc_lld_get_alarm(RTCDriver *rtcp,
168  rtcalarm_t alarm,
169  RTCAlarm *alarmspec);
170 #endif
171 #if RTC_SUPPORTS_CALLBACKS == TRUE
172  void rtc_lld_set_callback(RTCDriver *rtcp, rtccb_t callback);
173 #endif
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif /* HAL_USE_RTC == TRUE */
179 
180 #endif /* HAL_RTC_LLD_H */
181 
182 /** @} */
void rtc_lld_get_time(RTCDriver *rtcp, RTCDateTime *timespec)
Get current time.
Definition: hal_rtc_lld.c:103
RTCDriver virtual methods table.
Definition: hal_rtc_lld.h:122
void rtc_lld_set_alarm(RTCDriver *rtcp, rtcalarm_t alarm, const RTCAlarm *alarmspec)
Set alarm time.
Definition: hal_rtc_lld.c:122
rtcevent_t
Type of an RTC event.
Definition: hal_rtc_lld.h:98
Type of a structure representing an RTC alarm time stamp.
Definition: hal_rtc_lld.h:111
void rtc_lld_init(void)
RTC driver identifier.
Definition: hal_rtc_lld.c:69
void rtc_lld_get_alarm(RTCDriver *rtcp, rtcalarm_t alarm, RTCAlarm *alarmspec)
Get alarm time.
Definition: hal_rtc_lld.c:141
uint32_t rtcalarm_t
Type of an RTC alarm number.
Definition: hal_rtc_lld.h:92
Type of a structure representing an RTC date/time stamp.
Definition: hal_rtc.h:93
const struct RTCDriverVMT * vmt
Virtual Methods Table.
Definition: hal_rtc_lld.h:135
void rtc_lld_set_time(RTCDriver *rtcp, const RTCDateTime *timespec)
Set current time.
Definition: hal_rtc_lld.c:88
Structure representing an RTC driver.
Definition: hal_rtc_lld.h:130
void(* rtccb_t)(RTCDriver *rtcp, rtcevent_t event)
Type of a generic RTC callback.
Definition: hal_rtc_lld.h:105
#define _rtc_driver_methods
FileStream specific methods.
Definition: hal_rtc_lld.h:86