Source code for the Trusted Boot Module.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
tbm-mcu/source/platform/stm32f1/rtc.c

42 lines
597 B

#include <libopencm3/stm32/pwr.h>
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/rtc.h>
#include <macros.h>
#include <rtc.h>
int rtc_get_time(struct tm *time)
{
time_t unix_time;
if (!time)
return -1;
unix_time = rtc_get_counter_val();
if (!gmtime_r(&unix_time, time))
return -1;
return 0;
}
static int rtc_set_time(struct tm *time)
{
time_t unix_time;
if (!time)
return -1;
unix_time = mktime(time);
rtc_set_counter_val((uint32_t)unix_time);
return 0;
}
int rtc_init(struct tm *time)
{
rtc_auto_awake(RCC_LSE, 0x7fff);
rtc_set_time(time);
return 0;
}