Skip to content

Commit 4361c7c

Browse files
committedOct 12, 2014
language/core: support cycles_to_time and time_to_cycles outside of kernel
1 parent 77967f6 commit 4361c7c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed
 

‎artiq/language/core.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from copy import copy as _copy
55
from functools import wraps as _wraps
66

7+
from artiq.language import units as _units
8+
79

810
class int64(int):
911
"""64-bit integers for static compilation.
@@ -232,8 +234,6 @@ def _not_implemented(self, *args, **kwargs):
232234
take_time = _not_implemented
233235
get_time = _not_implemented
234236
set_time = _not_implemented
235-
time_to_cycles = _not_implemented
236-
cycles_to_time = _not_implemented
237237

238238
_time_manager = _DummyTimeManager()
239239

@@ -323,18 +323,30 @@ def at(time):
323323
_time_manager.set_time(time)
324324

325325

326-
def time_to_cycles(time):
326+
def time_to_cycles(time, core=None):
327327
"""Converts time to the corresponding number of RTIO cycles.
328328
329+
:param time: Time (in seconds) to convert.
330+
:param core: Core device for which to perform the conversion. Specify only
331+
when running in the interpreter (not in kernel).
332+
329333
"""
330-
return _time_manager.time_to_cycles(time)
334+
if core is None:
335+
raise ValueError("Core device must be specified for time conversion")
336+
return int64(time.amount//core.runtime_env.ref_period)
331337

332338

333-
def cycles_to_time(cycles):
339+
def cycles_to_time(cycles, core=None):
334340
"""Converts RTIO cycles to the corresponding time.
335341
342+
:param time: Cycle count to convert.
343+
:param core: Core device for which to perform the conversion. Specify only
344+
when running in the interpreter (not in kernel).
345+
336346
"""
337-
return _time_manager.cycles_to_time(cycles)
347+
if core is None:
348+
raise ValueError("Core device must be specified for time conversion")
349+
return cycles*core.runtime_env.ref_period*_units.s
338350

339351

340352
def syscall(*args):

0 commit comments

Comments
 (0)
Please sign in to comment.