summaryrefslogtreecommitdiff
path: root/components/drivers/rtc/rtc.c
diff options
context:
space:
mode:
authortyx <[email protected]>2022-04-04 23:41:13 +0800
committerguo <[email protected]>2022-04-06 10:26:04 +0800
commit8a7babadda7008f1f057dd373e32294482012a6e (patch)
tree1d8817375bc69869105a082aa5302e9743537d3b /components/drivers/rtc/rtc.c
parent9a4bd201496c5775c0ad93995c244320bd7d1f2a (diff)
[drivers][rtc]Add get/set timestamp function
Diffstat (limited to 'components/drivers/rtc/rtc.c')
-rw-r--r--components/drivers/rtc/rtc.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c
index cd1d861939..85e5c75020 100644
--- a/components/drivers/rtc/rtc.c
+++ b/components/drivers/rtc/rtc.c
@@ -228,6 +228,49 @@ rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second)
return ret;
}
+/**
+ * Set timestamp(utc).
+ *
+ * @param time_t timestamp
+ *
+ * @return rt_err_t if set success, return RT_EOK.
+ */
+rt_err_t set_timestamp(time_t timestamp)
+{
+ if (_rtc_device == RT_NULL)
+ {
+ _rtc_device = rt_device_find("rtc");
+ if (_rtc_device == RT_NULL)
+ {
+ return -RT_ERROR;
+ }
+ }
+
+ /* update to RTC device. */
+ return rt_device_control(_rtc_device, RT_DEVICE_CTRL_RTC_SET_TIME, &timestamp);
+}
+
+/**
+ * Get timestamp(utc).
+ *
+ * @param time_t* timestamp
+ *
+ * @return rt_err_t if set success, return RT_EOK.
+ */
+rt_err_t get_timestamp(time_t *timestamp)
+{
+ if (_rtc_device == RT_NULL)
+ {
+ _rtc_device = rt_device_find("rtc");
+ if (_rtc_device == RT_NULL)
+ {
+ return -RT_ERROR;
+ }
+ }
+
+ /* Get timestamp from RTC device. */
+ return rt_device_control(_rtc_device, RT_DEVICE_CTRL_RTC_GET_TIME, timestamp);
+}
#ifdef RT_USING_FINSH
#include <finsh.h>