rtc: add an rtc_ticks() function similar to RTC_GetTicks()

This commit is contained in:
Lephe 2021-01-31 09:19:19 +01:00
parent 7e1becbd79
commit 6440527527
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 24 additions and 1 deletions

View File

@ -41,6 +41,7 @@ set(SOURCES_COMMON
src/render/topti.c
src/rtc/inth.s
src/rtc/rtc.c
src/rtc/rtc_ticks.c
src/spu/spu.c
src/std/tinymt32/rand.c
src/std/tinymt32/tinymt32.c

View File

@ -22,6 +22,7 @@ typedef struct
uint8_t hours; /* Hour (0..23) */
uint8_t minutes; /* Minute (0..59) */
uint8_t seconds; /* Second (0..59) */
uint8_t ticks; /* 128-Hz sub-second counter (0...127) */
} rtc_time_t;
@ -31,10 +32,16 @@ void rtc_get_time(rtc_time_t *time);
/* rtc_set_time(): Set current time in the RTC
If [time->week_day] is not in the valid range, it is set to 0. Other fields
are not checked.
are not checked. R64CNT cannot be set to [time->ticks] is ignored.
@time Pointer to new time */
void rtc_set_time(rtc_time_t const *time);
/* rtc_ticks(): Get number of 128-Hz ticks elapsed since Midnight.
Returns R64CNT + 128*RSECCNT + 128*60*RMINCNT + 128*60*60*RHRCNT. This can
be used as a 128-Hz counter, but it wraps around at midnight. */
uint32_t rtc_ticks(void);
//---
// RTC timer
// The real-time clock produces a regular interrupt which may be used as a

View File

@ -61,6 +61,7 @@ void rtc_get_time(rtc_time_t *time)
do {
RTC->RCR1.CF = 0;
time->ticks = RTC->R64CNT;
time->seconds = int8(RTC->RSECCNT.byte);
time->minutes = int8(RTC->RMINCNT.byte);
time->hours = int8(RTC->RHRCNT.byte);

14
src/rtc/rtc_ticks.c Normal file
View File

@ -0,0 +1,14 @@
#include <gint/rtc.h>
uint32_t rtc_ticks(void)
{
rtc_time_t t;
rtc_get_time(&t);
uint32_t ticks = t.hours;
ticks = 60 * ticks + t.minutes;
ticks = 60 * ticks + t.seconds;
ticks = 128 * ticks + t.ticks;
return ticks;
}