mirror of
https://git.planet-casio.com/Lephenixnoir/gint.git
synced 2025-05-23 20:15:10 +02:00
rtc: add an rtc_ticks() function similar to RTC_GetTicks()
This commit is contained in:
parent
7e1becbd79
commit
6440527527
4 changed files with 24 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
14
src/rtc/rtc_ticks.c
Normal 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;
|
||||
}
|
Loading…
Add table
Reference in a new issue