Skip to content
Snippets Groups Projects
Commit da4d936e authored by Hauke Mehrtens's avatar Hauke Mehrtens Committed by schneider
Browse files

RTC: Add function to set time


This allows to set the current time in milliseconds.

Signed-off-by: default avatarHauke Mehrtens <hauke@hauke-m.de>
parent ec1cadae
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,7 @@ typedef _Bool bool;
#define API_RTC_GET_SECONDS 0x50
#define API_RTC_SCHEDULE_ALARM 0x51
#define API_RTC_SET_MILLISECONDS 0x52
#define API_LEDS_SET 0x60
#define API_LEDS_SET_HSV 0x61
......@@ -964,6 +965,11 @@ API(API_FILE_UNLINK, int epic_file_unlink(const char* path));
*/
API(API_RTC_GET_SECONDS, uint32_t epic_rtc_get_seconds(void));
/**
* Sets the current RTC time in milliseconds
*/
API(API_RTC_SET_MILLISECONDS, void epic_rtc_set_milliseconds(uint64_t milliseconds));
/**
* Schedule the RTC alarm for the given timestamp.
*
......
......@@ -25,6 +25,21 @@ uint32_t epic_rtc_get_seconds(void)
return sec;
}
void epic_rtc_set_milliseconds(uint64_t milliseconds)
{
uint32_t sec, subsec;
sec = milliseconds / 1000;
subsec = (milliseconds % 1000);
subsec *= 256;
subsec /= 1000;
while (RTC_Init(MXC_RTC, sec, subsec, NULL) == E_BUSY)
;
while (RTC_EnableRTCE(MXC_RTC) == E_BUSY)
;
}
void RTC_IRQHandler(void)
{
int flags = RTC_GetFlags();
......
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