-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtc.h
More file actions
211 lines (179 loc) · 4.63 KB
/
rtc.h
File metadata and controls
211 lines (179 loc) · 4.63 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#ifndef H8_RTC_H
#define H8_RTC_H
#include "types.h"
#include <time.h>
/**
* RSECDR counts the BCD-coded second value. The setting range is decimal
* 00 to 59. It is an 8-bit read register used as a counter, when it operates
* as a free running counter.
* Mapped to 0xF068.
*/
typedef union
{
H8_BITFIELD_3
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1,
/** Counting Ten's Position. Counts from 0-5. */
h8_u8 ct : 3,
/** Counting One's Position. Counts from 0-9. */
h8_u8 co : 4
) flags;
h8_byte_t raw;
} h8_rsecdr_t;
/**
* RMINDR counts the BCD-coded minute value on the carry generated once per
* minute by the RSECDR counting. The setting range is decimal 00 to 59.
* Mapped to 0xF069.
*/
typedef union
{
H8_BITFIELD_3
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1,
/** Counting Ten's Position. Counts from 0-5. */
h8_u8 ct : 3,
/** Counting One's Position. Counts from 0-9. */
h8_u8 co : 4
) flags;
h8_byte_t raw;
} h8_rmindr_t;
/**
* RHRDR counts the BCD-coded hour value on the carry generated once per hour
* by RMINDR. The setting range is either decimal 00 to 11 or 00 to 23 by the
* selection of the 12/24 bit in RTCCR1.
* Mapped to 0xF06A.
*/
typedef union
{
H8_BITFIELD_4
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1,
/** Reserved. This bit is always read as 0. */
h8_u8 r : 1,
/** Counting Ten's Position. Counts from 0-2. */
h8_u8 ct : 2,
/** Counting One's Position. Counts from 0-9. */
h8_u8 co : 4
) flags;
h8_byte_t raw;
} h8_rhrdr_t;
enum
{
H8_RTC_SUNDAY = 0,
H8_RTC_MONDAY,
H8_RTC_TUESDAY,
H8_RTC_WEDNESDAY,
H8_RTC_THURSDAY,
H8_RTC_FRIDAY,
H8_RTC_SATURDAY,
H8_RTC_RESERVED
};
/**
* RWKDR counts the BCD-coded day-of-week value on the carry generated once per
* day by RHRDR. The setting range is decimal 0 to 6 using bits WK2 to WK0.
*/
typedef union
{
H8_BITFIELD_3
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1,
/** Reserved. These bits are always read as 0. */
h8_u8 r : 4,
/** Day-of-Week Counting. Counts from 0-6. */
h8_u8 wk : 3
) flags;
h8_byte_t raw;
} h8_rwkdr_t;
enum
{
H8_RTC_12H = 0,
H8_RTC_24H = 1
};
/**
* RTCCR1 controls start/stop and reset of the clock timer.
*/
typedef union
{
H8_BITFIELD_6
(
/** RTC Operation Start. Represents whether RTC is active. */
h8_u8 run : 1,
/** Operating Mode. Using 24H mode when set. */
h8_u8 om : 1,
/** AM/PM. Set when after noon in 12H mode. */
h8_u8 pm : 1,
/**
* Reset. Resets registers and control circuits except RTCCSR and this
* bit. Clear this bit to 0 after having been set to 1.
*/
h8_u8 rst : 1,
/** Interrupt Occurrence Timing. @todo */
h8_u8 intr : 1,
/** Reserved. These bits are always read as 0. */
h8_u8 r : 3
) flags;
h8_byte_t raw;
} h8_rtccr1_t;
/** RTCCR2. @todo Not particularly needed for an emulator. */
typedef union
{
h8_byte_t raw;
} h8_rtccr2_t;
/** RTCCSR. @todo Not particularly needed for an emulator. */
typedef union
{
h8_byte_t raw;
} h8_rtccsr_t;
/** RTCFLG. @todo Not particularly needed for an emulator. */
typedef union
{
h8_byte_t raw;
} h8_rtcflg_t;
typedef struct
{
h8_rsecdr_t rsecdr;
h8_rmindr_t rmindr;
h8_rhrdr_t rhrdr;
h8_rwkdr_t rwkdr;
h8_rtccr1_t rtccr1;
h8_rtccr2_t rtccr2;
h8_rtccsr_t rtccsr;
h8_rtcflg_t rtcflg;
} h8_rtc_t;
/**
* Updates the system's RTC registers to match a given time_t.
*/
void h8_rtc_set(h8_rtc_t *rtc, const time_t time);
/**
* Updates the system's RTC registers to match the current time.
*/
void h8_rtc_set_current(h8_rtc_t *rtc, const time_t offset);
#endif