-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTC.cpp
More file actions
161 lines (124 loc) · 3.64 KB
/
Copy pathRTC.cpp
File metadata and controls
161 lines (124 loc) · 3.64 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
//
// RTC.cpp
// SDL3Test
//
// Created by Matt Parsons on 24/03/2026.
//
#include "RTC.hpp"
void RTC::Init(uint32_t bas, uint8_t* dat, int siz){
}
uint32_t RTC::Read8(uint32_t address){
return ReadBatClock(address);
}
uint32_t RTC::Read16(uint32_t address){
return ReadBatClock(address);
}
uint32_t RTC::Read32(uint32_t address){
return 0;
}
void RTC::Write8(uint32_t address, uint32_t value){
SetBatClock(address, value);
return;
}
void RTC::Write16(uint32_t address, uint32_t value){
return;
}
void RTC::Write32(uint32_t address, uint32_t value){
return;
}
int RTC::BCDLower(int value){
int tens = value / 10;
return value - (tens * 10);
}
int RTC::BCDUpper(int value){
return value / 10;
}
void RTC::SetBatClock(uint32_t address,uint8_t value){
//printf("Write: %d - Battery RTC (Reg: 0x%X): 0x%X : %d\n", size,(address & 0x3F) >> 2 , address, value);
int index = address >> 2;
index &=0xF;
if(index==0xd){
//Snapshot clock
if(value & 1){
time(&batClockRawtime);
batClockInfo = localtime(&batClockRawtime);
batClockInfo->tm_mon += 1;
RTC[0] = BCDLower(batClockInfo->tm_sec);
RTC[1] = BCDUpper(batClockInfo->tm_sec);
RTC[2] = BCDLower(batClockInfo->tm_min);
RTC[3] = BCDUpper(batClockInfo->tm_min);
RTC[4] = BCDLower(batClockInfo->tm_hour);
RTC[5] = BCDUpper(batClockInfo->tm_hour);
RTC[6] = BCDLower(batClockInfo->tm_mday);
RTC[7] = BCDUpper(batClockInfo->tm_mday);
RTC[8] = BCDLower(batClockInfo->tm_mon);
RTC[9] = BCDUpper(batClockInfo->tm_mon);
RTC[10] = BCDLower(batClockInfo->tm_year);
RTC[11] = BCDUpper(batClockInfo->tm_year);
RTC[12] = batClockInfo->tm_wday;
}
}
RTC[index] = value;
}
int RTC::ReadBatClock(uint32_t address){
//printf("Read: %d - Battery RTC (Reg: 0x%X): 0x%X :: %d\n", size, (address & 0x3F) >> 2 ,address, RAM24bit[address]);
int index = address >> 2;
index &=0xF;
if(RTC[0xD] & 1){
return RTC[index];
}
time(&batClockRawtime);
batClockInfo = localtime(&batClockRawtime);
batClockInfo->tm_mon += 1;
switch(index){
case 0:
return BCDLower(batClockInfo->tm_sec);
break;
case 1:
return BCDUpper(batClockInfo->tm_sec);
break;
case 2:
return BCDLower(batClockInfo->tm_min);
break;
case 3:
return BCDUpper(batClockInfo->tm_min);
break;
case 4:
return BCDLower(batClockInfo->tm_hour);
break;
case 5:
return BCDUpper(batClockInfo->tm_hour);
break;
case 6:
return BCDLower(batClockInfo->tm_mday);
break;
case 7:
return BCDUpper(batClockInfo->tm_mday);
break;
case 8:
return BCDLower(batClockInfo->tm_mon);
break;
case 9:
return BCDUpper(batClockInfo->tm_mon);
break;
case 10:
return BCDLower(batClockInfo->tm_year);
break;
case 11:
return BCDUpper(batClockInfo->tm_year);
break;
case 12:
return batClockInfo->tm_wday;
break;
case 13:
return RTC[13];
break;
case 14:
return RTC[14];
break;
case 15:
return RTC[15];
break;
}
return 0;
}