-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed timer ReadEClock and added pytask test for it
- Loading branch information
Showing
9 changed files
with
189 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
import time | ||
from amitools.vamos.libcore import LibImpl | ||
from amitools.vamos.machine.regs import REG_A0 | ||
from amitools.vamos.astructs import AccessStruct | ||
from amitools.vamos.libstructs import DateStampStruct | ||
|
||
from datetime import datetime | ||
from amitools.vamos.libstructs import TimeValStruct | ||
|
||
|
||
class TimerDevice(LibImpl): | ||
def ReadEClock(self, ctx): | ||
eclockval = ctx.cpu.r_reg(REG_A0) | ||
# our simulated EClock freq: 10 MHz | ||
# its around the real EClock (3 MHz) | ||
ECLOCK_HZ = 10_000_000 | ||
# how to convert ns time stamp to eclock | ||
ECLOCK_NS_FACTOR = 100 | ||
|
||
dt = datetime.now() | ||
def _get_eclock_lo_hi(self): | ||
# use the monotonic time here to have a suitable clock for benchmarks | ||
ts_ns = time.monotonic_ns() | ||
eclk = ts_ns // self.ECLOCK_NS_FACTOR | ||
eclk_lo = eclk & 0xFFFFFFFF | ||
eclk_hi = eclk >> 32 | ||
return eclk_lo, eclk_hi | ||
|
||
def ReadEClock(self, ctx): | ||
addr = ctx.cpu.r_reg(REG_A0) | ||
# get val struct | ||
tv = TimeValStruct(mem=ctx.mem, addr=addr) | ||
|
||
# abuse DateStampStruct | ||
tv = AccessStruct(ctx.mem, DateStampStruct, struct_addr=eclockval) | ||
tv.ds_Days = dt.microsecond / 1000000 | ||
tv.ds_Minute = dt.microsecond % 1000000 | ||
lo, hi = self._get_eclock_lo_hi() | ||
tv.secs.val = hi | ||
tv.micro.val = lo | ||
|
||
return 50 | ||
# always return eclock freq | ||
return self.ECLOCK_HZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .exec_ import * | ||
from .dos import * | ||
from .util import * | ||
from .timer import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from amitools.vamos.astructs import ( | ||
AmigaStructDef, | ||
AmigaStruct, | ||
ULONG, | ||
) | ||
from .exec_ import IORequestStruct | ||
|
||
|
||
# TimeVal | ||
@AmigaStructDef | ||
class TimeValStruct(AmigaStruct): | ||
_format = [(ULONG, "tv_secs"), (ULONG, "tv_micro")] | ||
|
||
|
||
# TimeRequest | ||
@AmigaStructDef | ||
class TimeRequestStruct(AmigaStruct): | ||
_format = [ | ||
(IORequestStruct, "tr_node"), | ||
(TimeValStruct, "tr_time"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import time | ||
from amitools.vamos.libstructs import TimeValStruct, TimeRequestStruct | ||
from amitools.vamos.lib.TimerDevice import TimerDevice | ||
|
||
|
||
def pytask_timer_eclock_test(vamos_task): | ||
"""check GetEClock of Python""" | ||
|
||
def task(ctx, task): | ||
# get exec library | ||
exec_proxy = ctx.proxies.get_exec_lib_proxy() | ||
|
||
# alloc time struct | ||
tv = TimeValStruct.alloc(ctx.alloc) | ||
assert tv is not None | ||
|
||
# alloc timer io req | ||
req = TimeRequestStruct.alloc(ctx.alloc) | ||
assert req is not None | ||
|
||
prox = ctx.proxies.open_lib_proxy("timer.device") | ||
print(f"prox: addr={prox.base_addr:08x}") | ||
|
||
# open timer device | ||
res = exec_proxy.OpenDevice("timer.device", 0, req.addr, 0) | ||
assert res == 0 | ||
|
||
# get proxy for device | ||
base_addr = req.node.device.aptr | ||
tdev = ctx.proxies.open_lib_proxy_addr(base_addr) | ||
assert tdev is not None | ||
|
||
# call lib func | ||
res = tdev.ReadEClock(tv.addr) | ||
assert res == TimerDevice.ECLOCK_HZ | ||
ts_last = tv.secs.val << 32 | tv.micro.val | ||
|
||
for i in range(100): | ||
# call lib func | ||
res = tdev.ReadEClock(tv.addr) | ||
assert res == TimerDevice.ECLOCK_HZ | ||
ts = tv.secs.val << 32 | tv.micro.val | ||
|
||
# assert monotonic time stamp | ||
assert ts > ts_last | ||
|
||
ts_last = ts | ||
|
||
# free proxy | ||
ctx.proxies.close_lib_proxy(tdev) | ||
|
||
# close device | ||
exec_proxy.CloseDevice(req.addr) | ||
|
||
# free req | ||
req.free() | ||
|
||
# free timeval | ||
tv.free() | ||
|
||
return 0 | ||
|
||
exit_codes = vamos_task.run([task]) | ||
assert exit_codes == [0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters