Skip to content
Snippets Groups Projects
Commit e94f7bf9 authored by Ferdinand Bachmann's avatar Ferdinand Bachmann
Browse files

epicardium/rtc: add monotonic time

parent 612772fa
No related branches found
No related tags found
No related merge requests found
...@@ -81,6 +81,8 @@ typedef _Bool bool; ...@@ -81,6 +81,8 @@ typedef _Bool bool;
#define API_RTC_SCHEDULE_ALARM 0x51 #define API_RTC_SCHEDULE_ALARM 0x51
#define API_RTC_SET_MILLISECONDS 0x52 #define API_RTC_SET_MILLISECONDS 0x52
#define API_RTC_GET_MILLISECONDS 0x53 #define API_RTC_GET_MILLISECONDS 0x53
#define API_RTC_GET_MONOTONIC_SECONDS 0x54
#define API_RTC_GET_MONOTONIC_MILLISECONDS 0x55
#define API_LEDS_SET 0x60 #define API_LEDS_SET 0x60
#define API_LEDS_SET_HSV 0x61 #define API_LEDS_SET_HSV 0x61
...@@ -1693,6 +1695,24 @@ API(API_FILE_MKDIR, int epic_file_mkdir(const char *dirname)); ...@@ -1693,6 +1695,24 @@ API(API_FILE_MKDIR, int epic_file_mkdir(const char *dirname));
* === * ===
*/ */
/**
* Get the monotonic time in seconds.
*
* :return: monotonic time in seconds
*/
API(API_RTC_GET_MONOTONIC_SECONDS,
uint32_t epic_rtc_get_monotonic_seconds(void)
);
/**
* Get the monotonic time in ms.
*
* :return: monotonic time in milliseconds
*/
API(API_RTC_GET_MONOTONIC_MILLISECONDS,
uint64_t epic_rtc_get_monotonic_milliseconds(void)
);
/** /**
* Read the current RTC value. * Read the current RTC value.
* *
......
...@@ -9,6 +9,18 @@ ...@@ -9,6 +9,18 @@
#include <stdint.h> #include <stdint.h>
uint64_t monotonic_offset = 0;
uint32_t epic_rtc_get_monotonic_seconds(void)
{
return epic_rtc_get_seconds() + monotonic_offset / 1000ULL;
}
uint64_t epic_rtc_get_monotonic_milliseconds(void)
{
return epic_rtc_get_milliseconds() + monotonic_offset;
}
uint32_t epic_rtc_get_seconds(void) uint32_t epic_rtc_get_seconds(void)
{ {
uint32_t sec, subsec; uint32_t sec, subsec;
...@@ -38,6 +50,9 @@ uint64_t epic_rtc_get_milliseconds(void) ...@@ -38,6 +50,9 @@ uint64_t epic_rtc_get_milliseconds(void)
void epic_rtc_set_milliseconds(uint64_t milliseconds) void epic_rtc_set_milliseconds(uint64_t milliseconds)
{ {
uint32_t sec, subsec; uint32_t sec, subsec;
uint64_t old_milliseconds, new_milliseconds, diff;
old_milliseconds = epic_rtc_get_milliseconds();
sec = milliseconds / 1000; sec = milliseconds / 1000;
subsec = (milliseconds % 1000); subsec = (milliseconds % 1000);
...@@ -48,6 +63,11 @@ void epic_rtc_set_milliseconds(uint64_t milliseconds) ...@@ -48,6 +63,11 @@ void epic_rtc_set_milliseconds(uint64_t milliseconds)
; ;
while (RTC_EnableRTCE(MXC_RTC) == E_BUSY) while (RTC_EnableRTCE(MXC_RTC) == E_BUSY)
; ;
new_milliseconds = epic_rtc_get_milliseconds();
diff = old_milliseconds - new_milliseconds;
monotonic_offset += diff;
} }
void RTC_IRQHandler(void) void RTC_IRQHandler(void)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment