Skip to content

Commit f009b38

Browse files
committed
The RTC is harder than I think
1 parent 3bdec8e commit f009b38

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

qiling/hw/timer/stm32f4xx_rtc.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
44
#
55

6+
import time
67
import ctypes
8+
from datetime import datetime
79

810
from qiling.hw.peripheral import QlPeripheral
911
from qiling.hw.const.stm32f4xx_rtc import RTC_TR, RTC_ISR
10-
from qiling.hw.utils.bcd import byte2bcd
12+
from qiling.hw.utils.bcd import bcd2byte, byte2bcd
1113

1214

13-
class Time:
14-
def __init__(self):
15-
pass
16-
1715
class STM32F4xxRtc(QlPeripheral):
1816
class Type(ctypes.Structure):
1917
""" the structure is available in :
@@ -133,8 +131,17 @@ def set_time(self, hour=0, minute=0, second=0, time_format=0):
133131

134132
self.rtc.TR = hour | minute | second | time_format
135133

136-
def get_time(self):
137-
pass
134+
def get_time(self, value):
135+
hour = (value & (RTC_TR.HT | RTC_TR.HU)) >> 16
136+
minute = (value & (RTC_TR.MNT | RTC_TR.MNU)) >> 8
137+
second = value & (RTC_TR.ST | RTC_TR.SU)
138+
time_format = (value & RTC_TR.PM) >> 16
139+
140+
return hour, minute, second, time_format
141+
142+
def increase(self):
143+
self.calendar += 1
144+
self.set_time(self.calendar.tm_hour, self.calendar.tm_min, self.calendar.tm_sec)
138145

139146
def step(self):
140147
if self.rtc.ISR & RTC_ISR.INIT:

0 commit comments

Comments
 (0)