Hardware Abstraction Layer for FreeRTOS
rtc.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: Andreas Werner <kernel@andy89.org>
4  * Date: 2016
5  */
6 #ifndef RTC_H_
7 #define RTC_H_
8 #include <FreeRTOS.h>
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <system.h>
12 #include <semphr.h>
13 #include <hal.h>
27 struct rtc;
28 #ifdef CONFIG_RTC_MULTI
29 
32 struct rtc_ops {
33  struct rtc *(*rtc_init)(uint32_t index);
34  int32_t (*rtc_deinit)(struct rtc *rtc);
35  int32_t (*rtc_adjust)(struct rtc *rtc, struct timespec *offset, TickType_t waittime);
36  int32_t (*rtc_getTime)(struct rtc *rtc, struct timespec *time, TickType_t waittime);
37  int32_t (*rtc_setTime)(struct rtc *rtc, struct timespec *time, TickType_t waittime);
38  int32_t (*rtc_adjustISR)(struct rtc *rtc, struct timespec *offset);
39  int32_t (*rtc_getTimeISR)(struct rtc *rtc, struct timespec *time);
40  int32_t (*rtc_setTimeISR)(struct rtc *rtc, struct timespec *time);
41 };
42 #endif
43 
53 struct rtc_generic {
58  bool init;
59 #ifdef CONFIG_INSTANCE_NAME
60 
63  const char *name;
64 #endif
65 #ifdef CONFIG_RTC_THREAD_SAVE
66 
70 #endif
71 #ifdef CONFIG_RTC_MULTI
72 
75  const struct rtc_ops *ops;
76 #endif
77 };
78 #ifdef CONFIG_NEWLIB
79 #include <time.h>
80 #include <sys/time.h>
81 #else
82 #include <stdint.h>
83 typedef int64_t time_t;
87 struct timespec {
95  int64_t tv_nsec;
96 };
97 #endif
98 #ifndef CONFIG_RTC_MULTI
99 
104 struct rtc *rtc_init(uint32_t index);
110 int32_t rtc_deinit(struct rtc *rtc);
111 int32_t rtc_adjust(struct rtc *rtc, struct timespec *offset, TickType_t waittime);
112 int32_t rtc_getTime(struct rtc *rtc, struct timespec *time, TickType_t waittime);
113 int32_t rtc_setTime(struct rtc *rtc, struct timespec *time, TickType_t waittime);
114 int32_t rtc_adjustISR(struct rtc *rtc, struct timespec *offset);
115 int32_t rtc_getTimeISR(struct rtc *rtc, struct timespec *time);
116 int32_t rtc_setTimeISR(struct rtc *rtc, struct timespec *time);
117 #else
118 inline struct rtc *rtc_init(uint32_t index) {
120  struct rtc_generic *p = (struct rtc_generic *) HAL_GET_DEV(rtc, index);
121  if (p == NULL) {
122  return NULL;
123  }
124  return p->ops->rtc_init(index);
125 }
126 inline int32_t rtc_deinit(struct rtc *rtc) {
127  struct rtc_generic *p = (struct rtc_generic *) rtc;
128  return p->ops->rtc_deinit(rtc);
129 }
130 inline int32_t rtc_adjust(struct rtc *rtc, struct timespec *offset, TickType_t waittime) {
131  struct rtc_generic *p = (struct rtc_generic *) rtc;
132  return p->ops->rtc_adjust(rtc, offset, waittime);
133 }
134 inline int32_t rtc_getTime(struct rtc *rtc, struct timespec *time, TickType_t waittime) {
135  struct rtc_generic *p = (struct rtc_generic *) rtc;
136  return p->ops->rtc_getTime(rtc, time, waittime);
137 }
138 inline int32_t rtc_setTime(struct rtc *rtc, struct timespec *time, TickType_t waittime) {
139  struct rtc_generic *p = (struct rtc_generic *) rtc;
140  return p->ops->rtc_setTime(rtc, time, waittime);
141 }
142 inline int32_t rtc_adjustISR(struct rtc *rtc, struct timespec *offset) {
143  struct rtc_generic *p = (struct rtc_generic *) rtc;
144  return p->ops->rtc_adjustISR(rtc, offset);
145 }
146 inline int32_t rtc_getTimeISR(struct rtc *rtc, struct timespec *time) {
147  struct rtc_generic *p = (struct rtc_generic *) rtc;
148  return p->ops->rtc_getTimeISR(rtc, time);
149 }
150 inline int32_t rtc_setTimeISR(struct rtc *rtc, struct timespec *time) {
151  struct rtc_generic *p = (struct rtc_generic *) rtc;
152  return p->ops->rtc_setTimeISR(rtc, time);
153 }
154 #endif
155 
156 #endif
157 
rtc_init
struct rtc * rtc_init(uint32_t index)
timespec::tv_nsec
int64_t tv_nsec
Definition: rtc.h:95
rtc_getTimeISR
int32_t rtc_getTimeISR(struct rtc *rtc, struct timespec *time)
OS_DEFINE_MUTEX_RECURSIVE
#define OS_DEFINE_MUTEX_RECURSIVE(name)
Definition: os.h:59
hal.h
rtc_deinit
int32_t rtc_deinit(struct rtc *rtc)
HAL_DEFINE_GLOBAL_ARRAY
#define HAL_DEFINE_GLOBAL_ARRAY(gns)
Definition: hal.h:149
rtc_adjustISR
int32_t rtc_adjustISR(struct rtc *rtc, struct timespec *offset)
rtc_getTime
int32_t rtc_getTime(struct rtc *rtc, struct timespec *time, TickType_t waittime)
rtc_adjust
int32_t rtc_adjust(struct rtc *rtc, struct timespec *offset, TickType_t waittime)
timespec::tv_sec
time_t tv_sec
Definition: rtc.h:91
HAL_GET_DEV
#define HAL_GET_DEV(gns, index)
Definition: hal.h:182
rtc_setTimeISR
int32_t rtc_setTimeISR(struct rtc *rtc, struct timespec *time)
rtc_generic::init
bool init
Definition: rtc.h:58
rtc_generic
Definition: rtc.h:53
system.h
timespec
Definition: rtc.h:87
time_t
int64_t time_t
Definition: rtc.h:83
rtc_setTime
int32_t rtc_setTime(struct rtc *rtc, struct timespec *time, TickType_t waittime)