mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
d092c12a66
Use RTC helper functions instead of libc functions. This gives us y2038 safety by the extended epoch and saves a good chunk of memory: picolibc mktime(): text data bss dec hex filename 15048 520 2504 18072 4698 tests/periph_rtc/bin/hifive1/tests_periph_rtc.elf rtc_mktime(): text data bss dec hex filename 7632 40 2452 10124 278c tests/periph_rtc/bin/hifive1/tests_periph_rtc.elf
103 lines
1.5 KiB
C
103 lines
1.5 KiB
C
/*
|
|
* Copyright 2017 Ken Rabold
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup cpu_fe310
|
|
* @{
|
|
*
|
|
* @file rtc.c
|
|
* @brief RTC interface wrapper for use with RTT modules
|
|
*
|
|
* @author Ken Rabold
|
|
* @}
|
|
*/
|
|
|
|
#include "cpu.h"
|
|
#include "periph_cpu.h"
|
|
#include "periph_conf.h"
|
|
#include "periph/rtt.h"
|
|
#include "periph/rtc.h"
|
|
|
|
#define ENABLE_DEBUG (0)
|
|
#include "debug.h"
|
|
|
|
|
|
typedef struct {
|
|
rtc_alarm_cb_t cb; /**< callback called from RTC interrupt */
|
|
}rtc_state_t;
|
|
|
|
static rtc_state_t rtc_callback;
|
|
|
|
static void rtc_cb(void *arg);
|
|
|
|
void rtc_init(void)
|
|
{
|
|
rtt_init();
|
|
}
|
|
|
|
int rtc_set_time(struct tm *time)
|
|
{
|
|
uint32_t t = rtc_mktime(time);
|
|
|
|
rtt_set_counter(t);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int rtc_get_time(struct tm *time)
|
|
{
|
|
uint32_t t = rtt_get_counter();
|
|
|
|
rtc_localtime(t, time);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
|
{
|
|
uint32_t t = rtc_mktime(time);
|
|
|
|
rtc_callback.cb = cb;
|
|
|
|
rtt_set_alarm(t, rtc_cb, arg);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int rtc_get_alarm(struct tm *time)
|
|
{
|
|
uint32_t t = rtt_get_alarm();
|
|
|
|
rtc_localtime(t, time);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void rtc_clear_alarm(void)
|
|
{
|
|
rtt_clear_alarm();
|
|
rtc_callback.cb = NULL;
|
|
}
|
|
|
|
void rtc_poweron(void)
|
|
{
|
|
rtt_poweron();
|
|
}
|
|
|
|
void rtc_poweroff(void)
|
|
{
|
|
rtt_poweroff();
|
|
}
|
|
|
|
static void rtc_cb(void *arg)
|
|
{
|
|
if (rtc_callback.cb != NULL) {
|
|
rtc_callback.cb(arg);
|
|
}
|
|
}
|