blob: 4dc4b41fc1dcaf03aa7b018718cd910ffab7fbeb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#ifndef CLOCK_H_
#define CLOCK_H_
#include <time.h>
#include "../bang.h"
// A 16-bit countdown timer.
typedef struct {
u32 end; // End time as an uptime value, zero if inactive
u16 read, write; // Read write caches for remaining duration
} ClockTimer;
// Bedrock clock device.
typedef struct {
ClockTimer t1, t2, t3, t4; // Timers
u16 uptime; // Read cache for uptime
u32 start; // Uptime offset
} ClockDevice;
// Extract fields from a tm struct.
#define YEAR(tm) (tm->tm_year - 100)
#define MONTH(tm) (tm->tm_mon)
#define DAY(tm) (tm->tm_mday - 1)
#define HOUR(tm) (tm->tm_hour)
#define MINUTE(tm) (tm->tm_min)
#define SECOND(tm) (tm->tm_sec)
// Functions.
void init_nds_clock(void);
struct tm* get_datetime(void);
// Timer methods.
void timer_read(ClockTimer *timer);
void timer_write(ClockTimer *timer);
// Clock methods.
void clock_reset(ClockDevice *clock);
void clock_uptime_read(ClockDevice *clock);
bool clock_check_timers(ClockDevice *clock);
#endif
|